Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:remotelab:sut:generalpurpose2:u3 [2019/10/29 20:23] pczekalskien:iot-open:remotelab:sut:generalpurpose2:u3 [2021/02/27 10:00] (current) – external edit 127.0.0.1
Line 21: Line 21:
  
 === Start === === Start ===
-Define some identifiers to separate and update AP's SSID and passphrase easily. To format lines for the LCD, we suggest using a char buffer of 20 characters (one full line) and some 2-3 integers for iterators. Remember to declare the LCD control class in your code. You do not need to instantiate WiFi communication class - as you have only one interface here, it is singleton class you can refer directly using WiFi. Note - in this scenario, you connect only once. If your connection breaks, you will have no information about it here. To handle such situation, there are multiple solutions: you can check in the loop() if the connection is OK and in case it is down, you can call your re-connecting function, or you can use one of the asynchronous handlers, triggered automatically via the WiFi manager. To use the latter approach, refer to the ESP8266 WiFi implementation for Arduino documentation. +Define some identifiers to separate and update AP's SSID and passphrase easily. To format lines for the LCD, we suggest using a char buffer of 20 characters (one full line) and some 2-3 integers for iterators. Remember to declare the LCD control class in your code. You do not need to instantiate the WiFi communication class - as you have only one interface here, it is singleton class you can refer to directly using WiFi. Note - in this scenario, you connect only once. If your connection breaks, you will have no information about it here. To handle such situation, there are multiple solutions: you can check in the loop() if the connection is OK and in case it is down, you can call your re-connecting function, or you can use one of the asynchronous handlers, triggered automatically via the WiFi manager. To use the latter approach, refer to the ESP8266 WiFi implementation for Arduino documentation. 
  
 === Steps === === Steps ===
-Following steps do not present full code - you need to supply missing parts on your own! We do not present here how to connect to the WiFi AP. If you're in doubt, rever to the U1 scenario. We also do not present in details on how to organise and print DHT22 sensor data on the LCD screen. Please refer to the scenario B2 if you need a recall.+Following steps do not present full code - you need to supply missing parts on your own! We do not present here how to connect to the WiFi AP. If you're in doubt, rever to the U1 scenario. We also do not present in details how to organise and print DHT11 sensor data on the LCD screen. Please refer to scenario B2 if you need a recall.
 == Step 1 == == Step 1 ==
 Include all necessary libraries. We use ''PubSubClient'' library to contact MQTT broker. The minimum set here is: Include all necessary libraries. We use ''PubSubClient'' library to contact MQTT broker. The minimum set here is:
Line 81: Line 81:
   while (!client.connected()) {   while (!client.connected()) {
     if (client.connect(MQTTClientName, mqtt_user, mqtt_password,      if (client.connect(MQTTClientName, mqtt_user, mqtt_password, 
-    lastWillTopic, 0, true, lastWillMessage)) {+                       lastWillTopic, 0, true, lastWillMessage))  
 +    {
       client.publish(lastWillTopic, mqttWelcomeMessage, true);       client.publish(lastWillTopic, mqttWelcomeMessage, true);
-    } else {+    } else  
 +    {
       // Wait 5 seconds before retrying       // Wait 5 seconds before retrying
       delay(5000);       delay(5000);
Line 114: Line 116:
     if (!(isnan(temp)||isnan(hum)))     if (!(isnan(temp)||isnan(hum)))
     {     {
-      client.publish(tempTopic, String(temp).c_str(), false);  // Do not retain messages+      client.publish(tempTopic, String(temp).c_str(), false);  // Do not retain 
 +                                                               // messages
       client.publish(humTopic, String(hum).c_str(), false);       client.publish(humTopic, String(hum).c_str(), false);
     }     }
en/iot-open/remotelab/sut/generalpurpose2/u3.1572380600.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0