ESP8266 and WiFi Manager with Blynk

Hello Blynkers,
I have this code with wifimanager and I would like from you if you want to and some think in code so that to I can add and auth token such as ssid and pass from the IP (192.168.4.1). I am new in this world and I try my best to develop this code but this, with auth token its complicated. Thanks you a lot for your time

‘’’ /* ESP & Blynk */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial

#include <WiFiManager.h>
#include <Ticker.h>
Ticker ticker;

#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif

int LED = LED_BUILTIN;

/* 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);

float temp0;
float temp1;
float temp2;
unsigned long lst_milis = 0;

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

void tick()
{
//toggle state
digitalWrite(LED, !digitalRead(LED)); // set pin to the opposite state
}

void configModeCallback (WiFiManager *myWiFiManager) {
Serial.println(“Entered config mode”);
Serial.println(WiFi.softAPIP());
Serial.println(myWiFiManager->getConfigPortalSSID());
ticker.attach(0.2, tick);
}

void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
Serial.begin(115200);

DS18B20.begin();

Serial.begin(115200);
pinMode(LED, OUTPUT);
ticker.attach(0.6, tick); // start ticker with 0.5 because we start in AP mode and try to connect
WiFiManager wm;
wm.setAPCallback(configModeCallback);

if (!wm.autoConnect()) {
Serial.println(“failed to connect and hit timeout”);
ESP.restart();
delay(1000);
}

Serial.println(“connected…yeey :)”);
ticker.detach();
digitalWrite(LED, LOW);
}

void loop() {
getSendData();
Blynk.run();
delay(10); //for stability
}

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();

       temp0 = DS18B20.getTempCByIndex(0); // Sensor 1 will capture Temp in Celcius
       temp1 = DS18B20.getTempCByIndex(1); // Sensor 2 will capture Temp in Celcius
       temp2 = DS18B20.getTempCByIndex(2); // Sensor 3 will capture Temp in Celcius     

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

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

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

2 posts were merged into an existing topic: ESP8266 and WiFi Manager