|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
#include "mqttled.h"
|
|
|
#include "mqttled.h"
|
|
|
|
|
|
|
|
|
// C'est moche mais c'est pour récuperer EVERY_N_SECONDS :)
|
|
|
// C'est moche mais c'est pour récuperer EVERY_N_SECONDS :)
|
|
|
@ -35,12 +37,12 @@ void setupWifi() { |
|
|
Serial.print("Connexion a "); |
|
|
Serial.print("Connexion a "); |
|
|
Serial.print(wifi_ssid); |
|
|
Serial.print(wifi_ssid); |
|
|
WiFi.begin(wifi_ssid, wifi_password); |
|
|
WiFi.begin(wifi_ssid, wifi_password); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (WiFi.status() != WL_CONNECTED) { |
|
|
while (WiFi.status() != WL_CONNECTED) { |
|
|
delay(500); |
|
|
delay(500); |
|
|
Serial.print("."); |
|
|
Serial.print("."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println(); |
|
|
Serial.println(); |
|
|
Serial.print("IP : "); |
|
|
Serial.print("IP : "); |
|
|
Serial.println(WiFi.localIP()); |
|
|
Serial.println(WiFi.localIP()); |
|
|
@ -71,7 +73,7 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) { |
|
|
message_buff[i] = '\0'; |
|
|
message_buff[i] = '\0'; |
|
|
String msgString = String(message_buff); |
|
|
String msgString = String(message_buff); |
|
|
Serial.print(msgString); |
|
|
Serial.print(msgString); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (msgString == "ON") { |
|
|
if (msgString == "ON") { |
|
|
digitalWrite(LED_PIN, HIGH); |
|
|
digitalWrite(LED_PIN, HIGH); |
|
|
} else { |
|
|
} else { |
|
|
@ -82,7 +84,7 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) { |
|
|
void loop() { |
|
|
void loop() { |
|
|
testConnectMQTT(); |
|
|
testConnectMQTT(); |
|
|
client.loop(); |
|
|
client.loop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EVERY_N_SECONDS(180) { |
|
|
EVERY_N_SECONDS(180) { |
|
|
Serial.print("MQTT Subscribe refresh"); |
|
|
Serial.print("MQTT Subscribe refresh"); |
|
|
client.subscribe("homeassistant/select1"); |
|
|
client.subscribe("homeassistant/select1"); |