From 19ecd646ed6ada9c0224d7b0a4a152f0e4779fc5 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Sun, 2 Jun 2019 11:36:47 +0200 Subject: [PATCH] add simple software for kitchen heater --- .../kitchen_pilot_wire_control.ino | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino diff --git a/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino b/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino new file mode 100644 index 0000000..5eb5491 --- /dev/null +++ b/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino @@ -0,0 +1,57 @@ +/* + SimpleMQTTClient.ino + The purpose of this exemple is to illustrate a simple handling of MQTT and Wifi connection. + Once it connects successfully to a Wifi network and a MQTT broker, it subscribe to a topic and send a message to it. + It will also send a message delayed 5 seconds later. +*/ + +#include "EspMQTTClient.h" + +EspMQTTClient client( + "rico2", + "xxxxxx", + "192.168.1.3", // MQTT Broker server ip + "MQTTUsername", // Can be omitted if not needed + "MQTTPassword", // Can be omitted if not needed + "pilote_cuisine", // Client name that uniquely identify your device + 1883 // The MQTT port, default to 1883. this line can be omitted +); + +const int heating_pin = 14; + +void message_callback(const String &message) +{ + Serial.println(message); + if (message == "off") { + digitalWrite(heating_pin, LOW); + } + if (message == "on") { + digitalWrite(heating_pin, HIGH); + } +} + +void setup() +{ + pinMode(heating_pin, OUTPUT); // Initialize the LED_BUILTIN pin as an output + digitalWrite(heating_pin, LOW); // Turn the LED on (Note that LOW is the voltage level + + Serial.begin(115200); + + // Optionnal functionnalities of EspMQTTClient : + client.enableDebuggingMessages(); // Enable debugging messages sent to serial output + client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password"). + //client.enableLastWillMessage("TestClient/lastwill", "I am going offline"); // You can activate the retain flag by setting the third parameter to true +} + +// This function is called once everything is connected (Wifi and MQTT) +// WARNING : YOU MUST IMPLEMENT IT IF YOU USE EspMQTTClient +void onConnectionEstablished() +{ + // Subscribe to "mytopic/test" and display received message to Serial + client.subscribe("chauffage/cuisine", &message_callback); +} + +void loop() +{ + client.loop(); +}