Yesterday I got my first Blynk script running. I was very pleased at how easy it was.
Today I wrote my second script, and I can’t get it to log in to the server.
Here’s the background:
I am using ESP12’s as the hardware, with the Arduino IDE.
I have enabled DEBUG and here’s the log that Blynk generates:
[34240] Connecting to house-net
[39741] Connected to WiFi
[39741] IP: 192.168.1.54
[39741] Blynk v0.3.7 on ESP8266
[39741] Connecting to blynk-cloud.com:8442
[39831] <[02|00|01|00] edda09ed65974cdaa8b4c4a20b74082a
Light: 911
[41907] Login timeout
PIR high
2.6 PIR low
[44907] Connecting to blynk-cloud.com:8442
[44988] <[02|00|01|00] edda09ed65974cdaa8b4c4a20b74082a
[47069] Login timeout
Light: 985
[50069] Connecting to blynk-cloud.com:8442
[50899] <[02|00|01|00] edda09ed65974cdaa8b4c4a20b74082a
6.4 PIR high
[52977] Login timeout
3.1 PIR low
[55977] Connecting to blynk-cloud.com:8442
[56053] <[02|00|01|00] edda09ed65974cdaa8b4c4a20b74082a
[58123] Login timeout
5.1 PIR high
Light: 1024
[61123] Connecting to blynk-cloud.com:8442
[61204] <[02|00|01|00] edda09ed65974cdaa8b4c4a20b74082a
Here’s the code. The main difference as far as I can see is that in this example
I’m using virtual pins for all the communications with the app on my phone.
The project is a clone of the first one, so all the configuration data is identical.
What I have tried so far:
-
Waiting a few minutes and retrying
-
Checking that the original app still works
-
Getting a new AUTH code
-
Beer
-
More beer
-
Reading the documentation
// Button controlled relays
// Using ESP-12
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_DEBUG // Optional, this enables more detailed prints
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define RLA1 16 // opto-isolated relays
#define RLA2 14 //
#define PIR 13 // PIR detector High -- hit
#define LDR 0 // Light Dependent Resistor
#define SW1 2 // switch for RLA1
#define SW2 12 // switch for RLA2
#define LED1 4 // LED state of RLA1
#define LED2 5 // LED state of RLA2
// char auth[] = "2f75960dca504b28a5e5abaebae278b3";
char auth[] = "edda09ed65974cdaa8b4c4a20b74082a";
void setup() {
Serial.begin(9600);
Serial.println("Hello");
pinMode(RLA1, OUTPUT);
pinMode(RLA2, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(PIR, INPUT_PULLUP);
pinMode(LDR, INPUT);
pinMode(SW1, INPUT);
pinMode(SW2, INPUT);
digitalWrite(RLA1, 0);
digitalWrite(RLA2, 0);
digitalWrite(LED1, 1);
digitalWrite(LED2, 1);
// Blynk.connectWiFi("house-net", "yeah, this really is my passcode");
// Blynk.config(auth);
Blynk.begin(auth, "house-net", "no, really. It is");
digitalWrite(LED1, 0);
digitalWrite(LED2, 0);
}
bool pir_state = 0;
unsigned int change_time = 0;
unsigned int last = 0;
unsigned int sw_poll_time = 0;
int light;
bool rla1_state = 0;
bool rla1_cmd = 0;
bool rla2_state = 0;
bool rla2_cmd = 0;
void loop() {
Blynk.run();
light = analogRead(LDR);
if(rla1_cmd != rla1_state) {
pr_time(millis());
digitalWrite(RLA1, rla1_cmd);
rla1_state = rla1_cmd;
digitalWrite(LED1, rla1_state);
if(rla1_state == 1) {
Serial.println(" RLA1 closed");
} else {
Serial.println(" RLA1 opened");
}
}
if(rla2_cmd != rla2_state) {
pr_time(millis());
digitalWrite(RLA2, rla2_cmd);
rla2_state = rla2_cmd;
digitalWrite(LED2, rla2_state);
if(rla2_state == 1) {
Serial.println(" RLA2 closed");
} else {
Serial.println(" RLA2 opened");
}
}
bool new_state = digitalRead(PIR);
if(new_state) {
if(new_state != pir_state) {
pir_state = new_state;
if(change_time > 0) {
pr_time(millis()-change_time);
}
change_time = millis();
Serial.println(" PIR high");
}
} else {
if(new_state != pir_state) {
pir_state = new_state;
if(change_time > 0) {
pr_time(millis() - change_time);
}
change_time = millis();
Serial.println(" PIR low");
}
}
// poll the switches every second, toggle state when pressed
if((millis() - sw_poll_time) > 1000) {
if(digitalRead(SW1) == 0) {
if(rla1_state == rla1_cmd) {
rla1_cmd = ! rla1_cmd;
}
}
if(digitalRead(SW2) == 0) {
if(rla2_state == rla2_cmd) {
rla2_cmd = ! rla2_cmd;
}
}
sw_poll_time = millis();
}
if((millis() - last) > 10000) {
last = millis();
Serial.print("Light: ");
Serial.println(light);
}
}
void pr_time(unsigned int s) {
bool leading = 0;
int secs = s / 1000;
if(secs > 3600) {
int hours = secs / 3600;
Serial.print(hours);
Serial.print(":");
secs = secs - (hours * 3600);
leading = 1;
}
if(secs > 60) {
int mins = (secs / 60);
if((mins < 10) && (leading == 1)) {
Serial.print("0");
}
Serial.print(mins);
Serial.print(":");
secs = secs - (mins * 60);
leading = 1;
}
if((secs < 10) && (leading == 1)) {
Serial.print("0");
}
Serial.print(secs);
Serial.print(".");
Serial.print((int)(s % 1000) / 100);
}
// Update Relay1 LED
BLYNK_READ(V20)
{
Blynk.virtualWrite(V20, rla1_state);
}
// Update Relay2 LED
BLYNK_READ(V21)
{
Blynk.virtualWrite(V21, rla1_state);
}
// Value from Relay1 button
BLYNK_WRITE(V22)
{
int val = param.asInt(); // Get value as integer
if(val) { rla1_cmd = 1; }
else { rla1_cmd = 0; }
}
// Value from Relay2 button
BLYNK_WRITE(V23)
{
int val = param.asInt(); // Get value as integer
if(val) { rla2_cmd = 1; }
else { rla2_cmd = 0; }
}
// value from Timer
BLYNK_WRITE(V24)
{
int val = param.asInt(); // Get value as integer
if(val) { rla1_cmd = 1; }
else { rla1_cmd = 0; }
}