Blynk Community, i have problem with transfering data to my blynk.app. I send 5 diffeent values to 5 display sensors in application simultaneously. Can you give me hint about my problem?
Code is below.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
SoftwareSerial EspSerial(2, 0); // RX, TX
boolean stringComplete = false;
const int bSize = 20;
char Buffer[bSize];
char data[bSize];
int ByteCount;
String str;
String tempStr;
String speedStr;
long inDataT;
long inDataG;
long inDataD;
long inDataF;
int speeds;
String tmp;
SimpleTimer timer_temp;
SimpleTimer timer_gas;
SimpleTimer timer_dist;
SimpleTimer timer_flame;
SimpleTimer timer_speed;
char auth[] = "e88d93a10ac24bd99f33730ecb7b5e8d";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "-----------", "-----------");
delay(10);
EspSerial.begin(9600);
delay(10);
timer_temp.setInterval(5000L, sendUptimeTemp);
timer_gas.setInterval(5000L, sendUptimeGas);
timer_dist.setInterval(5000L, sendUptimeDist);
timer_flame.setInterval(5000L, sendUptimeFlame);
timer_speed.setInterval(5000L, sendUptimeSpeed);
while (Blynk.connect() == false) {
// Wait until connected
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V10)
{
speeds = param.asInt();
}
BLYNK_WRITE(V11)
{
if (param.asInt())
{
BLYNK_LOG("forward");
}
}
BLYNK_WRITE(V12)
{
if (param.asInt())
{
BLYNK_LOG("backward");
}
}
BLYNK_WRITE(V13)
{
if (param.asInt())
{
BLYNK_LOG("left");
}
}
BLYNK_WRITE(V14)
{
if (param.asInt())
{
BLYNK_LOG("right");
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void serialEventRx()
{
while (EspSerial.available()) {
ByteCount = -1;
ByteCount = EspSerial.readBytesUntil('\n',Buffer,bSize);
if (ByteCount > 0) {
strcpy(data,Buffer);
}
memset(Buffer, 0, sizeof(Buffer));
EspSerial.flush();
stringComplete = true;
}
}
void serialEventTx(String tmp)
{
while (EspSerial.available()) {
EspSerial.println(tmp);
EspSerial.flush();
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void sendUptimeTemp()
{
Blynk.virtualWrite(V0, inDataT);
Blynk.virtualWrite(V9, inDataT);
Blynk.virtualWrite(V5, inDataT);
}
void sendUptimeGas()
{
Blynk.virtualWrite(V1, inDataG);
Blynk.virtualWrite(V4, inDataG);
}
void sendUptimeDist()
{
Blynk.virtualWrite(V2, inDataD);
Blynk.virtualWrite(V6, 1023-inDataD);
}
void sendUptimeFlame()
{
Blynk.virtualWrite(V3, inDataF);
Blynk.virtualWrite(V8, inDataF);
}
void sendUptimeSpeed()
{
Blynk.virtualWrite(V7,speeds);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void loop()
{
Blynk.run();
timer_temp.run();
timer_gas.run();
timer_dist.run();
timer_flame.run();
timer_speed.run();
serialEventRx();
if (stringComplete)
{
str = data;
if (str.startsWith("temperature"))
{
tempStr = str;
serialEventTx(tempStr);
str.remove(0,11);
str.trim();
inDataT = str.toInt();
}
if (str.startsWith("gas"))
{
tempStr = str;
serialEventTx(tempStr);
str.remove(0,3);
str.trim();
inDataG = str.toInt();
}
if (str.startsWith("distance"))
{
tempStr = str;
serialEventTx(tempStr);
str.remove(0,8);
str.trim();
inDataD = str.toInt();
}
if (str.startsWith("flame"))
{
tempStr = str;
serialEventTx(tempStr);
str.remove(0,5);
str.trim();
inDataF = str.toInt();
}
if (str.startsWith("speed"))
{
str = String(speeds, DEC);
speedStr = "speed " + str;
serialEventTx(speedStr);
}
memset(data, 0, sizeof(data));
str = "";
tempStr = "";
stringComplete = false;
}
}
Log of my connection is below.
Also interface of my profile.