BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Local server and esp8266

Hello blynker, I have a problem, in my raspberry I have a blynk local server , before a day’s everything works OK, but today I try to connect my esp8266 in my server. I add the Auth token of my project to my code for esp but then it not connected to the app. Of try to add Auth from the main server (original) everything works. Do you know what the problem is? :confused:

You’ll need to explain much more about how you have the custom server settings configured in the app when you’re generating the Auth token, and what connection command you are using in the sketch…
Screenshots of the local server config showing the Auth token would also be useful, along with the server logs when you try to connect a device.

Pete.

thanks you Pete… i tried to download again the server… create new user then new project i get new auth. finally i try to upload code to my esp8266 but i have the same problem :confused: while i try to connect my device with public server it is ok, the last but not least, I have download blynk app and do tries in version last and prelast

I cannot see the ip address mentioned in your Blynk.begin :thinking::face_with_monocle:

before i click log in i put ip from my raspberry end port 9443… i understand something wrong from your question? :slight_smile:

The Blynk.begin command in your sketch will ALWAYS connect to the Blynk cloud server.
You need to specify the IP address and port of your local server for it to connect to your local server.

Pete.

Mr. Pete thanks you again for your quick answers. With the same code i had connected again to the local server… may could you please to tell me what should i add in my code? because i am new and this project it is very important for me because i have necessery devise for reptiles connected to the blynk

Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

Change the IP address to your Blynk local server.

Pete.

I can’t explain this… in the picture you can see that the esp connected to the server … but the app not response

I will try to add this line in my code ( before without this line works ok)

Please stop posting pictures of your screen, or screenshots of your code.

