#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "HUAWEI-E6878-C595";
char pass[] = "@Sameera123";
SimpleTimer timer;
String myString; // complete message from arduino, which consistors of snesors data
char rdata; // received charactors
int GF_firstVal, GF_secondVal, GF_thirdVal, GF_fourthVal, GF_fifthVal, FF_firstVal, FF_secondVal, FF_thirdVal, FF_fourthVal, FF_fifthVal; // sensors
int led1,led2,led3,led4,led5,led6,led7,led8,led9,led10;
// This function sends Arduino's up time every second to Virtual Pin (1).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V1, millis() / 1000);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L,sensorvalue1);
timer.setInterval(1000L,sensorvalue2);
timer.setInterval(1000L,sensorvalue3);
timer.setInterval(1000L,sensorvalue4);
timer.setInterval(1000L,sensorvalue5);
timer.setInterval(1000L,sensorvalue6);
timer.setInterval(1000L,sensorvalue7);
timer.setInterval(1000L,sensorvalue8);
timer.setInterval(1000L,sensorvalue9);
timer.setInterval(1000L,sensorvalue10);
}
void loop()
{
if (Serial.available() == 0 )
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
if (Serial.available() > 0 )
{
rdata = Serial.read();
myString = myString+ rdata;
// Serial.print(rdata);
if( rdata == '\n')
{
Serial.println(myString);
// new code
String l = getValue(myString, ',', 0);
String m = getValue(myString, ',', 1);
String n = getValue(myString, ',', 2);
String o = getValue(myString, ',', 3);
String p = getValue(myString, ',', 4);
String q = getValue(myString, ',', 5);
String r = getValue(myString, ',', 6);
String s = getValue(myString, ',', 7);
String t = getValue(myString, ',', 8);
String u = getValue(myString, ',', 9);
// these leds represents the leds used in Blynk application
led1 = l.toInt();
led2 = m.toInt();
led3 = n.toInt();
led4 = o.toInt();
led5 = p.toInt();
led6 = q.toInt();
led7 = r.toInt();
led8 = s.toInt();
led9 = t.toInt();
led10 = u.toInt();
myString = "";
// end new code
}
}
}
void sensorvalue1()
{
int sdata = led1;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V10, sdata);
}
void sensorvalue2()
{
int sdata = led2;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V11, sdata);
}
void sensorvalue3()
{
int sdata = led3;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V12, sdata);
}
void sensorvalue4()
{
int sdata = led4;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V13, sdata);
}
void sensorvalue5()
{
int sdata = led5;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V14, sdata);
}
void sensorvalue6()
{
int sdata = led6;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V15, sdata);
}
void sensorvalue7()
{
int sdata = led7;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V16, sdata);
}
void sensorvalue8()
{
int sdata = led8;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V17, sdata);
}
void sensorvalue9()
{
int sdata = led9;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V18, sdata);
}
void sensorvalue10()
{
int sdata = led10;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V19, sdata);
}
// Function used to split string message using comma
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
Please edit your post and add triple backticks ( ``` ) before and after your sketch.
2 Likes
@Samiixv please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Pete.
1 Like
I have no idea what sort of values you are writing to the LEDs when you do this…
but an LED widget requires a value of 255 to turn it on at full brightness.
As for the rest of your code, it’s a total mess with a cluttered void loop and 10 timers that are all being called simultaneously.
Pete.
You should check this out
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean
The ideal blynk void loop should look like this
void loop()
{
Blynk.run();
timer.run();
}
1 Like