I keep getting "invalid auth token when trying to connect to Blynk server after a small software change, allthough previously the program ran fine. The program controls an arduino uno to control a heater project. I copied the data from the blynk console and incorporated them at the start of the program. I iinclude the start of my program.I can give the whoile program but it is rather lengthy. Any clue what has changed since a couple of months since it was running fine than.
- Search forum for similar topics
- Check http://docs.blynk.cc and http://help.blynk.cc/ done, no solution
- Add details :
• Arduino UNO with Ethernet Shield
• Smartphone OS iOS + iphone SE version 15.1
• Blynk server
• Blynk Library version 0.6.1 by volodymyr
• Add your sketch code.Code should be formatted as example below.
Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
/*
* rev 4: new blynk module
* rev 5: remote reset added
* rev 6: temperature bypass button added in case temp reading fails
* rev 7: eliminating 30° test as dallastemp allways reports 0 after a while
*
* Central heating Prégermain
*
* Gets a signal from the nest heatlink and start heater and circulation pump.
* If heatlink sends a stop signal , turns off the circulation and stops the heater after a while
*
* The circuit:
- heatlink switch attached to pin 6
- start stop circulation pump on pin 5
- start stop heater on pin 3
- heater temperature onewire DS18B20 on pin 2
*/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL0e7VvgzM"
#define BLYNK_DEVICE_NAME "Prégermain Heater Control"
#define BLYNK_AUTH_TOKEN "XqXokF-XkYGjdXSjEbqlDkZSZiEH2Ypq"
// include onwire libraries
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
//DeviceAddress insideThermometer = {0x28, 0x63, 0xCB, 0x79, 0x97, 0x00, 0x03, 0x5D }; // mac address of temperature probe DS18B20 at PG
//DeviceAddress insideThermometer = {0x28, 0x56, 0xE9, 0x79, 0x97, 0x00, 0x03, 0x20 }; // mac address of temperature probe DS18B20 home
/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial
//include blink libraries
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
//char auth[] = "XqXokF-XkYGjdXSjEbqlDkZSZiEH2Ypq";
//char auth[] = "dn-rx1VqwK_7gCWouL8Bue6Kpsbe5m0I"; //testopstelling thuis (old blynk)
//char auth[] = "M2KWX7fILaf9VUhx9X_PbsD-CAV1Izq1"; //installatie PG (old blynk)
#define W5100_CS 10
#define SDCARD_CS 4
WidgetLED circulatiepomp(V2);
WidgetLED ketel(V3);
BlynkTimer timer; // main timer to control heater/blynk communication/connection handling
#define BLYNK_GREEN "#23C48E"
#define BLYNK_RED "#D3435C"
#define BLYNK_YELLOW "#FBAD00"
// define input /outputs
#define heatlink 6 // heatlink input
#define ststcirc 5 // Start stop circultation pump on pin 5
#define ststheat 3 // Start sto of heater on pin 3
#define heartbeat 7 // heartbeat pin in pin 7
#define echoPin 8 // attach pin D8 Arduino to pin Echo of HC-SR04
#define trigPin 9 //attach pin D9 Arduino to pin Trig of HC-SR04
// variables
int noconnectcount=0; // counter when not connected
int resetcount=0; // counts the number of reset button presses
int mazouttlevel = 0; // initialise level of mazouttank
bool heatlinkstate = false; // status van nest heatlink
int flag_circ = false; // flag to start circulation pump
int flag_heater = false; // flag to start heater
bool restart_inhibit = true; // flag (true) not to restart heater immediately, false heater can start
bool stopflag = false; // flag (true) to indicate heater was started and should not restart immediately after stop
unsigned long stop_time = 0; // indicates heater reset or heater stop time
//initialise Virtual pins
int automanueel = 0; // blynk selector auto in auto (V8)
int tbypass = 0; // pushbutton to bypass Temp reading
int flag_mazoutt = 0; // blynk flag to measurelevel mazouttank
float tempC = 0;
float tempsaved = 0;
void setup() {
// initialise inputs-outputs
pinMode(ststcirc, OUTPUT);
pinMode(ststheat, OUTPUT);
pinMode(heatlink, INPUT);
pinMode(heartbeat, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
digitalWrite(ststcirc,LOW); // stop circulationpump
digitalWrite(ststheat,LOW); // stop heater
digitalWrite(heartbeat,LOW); // set heartbeat low
digitalWrite(trigPin, LOW); // set trigpin low to start
restart_inhibit = true; // set flag true so heater cannot start immediately after reset
stopflag = false; // set flag false to indicate heate was not yet started
stop_time = millis(); // save stop time, 0 after reset
resetcount = 0; // initialise resetcounter to 0
// initialise serial communication
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
//Blynk.begin(auth);
byte mac[]= {0xDE,0xAD,0xBE,0xEF,0xFE,0xEF};
if (Ethernet.begin(mac) == 0)
//Ethernet.begin(mac);
{
Serial.println("Failed to configure ethernet using DHCP");
}
Blynk.config(auth);
Blynk.connect();
// Setup a function to be called every 5 seconds
timer.setInterval(5000L, Heatercontrol);
// Setup timer for communication with blynk
timer.setInterval(5500L, blinkcomm);
// Setup a function to be called every 10 seconds for connection control and watchdog feeding
timer.setInterval(10000L, heaterreset);
// Setup a function to be called every minute to check if mazouttank level has to be measured
timer.setInterval(60000L, mazouttank);
// Setup a function to be called every 1,5 minute to check if distance reset has to be given
timer.setInterval (90000L, distancereset);
// Start up the library (one wire)
sensors.begin();
// set the resolution to 10 bit (good enough?)
//sensors.setResolution(insideThermometer, 10);
sensors.setResolution(9);
sensors.requestTemperatures();
//tempC = sensors.getTempC(insideThermometer);
tempC = sensors.getTempCByIndex(0);
if (tempC == -127.00)
{
Serial.println("Error getting temperature");
}
tempsaved = tempC;
Blynk.setProperty(V5, "color", BLYNK_GREEN);
} // end void setup
// define actions on virtual pins
// if resetbutton pressed increment resetcounter
BLYNK_WRITE (V0)
{
if (param.asInt())
{
resetcount = resetcount+1;
}
}
// read manual auto selector
BLYNK_WRITE (V8)
{
if (param.asInt())
{
automanueel = !automanueel; //toggle flag
}
}
// read temp bypass button
BLYNK_WRITE (V1)
{
if (param.asInt())
{
tbypass = !tbypass; //toggle flag
}
}
// read ketel push button
BLYNK_WRITE (V7)
{
if (param.asInt())
{
flag_heater = !flag_heater; //toggle flag
}
}
// read circulatie push button
BLYNK_WRITE (V6)
{
if (param.asInt())
{
flag_circ = !flag_circ; //toggle flag
}
}
// read flag to determine if level mazouttank has to be measured
BLYNK_WRITE (V9)
{
if (param.asInt())
{
flag_mazoutt = !flag_mazoutt; //toggle flag
}
}
// end definition of actions
void Heatercontrol() {
// set elapsed time to delay restart heater after reset or stop to two minutes
const unsigned long elapsed = (1000UL*60*2);
// set restart_inhibit flag false after elapsed time
if (restart_inhibit==true)
{
Serial.println(millis()- stop_time);
if (millis()- stop_time > elapsed)
{
restart_inhibit=false;
}
}
// read heater temperature and convert to real temp
sensors.requestTemperatures();
//tempC = sensors.getTempC(insideThermometer);
tempC = sensors.getTempCByIndex(0);
if (tempC == -127.00)
{
Serial.println("Error getting temperature");
} else
{
Serial.print("C: ");
Serial.println(tempC);
}
// if keuzeselector is auto
if (automanueel==false)
{
// read heatlinkstate and check if heatlink sends start signal
if (digitalRead(heatlink) == HIGH)
{
flag_heater = true; // set flag heater
flag_circ = true; // set flag circulation pump
// check heater temperature
//if ((tempC > 30)||(tbypass == true))
//{
//while(1);
// flag_circ = true; // set flag circulation pump
//}
//else
//{
//flag_circ = false; // clear flag circulation pump
//}
}
else
{
flag_circ = false; // clear flag circulation pump
flag_heater = false; // clear flag heater
}
}
// Start or stop heater and circulation pump according to flags
if (flag_heater == true) //if start heater condition is true
{
if (restart_inhibit==false) // and inhibit is not valid
{
digitalWrite (ststheat,flag_heater); // then start heater
stopflag = true; // and set flag when heater will be stopped
}
}
else
{
digitalWrite (ststheat,flag_heater); // else stop heater
if (stopflag == true) // if heater has been started
{
restart_inhibit = true; // set restart_inhibit ture not to restart heater immediately
stop_time = millis(); // take time stamp to calculate delay
Serial.println(stop_time);
stopflag = false; // clear flag to execute this once
}
}
//digitalWrite (ststheat,flag_heater);
digitalWrite (ststcirc,flag_circ);
//Serial.print("ketelstst:" );
//Serial.println (flag_heater);
//Serial.print("ciculatiestst:" );
//Serial.println (flag_circ);
}
void mazouttank(){
long duration; // variable for the duration of sound wave travel
float distance; // variable for the distance measurement
if (flag_mazoutt == true) //if flag true, level will be measured
{
for (int i = 0; i <= 5; i++)
{
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
}
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2.0; // Speed of sound wave divided by 2 (go and back)
//mazouttlevel = 137 - distance ;
mazouttlevel = round(134 - distance) ;
// Displays the distance on the Serial Monitor
//Serial.print(distance);
Serial.print(mazouttlevel);
Serial.println(" cm");
}
flag_mazoutt = false; //reset flag
}
void blinkcomm() {
if (Blynk.connected()) // test is arduino still connected to blynk server
{
Blynk.virtualWrite(V8, automanueel); //update auto manueel selector
Blynk.virtualWrite(V6, flag_circ); //update circulation pushbutton
Blynk.virtualWrite(V7, flag_heater); //update heater pushbutton
Blynk.virtualWrite(V1, tbypass); //update tbypass pushbutton
if(automanueel==true && digitalRead(ststheat) == false && digitalRead(ststcirc) == false) // if reset conditions are met, set color to red
{
Blynk.setProperty(V0, "color", BLYNK_RED);
Blynk.setProperty(V0, "offLabel", "Ja "+String(resetcount)); //show resetcounter in resetbutton
}
else
{
Blynk.setProperty(V0, "offLabel", "Neen "+String(resetcount)); //show resetcounter in resetbutton
if (resetcount == 0) //if resetcounter zero set collor of button to green
{
Blynk.setProperty(V0, "color", BLYNK_GREEN);
}
else //set color to yellow
{
Blynk.setProperty(V0, "color", BLYNK_YELLOW);
}
}
if (restart_inhibit==false)
{
Blynk.setProperty(V7, "color", BLYNK_RED);
}
else
{
Blynk.setProperty(V7, "color", BLYNK_YELLOW);
}
//set circulation led according to flag
if (flag_circ == true)
{
circulatiepomp.on();
}
else
{
circulatiepomp.off();
}
//set heater led according to heater status
if (tempC-tempsaved > 0.25 && digitalRead (ststheat)==true)
{
ketel.on();
}
if (tempC-tempsaved < 0)
{
ketel.off();
}
tempsaved = tempC;
// set color of gauge depending on heatlinkstate (red if on, green if off)
if (digitalRead(heatlink) == HIGH)
{
Blynk.setProperty(V5, "color", BLYNK_RED);
}
else
{
Blynk.setProperty(V5, "color", BLYNK_GREEN);
}
//update temperature gauge in Blynk
if (tbypass == false)
{
Blynk.virtualWrite(V5, tempC);
}
else
{
Blynk.virtualWrite(V5, 0);
}
// send level mazouttank to blynk app
//Blynk.setProperty(V9, "onLabel", String(mazouttlevel)+ " cm");
Blynk.setProperty(V9, "offLabel", String(mazouttlevel*24)+ " l / "+String(mazouttlevel)+ " cm");
}
}
void distancereset(){
if (automanueel==true) // check if in manual mode
{
if (digitalRead(ststheat) == false) //check if ketel off
{
if (digitalRead(ststcirc) == false) // check circulation off
{
if (resetcount >= 2) // check if resetbutton has been pressed at least twice
{
Serial.print("resetting by stalling");
//asm volatile (" jmp 0"); // restart arduino
while(1); // loop eternal to activate watchdog
}
}
}
}
resetcount = 0; // initialise resetcounter
}
void heaterreset() {
const int maxnoconnect = 2750; // maximum time no internet connection 12h*60min*19pulses on 5 minutes
if (!Blynk.connected()) // test is arduino still connected to blynk server, if not ...
{
noconnectcount=noconnectcount+1; // increment reset counter
if ((noconnectcount % 7) == 0) // check per minute (7-1)*10 sec
{
byte mac[]= {0xDE,0xAD,0xBE,0xEF,0xFE,0xEF};
Ethernet.begin(mac) == 0; // try and reconnect ethernet
bool result = Blynk.connect(); // try and reconnect to blynk
}
}
else
{
noconnectcount=0; // yes, reset counter
}
Serial.print("connection count = ");
Serial.println(noconnectcount);
// test if
if (noconnectcount < maxnoconnect) // 12 uur
{
// send heartbeat on
send_heartbeat(); //reset watchdog
}
}
void send_heartbeat(){
digitalWrite(heartbeat,HIGH); // Heartbeat sent to watchdog
delay(10); // can be as low as 50 microsecond
digitalWrite(heartbeat,LOW); // pull the heartbeat pin low again
Serial.println("Heartbeat");
}
void loop() {
Blynk.run();
timer.run(); // Initiates BlynkTimers
}
…