Hello everyone thanks for reading this post and helping me.
BASICS:
I wrote a small program to use my Lolin Nodemcu V3 to read a Temperature/humidity sensor ( HTU21D ).
The goal of my project is to read the sensor values once every 7 seconds display them on a small oled screen ( SSD1306 ), then send the values to the Blynk server to plot them on the SuperChart widget.
I’m using the Blynk_Release_v0.4.8, the app is updated and running on an Android (samsung S6), i’m using cloud server, powering the NodeMcu with an usb and battery power bank 12V, i’m using Arduino IDE 1.6.13.
THE PROBLEM:
So after sending two or three times the data to the Blynk server the ESP8266 gets disconnected… After a while it reconnects then disconnects again and again… Help please
I spent the past two days trying to solve the problem with no success, i’ve red tens of other posts of people having the same problem i have, but i wasn’t able to fix the code…
Here the code
> // Lolin NodeMcu V.3
> // HTU21D i2c sensor
> // SSD 1306 i2c OLED screen
> // Connect SDA to (D2)
> // Connect SCL to (D1)
>
> #define BLYNK_PRINT Serial
> #include <SPI.h>
> #include <ESP8266WiFi.h>
> #include <BlynkSimpleEsp8266.h>
> #include <Wire.h>
> #include "Adafruit_HTU21DF.h" // library for Sensor
> #include <ACROBOTIC_SSD1306.h> // library for OLED: SCL ==> D1; SDA ==> D2
>
> //char auth[] = "---------------------------------";
> //char ssid[] = "--------------";
> //char pass[] = "---------";
>
>
> int h=0; // variable for humidity
> int t =0; // variable for temperature
> //int ledPin = 2; // led pin
>
> Adafruit_HTU21DF htu = Adafruit_HTU21DF();
> BlynkTimer timer;
>
> void setup()
> {
> // Debug console
> Serial.begin(9600);
> // pinMode(ledPin, OUTPUT);
> oledStart();
> Blynk.begin(auth, ssid, pass);
>
> // --------Setup a function to be called every.....------
> timer.setInterval (7000L, sensing);
> }
>
> void loop()
> {
> Blynk.run();
> timer.run();
> }
>
> void sensing(){
> h = htu.readHumidity();
> t = htu.readTemperature();
> displayData();
> }
>
> /***************************************************
> * Display data at Serial Monitora & OLED Display
> **************************************************/
> void displayData(void)
> {
> oled.setTextXY(3,0); // Set cursor position, start of line 2
> oled.putString("Temp: " + String(t) + "C");
> oled.setTextXY(4,0); // Set cursor position, start of line 2
> oled.putString("Hum: " + String(h) + "%");
> // oled.setTextXY(5,0); // Set cursor position, start of line 2
> // oled.putString("Soil: " + String(soilMoister)");
>
> sendSensor();
> }
>
> /***************************************************
> * Start OLED
> **************************************************/
> void oledStart(void)
> {
> Wire.begin();
> oled.init(); // Initialze SSD1306 OLED display
> clearOledDisplay();
> //oled.setFont(font5x7); // Set font type (default 8x8)
> oled.clearDisplay(); // Clear screen
> oled.setTextXY(0,0);
> oled.putString("I still love u");
> }
>
> /***************************************************
> * Clear OLED Display
> **************************************************/
> void clearOledDisplay()
> {
> oled.setFont(font8x8);
> oled.setTextXY(0,0); oled.putString(" ");
> oled.setTextXY(1,0); oled.putString(" ");
> oled.setTextXY(2,0); oled.putString(" ");
> oled.setTextXY(3,0); oled.putString(" ");
> oled.setTextXY(4,0); oled.putString(" ");
> oled.setTextXY(5,0); oled.putString(" ");
> oled.setTextXY(6,0); oled.putString(" ");
> oled.setTextXY(7,0); oled.putString(" ");
> oled.setTextXY(0,0); oled.putString(" ");
> }
>
> /***************************************************
> * Send data to Blynk server
> **************************************************/
> void sendSensor()
> {
>
> oled.setTextXY(7,0); // Set cursor position, start of line 7
> oled.putString("Sending data");
>
> Blynk.virtualWrite(V11, h);
> Blynk.virtualWrite(V10, t);
>
> oled.setTextXY(7,0); oled.putString(" ");
> oled.setTextXY(7,0); // Set cursor position, start of line 7
> oled.putString("Data sent");
> }
Here the serial monitor:
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.4.8 on ESP8266
[21377] Connecting to blynk-cloud..com:8442
[21520] Ready (ping: 3ms).
[46839] Connecting to blynk-cloud..com:8442
[53463] Connecting to blynk-cloud..com:8442
[60712] Connecting to blynk-cloud..com:8442
[67838] Connecting to blynk-cloud..com:8442
[75036] Connecting to blynk-cloud..com:8442
[82211] Connecting to blynk-cloud..com:8442
[89386] Connecting to blynk-cloud..com:8442
[96535] Connecting to blynk-cloud..com:8442
[103711] Connecting to blynk-cloud..com:8442
[110784] Connecting to blynk-cloud..com:8442
[111780] Ready (ping: 0ms).
[127059] Connecting to blynk-cloud..com:8442
[134433] Connecting to blynk-cloud..com:8442
[141657] Connecting to blynk-cloud..com:8442
[148832] Connecting to blynk-cloud..com:8442
[156006] Connecting to blynk-cloud..com:8442