Announcement

Collapse
No announcement yet.

Project weekend: Using MQTT with HS3

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Project weekend: Using MQTT with HS3

    Spent this weekend doing a project using some old ARM boards I had around to start using MQTT to centralize my sensor data a bit from multiple sources. Sorry for the long post, but figured it may interest a few people here.

    Currently I had data coming from a few places that I started with:

    - 1-wire -> XapMCS1wire -> Xap -> Xap Plugin -> Homeseer
    - Davis Weather station -> Weewx -> Wunderground, APRS-IS, *not* connected to Homeseer
    - ESP8266 wifi boards I wanted to use (coming soon!)

    Starting config:
    - HS3 on Windows, running MQTT plugin from Updater (more details here http://www.domoticaforum.eu/viewforum.php?f=74)
    - Weewx on a BeagleBone Black running Ubuntu

    MQTT Server:
    Coworker gave me a Raspberry Pi 2 he didn't need, so decided to use this for the MQTT server. Started with Linux Mint, removed the UI and installed Mosquitto server following these directions:
    https://lukeisadog.wordpress.com/201...buntu-round-1/
    Took literally 5mins to get running... was amazed how easy. Added auth support, but MQTT plugin in HS I don't see a way to do auth with it, so optional for now.

    MQTT Plugin Initial Config:

    Started with a simple config since my own internal network, and set the subscribe path to watch everything, "#, /#"

    WeeWX:

    This was actually a lot easier than I thought. I had already been pushing data to Wunderground and APRS-IS, but wanted to also be able to receive within HS. turns out there's a WeeWX plugin for MQTT:
    https://github.com/weewx/weewx/wiki/mqtt

    Changed setting in weewx.conf to match my server details, and within a few minutes starting seeing data on the MQTT server using the command:

    Code:
    mosquitto_sub -t \#
    Output:
    Code:
    weather/monthET 0.0
    weather/barometer_inHg 29.6840967742
    weather/windrun_mile 0.0
    weather/rainAlarm 0.0
    weather/dayET 0.0
    weather/interval_minute 1.0
    weather/dewpoint_F 15.5842869329
    1-Wire:
    I've been using 1-wire for yeeaaars with XapMCS1wire and the MCSXap plugin (they work GREAT btw.) However lately wanted to try my hand at using OWServer, http://owfs.org/ so I could use some existing wiring going thru the house for Ethernet as a generic sensor network instead of just 1wire. (This is sort of what started this project off...) Plan is to add OWServers in the two key areas; attic and basement then reuse the existing cat5 going to attic for 1wire to be a normal LAN (chase pipe to attic is already pretty full...)

    Right now I've started with the first server using an old Beagle Bone Black in the basement until I split the network into pieces. This BBB is running Ubuntu Server, with DS9490 USB plugged into the back. Installation of OWW was thru the normal Ubuntu packages, and set the config files using this post:
    https://www.raspberrypi.org/forums/v...27379&p=505250

    IMPORTANT NOTE: I'm not using OWFS but the OWServer Service ATM as not need for it. more on that in a moment.

    1-Wire to MQTT Bridge:
    This is where the magic happens... After some Google searches I found an OW Server to MQTT python script that did 90% of what I needed:
    https://github.com/kylegordon/mqtt-owfs-temp

    However it's a few years old, and only supported temperature sensors. It did support OWServer queries directly, so no need to do an OWFS local mount and parse it. I started doing some modifications, and forked my own version here:
    https://github.com/mloebl/mqtt-owfs-temp

    I added support for Humidity, Barometer and Illuminance sensors, including more complex pathing. Details on packages I needed to install are in the readme file within that repo. It's still only supports a few sensors, but wouldn't be hard to modify to add more as needed. Also seems to support sensors thru the Hobby Boards hub that are in the attic until I split it, so double bonus. This python script runs and queries the OWserver every 60s, and dumps to my MQTT server here:
    Code:
    /raw/owserver01/1-wire/1F.497F02000000/main/26.CDA721010000/humidity 45.8854
    /raw/owserver01/1-wire/1F.497F02000000/main/10.F54D7C020800/temperature 41.25
    /raw/owserver01/1-wire/26.09E39D000000/B1-R1-A/pressure 29.803598403
    /raw/owserver01/1-wire/1F.497F02000000/main/26.CDA721010000/S3-R1-A/illuminance 65.8839
    Data Aggregation Within Homeseer3:
    The MQTT plugin makes this pretty easy. You can easily subscribe to MQTT topics thru their subscription options. You can see the topic paths using the mosquitto_sub I mentioned above:




    Current Configuration:
    - HS3 on Windows, running MQTT plugin connected to MQTT server
    - Mosquitto MQTT server running Ubuntu
    - Davis Weather station-> Weewx Server on Ubuntu Server-> WeeWX MQTT Plugin->MQTT Server
    - 1-wire ->OWFS OWServer on Ubuntu -> Python MQTT Script running as a service->MQTT Server

    Going to run with this for a couple weeks and see how it does. We've used MQTT at work for some past projects, but first time I've gotten my hands dirty with it. Pretty happy with the results so far and was amazed how easy it was. Worst part of the project, that I left out above, was when I reused an IP addressed from an old server that apparently had powered on by accident... So spent 2 days trying to figure out why some things could connect and others couldn't to the MQTT server... oops

    #2
    Thanks for the great write-up. I am also considering installing an MQTT server on a pi. Any reason you went with Mint rather than the standard Raspbian?

    Cheers
    Al
    HS 3.0.0.548: 1990 Devices 1172 Events
    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

    Comment


      #3
      Originally posted by sparkman View Post
      Thanks for the great write-up. I am also considering installing an MQTT server on a pi. Any reason you went with Mint rather than the standard Raspbian?

      Cheers
      Al

      No other reason than I prefer Ubuntu... basically removing the GUI and installing the server package set gives you an Ubuntu server ready to go

      Comment


        #4
        Another minor note, I'd probably run Mosquitto MQTT server on my HS3 box if it was running linux. Unfortunately ADIO-100 plugin doesn't work on Linux, so stuck with Windows for now.

        Comment


          #5
          Thanks


          Sent from my iPhone
          Tom
          baby steps...starting again with HS3
          HS3Pro: Z-NET & 80 Z wave Devices,
          HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
          Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
          In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
          System: XP on Fanless Mini-ITX w/ SSD

          Comment


            #6
            Another update...

            This weekend got an Arduino Yun, loaded up the Adafruit MQTT sample application, and testing replacing my ADIO-100 with this instead. Took maybe an hour of coding and super easy. Waiting for a terminal blocker header and will test it out with the Dakota Wireless Receiver

            The other thing I did today was write a Python script to read my TED1000 and post it to MQTT, it's based on this script; http://svn.navi.cx/misc/trunk/python/ted.py

            If anyone's interested, I can write it up and post it as well:
            Code:
            /raw/arm.localdomain/ted1000/house_code 69
            /raw/arm.localdomain/ted1000/HiVrmsMtd 139.7
            /raw/arm.localdomain/ted1000/kwH_month 921.142417562
            /raw/arm.localdomain/ted1000/volts 120.5
            /raw/arm.localdomain/ted1000/kwH_today 32.1682731003
            /raw/arm.localdomain/ted1000/kw 1.33
            /raw/arm.localdomain/ted1000/HiVrmsTdy 122.7
            /raw/arm.localdomain/ted1000/LoVrmsMtd 113.6
            /raw/arm.localdomain/ted1000/LoVrmsTdy 118.5
            /raw/arm.localdomain/ted1000/house_code 69
            /raw/arm.localdomain/ted1000/HiVrmsMtd 139.7
            /raw/arm.localdomain/ted1000/kwH_month 921.142417562
            /raw/arm.localdomain/ted1000/volts 120.5
            /raw/arm.localdomain/ted1000/kwH_today 32.1682731003
            /raw/arm.localdomain/ted1000/kw 1.34
            /raw/arm.localdomain/ted1000/HiVrmsTdy 122.7
            /raw/arm.localdomain/ted1000/LoVrmsMtd 113.6
            /raw/arm.localdomain/ted1000/LoVrmsTdy 118.5
            About an hour to reflash and configure an old Beagle Bone, and then another hour or so of coding. Polls the TED 1000 unit every second vs the Aeon Labs I was looking to put in that I believe is every minute?

            Comment


              #7
              For those at some point in the future who find this post... here's the github repo for getting MQTT running with TED1000 and posting energy to HS every seconds:

              https://github.com/mloebl/mqtt-ted1000

              Comment


                #8
                Friday night started playing with some NodeMCU ($9 from Amazon) and DHT22 sensors. NodeMCUs are ESP8266 wifi modules with a built in USB connector, power supply and break out pins. Makes it super easy to program them vs the stand alone ESP8266 modules. Using a couple Arduino sketch examples from Adafruit and the Arduino IDE, I created relatively cheap Wifi temp/humidity sensors I can put around the house.
                Code:
                /raw/nodemcu01/humidity 34.80
                /raw/nodemcu01/temperature 67.64
                Also officially eliminated my ADIO-100 as well for the driveway sensors using the Arduino Yun connected to my Dakota Wireless receiver. Events come in ~1s of the contact vs delayed before (and no more errors in the log!) Using a PoE module on the Yun to power it, and pretty cool as can upload configuration changes via Wifi or ethernet if required (didn't realize it did this, good job Arduino.cc on that one!)

                If you seriously haven't checked out MQTT... definitely worth a few minutes. The fact it works with so many devices and languages, it's pretty darn cool

                Comment


                  #9
                  Reading your excellent progress is driving me nuts in that I just need to find time to do this. Your work opens up a whole new path to sensors.
                  Which poe module did you use or where did you buy it.


                  Sent from my iPhone
                  Tom
                  baby steps...starting again with HS3
                  HS3Pro: Z-NET & 80 Z wave Devices,
                  HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
                  Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
                  In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
                  System: XP on Fanless Mini-ITX w/ SSD

                  Comment


                    #10
                    Originally posted by TomTom View Post
                    Reading your excellent progress is driving me nuts in that I just need to find time to do this. Your work opens up a whole new path to sensors.
                    Which poe module did you use or where did you buy it.


                    Sent from my iPhone
                    I had the same feelings as well which is what got me so excited about it. I finally split my 1-wire network as well this weekend, so have a Pi owfs 1wire server in the basement, and a second one up in the attic now. I had been looking at the Arduino plugins, and the MySensors ones as well. However this ended up sort of eliminating that need for me.

                    I couldn't find a PoE module on Amazon that worked, but this one seems to work:
                    http://www.ebay.com/itm/201395723489

                    A slight hum when plugged in, but working ok.

                    Really only "issue" I have found so far is the MQTT plugin seems to set the status/value kind of weird. If I send the "Off" string, HS updates beautifully, but I can't use that for events like I wanted. If I send a "0" instead, works great for events, but then it won't let me change the device string to "Off" thru the device settings. I'll probably ping the author about it to see if he has some ideas. Same sorta deal with formatting the numbers so not 8 digits long

                    But overall it seems to be working pretty well. HS3/MQTT/TED1000 seem to have no problems with my 1s updates on the power monitor either.

                    Comment


                      #11
                      So seeing the great work Mike's done inspired me to get on it. Let me just say it took me more than 5min that it took Mike . For Linux noob like me it took me 3-4 hours just because I had forgotten a lot of things from my previous dealing with linux and pi.

                      Using Mike's links above, I've come up with a set of Hand Holding Instructions that should get your MQTT server up without much thought.

                      1. Download Ubuntu for PI 2 or 3:
                      https://ubuntu-mate.org/raspberry-pi/

                      2. Unzip the downloaded Ubuntu .xz file using 7-zip:
                      http://www.7-zip.org/download.html
                      Now you'll have a .img file

                      3. Use Win32DiskImager to burn the image, .img file, on to SD card(minimum 8GB)

                      4. Insert your SD card, and boot up your Ubuntu Pi.
                      You will need to setup username, computer name, and password.

                      5. Use the Mate Terminal software on your Ubuntu Pi( Applications > System Tools > Mate Terminal) for the rest of the instructions. Remember to connect your HDMI cable to a monitor for this.
                      OR
                      For Remote Access Your Ubuntu Pi. See Remote Access Option(below).

                      6. If your using Mate Terminal on your Ubuntu Pi then go to
                      Applications > System Tools > Mate Terminal
                      Type the following:

                      MQTT Install Instruction:

                      Code:
                      sudo apt-get install python-software-properties
                      
                      sudo apt-get install software-properties-common
                      
                      
                      sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
                      
                      sudo apt-get update
                      
                      sudo apt-get install mosquitto
                      
                      sudo apt-get install mosquitto-clients
                      Well your done setting up your Ubuntu Pi MQTT Server!! Thanks Mike!!


                      ---------------------------------------------------------------------
                      Remote Access Option
                      - To remote access your Ubuntu Pi - Install OpenSSH to get SSH to Access to your Pi.
                      On your Ubuntu Pi go to Applications > System Tools > Mate Terminal
                      Type the following:
                      Code:
                      sudo apt-get install openssh-server
                      This will allow you to get SSH Access of you Ubuntu Pi.
                      Now Use Putty on your PC to access your Ubuntu Pi.
                      Then follow MQTT Install Instruction(above)

                      I'm stopping for now. Will tackle HS3 Setup and rest after I get my Yun.
                      Last edited by TomTom; May 24, 2016, 04:01 PM.
                      Tom
                      baby steps...starting again with HS3
                      HS3Pro: Z-NET & 80 Z wave Devices,
                      HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
                      Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
                      In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
                      System: XP on Fanless Mini-ITX w/ SSD

                      Comment


                        #12
                        @TomTom: Nice! Sorry I guess I could have put a few more details for people I use Linux a lot with my day job, so take a lot of it for granted.

                        I got an inexpensive esp8266 talking to it as well, though hitting a power limitation on the USB adapter i was using, so the readings from the DHT22 were intermittent from that one. The nodemcu however has been rock solid. Hoping to get an enclosure printed it out so I can mount it. I managed to put on a light web server on it as well for tracking sensor data:

                        Code:
                        Humidity (%): 33.70
                        Temperature (C): 20.20
                        Temperature (F): 68.36
                        VCC Voltage (volts): 2.943
                        This weekend I attempted to get ssl running on 8883 with certs, but not going well for the clients. Seeing if I can get owntrack to communicate with it.

                        Comment


                          #13
                          Very nice Mike!

                          How are your DHT22 numbers comparing to the old one wire Honeywell HIH-3605?

                          Yup; here still on the older Temp05 and Temp08 1-Wire devices (well and xAP) originally installed in a star topology (which today is wrong).

                          Lately here have been purchasing everything from Amazon Prime. It is that 2-day stuff that I like. Noticed the WiFi Module - ESP8266 for around $3 with free shipping on Ebay.
                          - Pete

                          Auto mator
                          Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb- Mono 6.12.X - HSTouch on Intel tabletop tablets
                          Homeseer Zee2 (Lite) - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e - CherryTrail x5-Z8350 BeeLink 4Gb BT3 Pro - Mono 6.12.X
                          HS4 Pro - V4.1.11.0 - Ubuntu 20.01/VB W7e 64 bit Intel Kaby Lake CPU - 32Gb - Mono
                          6.10.0.104
                          HS4 Lite -

                          X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Smartthings hub, Hubitat Hub, and Home Assistant

                          Comment


                            #14
                            Originally posted by Pete View Post
                            Very nice Mike!

                            How are your DHT22 numbers comparing to the old one wire Honeywell HIH-3605?
                            Not too bad at all. I have it a few feet away from it the Davis weather station console, which also monitors indoors. The DHT22 is usually pretty close to that as well.

                            Comment


                              #15
                              Here's the sample ESP8266/NodeMCU Arduino sketch I am using:

                              Code:
                              /***************************************************
                                Adafruit MQTT Library Arduino Yun Example
                              
                                Make sure your Arduino Yun is connected to a WiFi access point which
                                has internet access.  Also note this sketch uses the Console class
                                for debug output so make sure to connect to the Yun over WiFi and
                                open the serial monitor to see the console output.
                              
                                Works great with the Arduino Yun:
                                ----> https://www.adafruit.com/products/1498
                              
                                Adafruit invests time and resources providing this open source code,
                                please support Adafruit and open-source hardware by purchasing
                                products from Adafruit!
                              
                                Written by Tony DiCola for Adafruit Industries.
                                MIT license, all text above must be included in any redistribution
                              
                               **************************************************
                               
                               Adapted for the ESP8266 Boards
                               
                               This is also using the Adafruit DHT libraries which can be downloaded
                                from GitHub:
                                https://github.com/adafruit/DHT-sensor-library
                              
                               ****************************************************/
                              
                              #include <ESP8266WiFi.h>
                              #include "Adafruit_MQTT.h"
                              #include "Adafruit_MQTT_Client.h"
                              #include "DHT.h"
                              
                              /************************* Adafruit.io Setup *********************************/
                              
                              #define AIO_SERVER      "MQTT_SERVER_REPLACE"
                              #define AIO_SERVERPORT  1883
                              #define AIO_USERNAME    "optional_username_replace"
                              #define AIO_KEY         "optional_password_replace"
                              #define AIO_FEEDNAME    "/raw/nodemcu"  # Change this to what you may want to use
                              
                              /************ Global State (you don't need to change this!) ******************/
                              
                               #define DHTPIN 4     // NodeMCU
                              // #define DHTPIN 2     // ESP8266
                              #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
                              
                              DHT dht(DHTPIN, DHTTYPE);
                              ADC_MODE(ADC_VCC);
                              
                              WiFiClient client;
                              WiFiServer server(80);
                              
                              // Store the MQTT server, username, and password in flash memory.
                              // This is required for using the Adafruit MQTT library.
                              const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
                              const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
                              const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;
                              const char MQTT_FEEDNAME[] PROGMEM  = AIO_FEEDNAME;
                              
                              const char* ssid     = "ssid_replace";
                              const char* password = "password_replace";
                              
                              
                              
                              const int delaytime = 10000;
                              int loop_counter = 10;
                              float humidity = 0;
                              float temp_f = 0;
                              float temp_c = 0;
                              
                              // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
                              Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
                              
                              /****************************** Feeds ***************************************/
                              
                              const char HUMIDITY_FEED[] PROGMEM = AIO_FEEDNAME "/humidity";
                              const char TEMPERATURE_FEED[] PROGMEM = AIO_FEEDNAME "/temperature";
                              const char VOLTAGE_FEED[] PROGMEM = AIO_FEEDNAME "/volts";
                              
                              Adafruit_MQTT_Publish humiditySensor = Adafruit_MQTT_Publish(&mqtt, HUMIDITY_FEED);
                              Adafruit_MQTT_Publish temperatureSensor = Adafruit_MQTT_Publish(&mqtt, TEMPERATURE_FEED);
                              Adafruit_MQTT_Publish voltageSensor = Adafruit_MQTT_Publish(&mqtt, VOLTAGE_FEED);
                              
                              // Setup a feed called 'onoff' for subscribing to changes.
                              // const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
                              
                              // Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
                              
                              /*************************** Digital Input Pins *****************************/
                              
                              /*************************** Sketch Code ************************************/
                              
                              
                              
                              void setup() {
                              
                                Serial.begin(115200);
                                delay(100);
                               
                                // We start by connecting to a WiFi network
                               
                                Serial.println();
                                Serial.println();
                                Serial.print("Connecting to ");
                                Serial.println(ssid);
                              
                                WiFi.mode(WIFI_STA);
                                WiFi.begin(ssid, password);
                                 
                                
                                while (WiFi.status() != WL_CONNECTED) {
                                  delay(500);
                                  Serial.print(".");
                                }
                               
                                Serial.println("");
                                Serial.println("WiFi connected");  
                                Serial.println("IP address: ");
                                Serial.println(WiFi.localIP());
                                
                                // Bridge.begin();
                                
                                Serial.println(F("MQTT Server"));
                                server.begin();
                                // Setup MQTT subscription for onoff feed.
                                // mqtt.subscribe(&onoffbutton);
                              
                              }
                              
                              // uint32_t x=0;
                              
                              
                              void loop() {
                                // Ensure the connection to the MQTT server is alive (this will make the first
                                // connection and automatically reconnect when disconnected).  See the MQTT_connect
                                // function definition further below.
                                MQTT_connect();
                              
                              
                              
                                // ping the server to keep the mqtt connection alive
                                if(! mqtt.ping()) {
                                  Serial.println(F("MQTT Ping failed."));
                                }
                              
                               // delay(200);
                              
                                float h = 0;
                                // Read temperature as Celsius (the default)
                                float t = 0;
                                // Read temperature as Fahrenheit (isFahrenheit = true)
                                float f = 0;
                              
                                // Get ADC voltage
                                float v = ((float)ESP.getVcc() / 1000);
                                
                                if (loop_counter == 10)
                                {
                                // Reading temperature or humidity takes about 250 milliseconds!
                                // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
                                h = dht.readHumidity();
                                // Read temperature as Celsius (the default)
                                t = dht.readTemperature();
                                // Read temperature as Fahrenheit (isFahrenheit = true)
                                f = dht.readTemperature(true);
                              
                                // Check if any reads failed and exit early (to try again).
                                if (isnan(h) || isnan(t) || isnan(f)) {
                                  Serial.println("Failed to read from DHT sensor!");
                                  return;
                              
                                Serial.print("Humidity: ");
                                Serial.print(h);
                                Serial.print(" %\t");
                                Serial.print("Temperature: ");
                                Serial.print(t);
                                Serial.print(" *C ");
                                Serial.print(f);
                                Serial.println(" *F\t");
                                
                                }
                                
                              
                                humidity = h;
                                temp_f = f;
                                temp_c = t;
                                humiditySensor.publish(h);
                                temperatureSensor.publish(f);
                                voltageSensor.publish(v);
                                
                                loop_counter = 0;
                                
                                }
                              
                              
                                WiFiClient client = server.available();
                                client.println("HTTP/1.1 200 OK");
                                client.println("Content-Type: text/html");
                                client.println("Connection: close");  // the connection will be closed after completion of the response
                                client.println("Refresh: 10");  // refresh the page automatically every 5 sec
                                client.println();
                                client.println("<!DOCTYPE html>");
                                client.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
                                client.println("<head>\n<meta charset='UTF-8'>");
                                client.println("<title>ESP8266 Temperature & Humidity DHT11 Sensor</title>");
                                client.println("</head>\n<body>");
                                client.println("<H2>ESP8266 & DHT22 Sensor</H2>");
                                client.println("<H3>Humidity / Temperature</H3>");
                                client.println("<pre>");
                                client.print("Humidity (%): ");
                                client.println((float)humidity, 2);
                                client.print("Temperature (C): ");
                                client.println((float)temp_c, 2);
                                client.print("Temperature (F): ");
                                client.println((float)temp_f, 2);
                                client.print("VCC Voltage (volts): ");
                                client.println((float)v, 3);
                                client.println("</pre>");
                                client.print("</body>\n</html>");
                              
                                loop_counter++;
                                delay(1000);
                              }
                              
                              // Function to connect and reconnect as necessary to the MQTT server.
                              // Should be called in the loop function and it will take care if connecting.
                              void MQTT_connect() {
                                int8_t ret;
                              
                                // Stop if already connected.
                                if (mqtt.connected()) {
                                  return;
                                }
                              
                                Serial.print("Connecting to MQTT server" + String(AIO_SERVER) + " on port " + String(AIO_SERVERPORT) + "... ");
                              
                                while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
                                     Serial.println(mqtt.connectErrorString(ret));
                                     Serial.println("Retrying MQTT connection in 5 seconds...");
                                     mqtt.disconnect();
                                     delay(5000);  // wait 5 seconds
                                }
                                Serial.println("MQTT Connected!");
                              
                                
                              }

                              Comment

                              Working...
                              X