Skip to content

Instantly share code, notes, and snippets.

@NicolasDEVOUGE
Created April 30, 2019 05:33
Show Gist options
  • Save NicolasDEVOUGE/1f1c7859120a89050b81d55dbf6c62ca to your computer and use it in GitHub Desktop.
Save NicolasDEVOUGE/1f1c7859120a89050b81d55dbf6c62ca to your computer and use it in GitHub Desktop.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LOLIN_HP303B.h>
LOLIN_HP303B HP303B;
const int relayPin = D3; //Pin pour Relai
char auth[] = "*"; //Blynk
BlynkTimer timer;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Freebox-48A525";
char pass[] = "*";
int relayState = LOW; //Relais coupé
void setup()
{
// Debug console
Serial.begin(115200);
while (!Serial)
;
//Address of the HP303B (0x77 or 0x76)
HP303B.begin(); // I2C address = 0x77
Blynk.config(auth, "192.168.250.21", 8080);
Blynk.connect();
}
BLYNK_WRITE(V10)
{
int temp_voulue = param.asInt(); // assigning incoming value from pin V10 to a variable
// process received value
Serial.println("temperature voulue : ");
Serial.println(temp_voulue);
}
void loop()
{
Blynk.run();
int32_t temperature;
int16_t oversampling = 7;
int16_t ret;
Serial.println();
ret = HP303B.measureTempOnce(temperature, oversampling);
if (ret != 0)
{
Serial.print("FAIL! ret = ");
Serial.println(ret);
}
else
{
Blynk.virtualWrite(V5, temperature);
}
int32_t temp_voulue;
// si temp_capteur < temp_voulue
if (temperature < temp_voulue) {
// toggle the relay
relayState = HIGH;
digitalWrite(relayPin, relayState);
Serial.print(temperature);
Serial.print("° < ");
Serial.print(temp_voulue);
Serial.print("° on chauffe ! ");
}
else {
relayState = LOW;
digitalWrite(relayPin, relayState);
Serial.print(temperature);
Serial.print("° > ");
Serial.print(temp_voulue);
Serial.print("° on ne chauffe pas ! ");
}
timer.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment