Blynk Token : pKdEF1MNazj_aGhpq0VExG1CMTi5qT0n
[63560]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.0.0 on ESP8266
[63572] Connecting to blynk-cloud.com:80
Error: Could not read temperature data for sensor No.0
Error: Could not read temperature data for sensor No.1
Error: Could not read temperature data for sensor No.2
Error: Could not read temperature data for sensor No.3
connected
[63772] Invalid auth token
i have add this line with my server into void setup but without result
#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);
Blynk.config(blynk_token, "192.168.2.7", 8080);
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);
}```