Device was disconnected 2

Every time you see the token means hardware lost connection and sending login command again. So for some reason hardware drops connections. You need to investigate this. Try from posting your code here.

Okay here is the code I am using,

  • I changed the wifi router, it still gives the same result.
  • I am trying connecting to the blynk cloud server.
  • I am using the latest app version on andriod(6.0.1), Note 5.
  • I am using DHT 22 sensor, 6 channel relay, ESP8266 and Arduino Uno.
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG 
#include <SPI.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h> // include Blynk ESP8266
#include <SimpleTimer.h>
#include <DHT.h>
char auth[] = "19b*****************";
char ssid[] = "K********";
char pass[] = "**********";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // ( RX, TX )
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 4          // What digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
//Relay in Pin XX
#define Relay1 10
#define Relay2 9
#define Relay3 8
#define Relay4 7
#define Relay5 6
#define Relay6 5
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
  int RelayStatus1 = param.asInt();
  if (RelayStatus1 == 1) {
    digitalWrite(Relay1, LOW);
  }
  else {
    digitalWrite(Relay1, HIGH);
  }
}
BLYNK_WRITE(V2)
{
  int RelayStatus2 = param.asInt();
  if (RelayStatus2 == 1) {
    digitalWrite(Relay2, LOW);
  }
  else {
    digitalWrite(Relay2, HIGH);
  }
}
BLYNK_WRITE(V3)
{
  int RelayStatus3 = param.asInt();
  if (RelayStatus3 == 1) {
    digitalWrite(Relay3, LOW);
  }
  else {
    digitalWrite(Relay3, HIGH);
  }
}
BLYNK_WRITE(V4)
{
  int RelayStatus4 = param.asInt();
  if (RelayStatus4 == 1) {
    digitalWrite(Relay4, LOW);
  }
  else {
    digitalWrite(Relay4, HIGH);
  }
}
BLYNK_WRITE(V5)
{
  int RelayStatus5 = param.asInt();
  if (RelayStatus5 == 1) {
    digitalWrite(Relay5, LOW);
  }
  else {
    digitalWrite(Relay5, HIGH);
  }
}
BLYNK_WRITE(V6)
{
  int RelayStatus6 = param.asInt();
  if (RelayStatus6 == 1) {
    digitalWrite(Relay6, LOW);
  }
  else {
    digitalWrite(Relay6, HIGH);
  }
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V8, h);
  Blynk.virtualWrite(V7, t);
}
void setup()
{
  pinMode(Relay1, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay1, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay2, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay2, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay3, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay3, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay4, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay4, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay5, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay5, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay6, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay6, HIGH); // Prevents relays from starting up engaged
  // communication with the host computer
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  delay(10);
  dht.begin();
  // Setup a function to be called every 5 second
  timer.setInterval(5000L, sendSensor);
}
void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

Even the simplest blink code doesnt work? So I guess the code part is okay ?

Any sketch? Can you try http://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=GettingStarted%2FPushData
and see if it seems to disconnect around the same time, each time? This should simply display the uptime in seconds.

Code seems fine. Maybe issue in power supply? Signal strength?

The uptime is almost zero, it just says Device was disconnected at the bottom of the app after evert few seconds

Power supply for arduino is my laptop via usb and power supply for ESP8266 is an old phone charger of 5v 2A coupled with a voltage divider of 3.3V.

To help with the elimination process, can you test with the USB-link? http://docs.blynk.cc/#hardware-set-ups-arduino-over-usb-no-shield

Keep the shield on, just load this instead http://examples.blynk.cc/?board=Arduino%20Uno&shield=Serial%20or%20USB&example=GettingStarted%2FPushData

And connect via the IDE

I tried http://examples.blynk.cc/?board=Arduino%20Uno&shield=ESP8266%20WiFi%20Shield&example=GettingStarted%2FPushData

setting a display with virtual pin 5. It gives no data, just keep on doing what it was doing before, the device was disconnected

Try again using the USB link…

Blynk USB script failed
java.io.IOException: Cannot run program "/Users/junaid/Documents/Arduino/libraries/Blynk/scripts/blynk-ser.sh": error=13, Permission denied

The IDE displays this error when I run the USB script

Are you on an Apple or Windows PC?

Apple

I’m no Apple user, but I am sure they don’t use what looks like Windows directory structure…

Try following these instructions then instead of running the script from the IDE Arduino Uno and USB step by step tutorial

Start at the 5 minute mark for the relevant part.

Okay, It is working fine via the usb. The uptime is continous. The displays shows 360 and is still going on.

That means I am able to connect to the blynk server ? so the problem must be in the connection? i.e. how I have wired up the temperature sensor, relay board, esp8266 and the arduiono Uno? or it could be in the ESP8266 ? being faulty.

Yes, it means you are connected… so you can try other, more complicated scripts and sensors to test further stability… and if that all works, then the issue resides in your shield link to the Arduino, or it’s Wifi to the router… or power, or who knows what else :confused:

Confirm stability with other scripts first.

Also… what exactly is the model of the shield you use… any links or pictures?

I have tested this few other programs, looks fine.

Actually it was working fine before I connected it to a DHT 22 sensor. So I guess I’ll remove everything and connect it again one by one and see how it behaves.

I am not sure about the model of the wifi shield. its just the ESP8266-ESP-01

I think the ESP8266 has gone faulty and is not being able to hold a stable connection thats why it is behaving all weird. I’ll get a new one and will update this post.

Thanks a lot for your help. Really appreciate it.

I just had the same issue and solved it. What I was doing is checking if my device (ESP8266 12E) was connected to Blynk constantly using the code below. I think it takes about 5-8 seconds to check that. That’s was causing my device to appear “offline” even though it was online.

Below if the code I used and as soon as I removed it device was found by Blynk app. Tried multiple times, that seems to be the issue. Hope it helps someone.

void loop() {
 
  Blynk.run();
  if(Blynk.connect()== false){
  checkConnection();        //custom function I wrote to check wifi connection
  }
}

Again you don’t want to constantly check your Blynk connection status.

A post was split to a new topic: App says device was disconnected continuously