Hello
I am currently running Blynk 1.0 with custom server and want to go to 2.0. I have searched but cant seem to find a clear answer on wether or not my sketch will continue to run if internet connection is down. I am going to be running an A/C unit with a particle Photon to control cooler temp. If internet goes down or connection lost will the Photon know or retain the set temp on the slider widget? I did read on the forum somewhere 2.0 would be able to accomplish this in the future, post was about 1yr old. Has this been accomplished and if so how or what do i need to do? Below is the sketch
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You’ll need:
- Blynk App (download from AppStore or Google Play)
- Arduino Ethernet board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
//#include "math.h"
//#include "adafruit-sht31.h"
// Temp/Humidity Sensor
//Adafruit_SHT31 sht31 = Adafruit_SHT31();
#include <Wire.h>
#include "DFRobot_SHT20.h"
DFRobot_SHT20 sht20;
SYSTEM_THREAD(ENABLED);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxx";
const char* IP = "xxxxxxxxxxxxxx";
bool tempflag = true;
int relaisOn = D7;
int relaisV = D6;
int hysteresis = 2;
float Thermostat = 0;
//float h = sht20.readHumidity(); // Read Humidity
//float t = sht20.readTemperature();
//float Thermostat = (t* 9) /5 + 32;
BLYNK_WRITE(V4) {
Thermostat = param.asFloat();
}
// the timer object
BlynkTimer timer;
void setup() {
// Debug console
Serial.begin(9600);
//Serial.println("SHT20 Example!");
sht20.initSHT20(); // Init SHT20 Sensor
delay(100);
sht20.checkSHT20();
Blynk.config(auth, IP, 80);
delay (5000);
timer.setInterval(7 * 1000L, sendSensor) ;
timer.setInterval(1000L, relaisAlim);
//timer.setInterval(30 * 1000L, Temp) ;
//timer.setInterval(5 * 1000L, sendTemps) ;
//timer.setInterval(5000L, TempNotify );
}
void loop()
{
Blynk.run();
timer.run();
}
void sendSensor()
{
float h = sht20.readHumidity(); // Read Humidity
float t = sht20.readTemperature();
float ftemp = (t* 9) /5 + 32;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, ftemp);
//Serial.print(" Temperature:");
//Serial.print(ftemp, 1);
//Serial.print("F");
//Serial.print(" Humidity:");
//Serial.print(h, 1);
//Serial.print("%");
}
void relaisAlim()
{
float h = sht20.readHumidity();
float t = sht20.readTemperature();
float ftemp = (t* 9) /5 + 32;
//Serial.print("Temperature : ");
// Serial.print(TempSom);
//Serial.println("°C");
//Serial.print("Thermostat : ");
//Serial.println(Thermostat);
if (ftemp >= (Thermostat + hysteresis))
{
digitalWrite(relaisOn, 1);
Blynk.virtualWrite(V3, 0);
Blynk.virtualWrite(V2, 255);
}
else if (ftemp <= (Thermostat - hysteresis))
{
digitalWrite(relaisOn, 0);
Blynk.virtualWrite(V2, 0);
Blynk.virtualWrite(V3, 255);
}
}