may be i don’t write the code in the right way or may be i m not lucky but my blynk goes to many times offline wile i m connected
this is my code could you please help me and tell me what is wrong?
in my sketch Esp8266 communicate via Wire protocol to an arduino and just gives to arduino 1 byte
could you help me?
#include <SPI.h>
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#define I2CAddressESPWifi 6
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "666833b5703b49d097c7ca9f03e3a8c2";
#define ZoneUp V4
#define ZoneDown V3
#define DELAY 10 // Delay per loop in ms
boolean up_was_pressed; // previous state
boolean down_was_pressed; // previous state
unsigned long interval = 3000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.
int HR;
int Amp;
int Batt;
int Watt;
int RPM;
int Speed;
int TWatt;
int Th;
int Zone;
int HRWatt;
byte a, b, c, d, e, f, g;
void setup()
{
Serial.begin(115200);
Wire.begin(14,12);//Change to Wire.begin() for non ESP.
Zone = 0;
//Blynk.begin(auth, "S&S", "02011964");
Blynk.begin(auth, "iPhone di Simone", "downdown");
}
void loop()
{
if (Zone < 0) {Zone = 0;}
if (Zone > 4) {Zone = 4;}
if (Watt > 200) {Watt = 0;}
if (HR > 220) {HR = 0;}
if (Speed > 100) {Speed = 0;}
if (Batt > 100) {Batt = 0;}
Blynk.run();
if ((unsigned long)(millis() - previousMillis) >= interval) {
previousMillis = millis();
Blynk.virtualWrite(V0, HR);
Blynk.virtualWrite(V1, Watt);
if (Zone == 0) {Blynk.virtualWrite(V2, "Free");}
if (Zone == 1) {Blynk.virtualWrite(V2, "Eco");}
if (Zone == 2) {Blynk.virtualWrite(V2, "Tour");}
if (Zone == 3) {Blynk.virtualWrite(V2, "City");}
if (Zone == 4) {Blynk.virtualWrite(V2, "HWRS"); }
Blynk.virtualWrite(V5, Speed);
Blynk.virtualWrite(V6, Batt);
Trasmission();
Request();
}
}
BLYNK_WRITE(ZoneUp)
{
if (param.asInt()) Zone = Zone + 1; //else lightoff();
}
BLYNK_WRITE(ZoneDown)
{
if (param.asInt()) Zone = Zone - 1; //else lightoff();
}
void Trasmission()
{
byte myArray[1];
myArray[0] = Zone;
Wire.beginTransmission(I2CAddressESPWifi); // transmit to device #8
Wire.write(myArray,1); // sends one byte
Wire.endTransmission(); // stop transmittin
delay(1);
}
void Request()
{
Wire.requestFrom(I2CAddressESPWifi, 7);
if (Wire.available())
delay(1);
{
a = Wire.read();
b = Wire.read();
c = Wire.read();
d = Wire.read();
e = Wire.read();
f = Wire.read();
g = Wire.read();
HR = a;
Batt = b;
Watt = c;
Watt = (Watt << 8) | d;
Speed = e;
RPM = f;
HRWatt = g;
/*
Serial.print("HR ");
Serial.print(HR);
Serial.print(" : Batt ");
Serial.print(Batt);
Serial.print(" : Watt ");
Serial.print(Watt);
Serial.print(" : Zone ");
Serial.print(Zone);
Serial.print(" : HRWatt ");
Serial.print(HRWatt);
Serial.print(" : Speed ");
Serial.print(Th);
Serial.print(" : RPM ");
Serial.print(RPM);
Serial.println("]");
*/
}
//delay(500);
}