simplification, plus besoin de fastled
This commit is contained in:
parent
1cb4f8b6f5
commit
a77193497e
@ -2,8 +2,6 @@
|
||||
|
||||
#include "mqttled.h"
|
||||
|
||||
// C'est moche mais c'est pour récuperer EVERY_N_SECONDS :)
|
||||
#include <FastLED.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
@ -26,24 +24,22 @@ void setup() {
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
client.setCallback(callbackMQTT);
|
||||
testConnectMQTT();
|
||||
client.subscribe("homeassistant/switch1");
|
||||
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
// WIFI
|
||||
void setupWifi() {
|
||||
Serial.println();
|
||||
Serial.print("Connexion a ");
|
||||
Serial.print(wifi_ssid);
|
||||
WiFi.begin(wifi_ssid, wifi_password);
|
||||
Serial.print(WIFI_SSID);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
Serial.println(" OK");
|
||||
Serial.print("IP : ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
@ -53,6 +49,8 @@ void testConnectMQTT() {
|
||||
while (!client.connected()) {
|
||||
Serial.print("Connexion au serveur MQTT... ");
|
||||
if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
|
||||
Serial.print("OK\nSubscribe");
|
||||
client.subscribe("homeassistant/switch1");
|
||||
Serial.println(" OK");
|
||||
} else {
|
||||
Serial.print("KO, erreur : ");
|
||||
@ -64,15 +62,16 @@ void testConnectMQTT() {
|
||||
}
|
||||
|
||||
void callbackMQTT(char* topic, byte* payload, unsigned int length) {
|
||||
unsigned int i = 0;
|
||||
Serial.print("Received [" + String(topic) + "] : ");
|
||||
String stopic = String(topic);
|
||||
|
||||
unsigned int i = 0;
|
||||
for(i = 0; i < length; i++) {
|
||||
message_buff[i] = payload[i];
|
||||
}
|
||||
message_buff[i] = '\0';
|
||||
String msgString = String(message_buff);
|
||||
Serial.print(msgString);
|
||||
Serial.print("Received [" + stopic + "] : ");
|
||||
Serial.println(msgString);
|
||||
|
||||
if (msgString == "ON") {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
@ -83,11 +82,5 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) {
|
||||
|
||||
void loop() {
|
||||
testConnectMQTT();
|
||||
client.loop();
|
||||
|
||||
EVERY_N_SECONDS(180) {
|
||||
Serial.print("MQTT Subscribe refresh");
|
||||
client.subscribe("homeassistant/select1");
|
||||
Serial.println(" done");
|
||||
}
|
||||
client.loop();=
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user