Copy and paste the data and put it between triple backticks.
Triple backticks look like this:
```

Pete.

ok pete wait to correct my fault

i have this code

#include <FS.h>
#include <DNSServer.h>
#include <WiFiManager.h>
#include <ESP8266WebServer.h>
#include <BlynkSimpleEsp8266.h>
#include <ArduinoJson.h>
const char* host = "www.google.com"; 

/* TIMER */
#include <SimpleTimer.h>
SimpleTimer timer;

/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h> 
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

//BlynkTimer timer;

float temp_0;
float temp_1;
float temp_2;
float temp_3;
unsigned long lst_milis = 0;

const int relay_1 = 16;
const int relay_2 = 5;
const int relay_3 = 4;
const int relay_4 = 0;
const int relay_5 = 14;
const int relay_6 = 12;
const int relay_7 = 13;
const int relay_8 = 3;


#define SET_PIN 0

char blynk_token[40] = "";
bool shouldSaveConfig = false;

void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}


BLYNK_CONNECTED()  //sygxronizei to esp otan bgei apo to reuma stis leitoyrgies poy eixe stamatisi
{
 Blynk.syncAll();
}


void setup()
{
  //Blynk.config(auth);
 // Blynk.begin(auth, ssid, pass);
  DS18B20.begin();
  timer.setInterval(1000L,getSendData);
  timer.setInterval(10000L,WiFiStatus);
  
  Serial.begin(115200);
  Serial.println();
  pinMode(SET_PIN, INPUT_PULLUP);
  delay(3000);

  //read configuration from FS json
  Serial.println("mounting FS...");
  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        DynamicJsonDocument jsonBuffer ( 1024 ) ;
        DeserializationError error = deserializeJson ( jsonBuffer, configFile ) ;
        if ( not error )
          {
            serializeJson(jsonBuffer, Serial);
            strcpy(blynk_token, jsonBuffer["blynk_token"]) ;
            Serial.println("\nparsed json");
            Serial.println( blynk_token );
          }
        else  
          Serial.println("failed to load json config");

        configFile.close();
    }
  } else {
    Serial.println("failed to mount FS");
  }

  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32);
  WiFiManager wifiManager;
  wifiManager.setSaveConfigCallback(saveConfigCallback);
  wifiManager.addParameter(&custom_blynk_token);

  if (digitalRead(SET_PIN) == LOW) {
    wifiManager.resetSettings();
  }

  if (!wifiManager.autoConnect("Apo_Reptiles_Room")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    ESP.reset();
    delay(5000);
  }

  Serial.println("wifi connected");
  strcpy(blynk_token, custom_blynk_token.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonDocument jsonBuffer ( 1024 ) ;
    jsonBuffer["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }
    else
      serializeJson(jsonBuffer, configFile);
    configFile.close();
  }
  
  Serial.println();
  Serial.print("local ip : ");
  Serial.println(WiFi.localIP());
  Serial.print("Blynk Token : ");
  Serial.println(blynk_token);
  Blynk.config(blynk_token);
  }
}

void loop() {
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}


/***************************************************
 * Send Sensor data to Blynk
 **************************************************/
void getSendData(){
    unsigned long cur_millis = millis();
    if (cur_millis - lst_milis >= 2000)         //if 2 seconds since last mesurement 
        {
        lst_milis = cur_millis;
        DS18B20.requestTemperatures(); 
               
           temp_0 = DS18B20.getTempCByIndex(0); // Sensor 1 will capture Temp in Celcius
           temp_1 = DS18B20.getTempCByIndex(1); // Sensor 2 will capture Temp in Celcius
           temp_2 = DS18B20.getTempCByIndex(2); // Sensor 3 will capture Temp in Celcius  
           temp_3 = DS18B20.getTempCByIndex(2); // Sensor 3 will capture Temp in Celcius   

          if(temp_0 != -127){
            Serial.println(temp_0);
            Blynk.virtualWrite(21 , temp_0);    //virtual pin 1
          }
          else{
            Serial.println("Error: Could not read temperature data for sensor No.0");
          }

          if(temp_1 != -127){
            Serial.println(temp_1);
            Blynk.virtualWrite(22 , temp_1);    //virtual pin 2
          }
          else{
            Serial.println("Error: Could not read temperature data for sensor No.1");
            }

            if(temp_2 != -127){
            Serial.println(temp_2);
            Blynk.virtualWrite(23, temp_2);    //virtual pin 3
          }
          else{
            Serial.println("Error: Could not read temperature data for sensor No.2");
           }
           if(temp_3 != -127){
            Serial.println(temp_3);
            Blynk.virtualWrite(24, temp_3);    //virtual pin 4
          }
          else{
            Serial.println("Error: Could not read temperature data for sensor No.3");
           }
        }
    }



void WiFiStatus()
{
  WiFiClient client;
  if (client.connect(host, 80))
  {
        Serial.println("connected");
        client.stop();
     
    }
    else {
     Serial.println("connection failed!"); 
  digitalWrite(relay_1, HIGH); // Και εδω δηλωνεις οτι θα ξεκιναει κλειστο
  digitalWrite(relay_2, HIGH);
  digitalWrite(relay_3, HIGH);
  digitalWrite(relay_4, HIGH); 
  digitalWrite(relay_5, HIGH);
  digitalWrite(relay_6, HIGH);
  digitalWrite(relay_7, HIGH);
  digitalWrite(relay_8, HIGH); 
     client.stop();
    
   }
} 


    BLYNK_WRITE(V16)
{
  int pinData = param.asInt();
  digitalWrite(16, pinData);
}

BLYNK_WRITE(V5)
{
  int pinData = param.asInt();
  digitalWrite(5, pinData);
}

BLYNK_WRITE(V4)
{
  int pinData = param.asInt();
  digitalWrite(4, pinData);
}

BLYNK_WRITE(V0)
{
  int pinData = param.asInt();
  digitalWrite(0, pinData);
}

BLYNK_WRITE(V14)
{
  int pinData = param.asInt();
  digitalWrite(14, pinData);
}

BLYNK_WRITE(V12)
{
  int pinData = param.asInt();
  digitalWrite(12, pinData);
}

BLYNK_WRITE(V13)
{
  int pinData = param.asInt();
  digitalWrite(13, pinData);
}

BLYNK_WRITE(V3)
{
  int pinData = param.asInt();
  digitalWrite(3, pinData);
}

Moreover in serial i can see everythink ok… but in the app somethink goes wrong

sorry but the serial i cant post it with this (``` ) there are pic in my post :slight_smile:

That sketch is very different from the one in the screenshot on post #3
Why is this?

This command will connect your device to the legacy cloud server, not your local server

If you’re actually using this sketch rather than the first one in the screenshot then it needs to look like this:

Blynk.config(blynk_token, "192.168.1.251", 8080);

Replace the IP address with the IP of your local server.

Pete.

There are 2 different codes because I have 2 project… but they do the same job… in the second code there are some libraries which can add the Auth, ssid, pass without code, add this from the ip… in some minutes I replace this lines … but how you explain that this codes works normally and now not?

Pete sorry for the photo in serial i can’t copy paste

I see this… when I try to add Auth ! Finally the problem is there wrong Auth why? I have add this with copy paste 20210910_213047|666x500

Yes you can!
Use your mouse or CTRL A to select and CTRL C to copy.

Pete.

ok Pete thanks next time i do this :slight_smile:

but my problem there is yet :sleepy:

If you copy/paste your serial output I’ll explain what’s happening.

Pete.