Android Tutorial [B4X][IoT] - Monitor the home temperature with Adafruit IO

Discussion in 'Tutorials & Examples' started by Erel, Jun 19, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Adafruit IO is a cloud service built for IoT solutions. It provides two interfaces: MQTT and REST API. It is very simple to use it with B4X as demonstrated in this example.

    It is more than a MQTT broker. It also saves the historic values and allows integration with other services.
    As this is a cloud service you can use it over the internet, which is very nice.

    Each topic is mapped to a "feed". For this example we will be using two feeds:


    The ping feed is required for the reconnect method.

    In this example an ESP8266 is connected to a BMP180 temperature sensor and it sends the temperature to the temperature topic.
    Other connected devices monitor the temperature:



    - The Arduino connects to the non-ssl port. Other platforms should connect to the ssl port.
    - You need to update the username and password in the examples. The password is the AIO key.
    - The payload should be a string. Raw bytes will not be sent properly. If you need to send more complex messages then you can use B4RSerializator and convert the bytes to a hex string (ByteConverter.HexFromBytes) and then back from a hex string to bytes.
    - The B4A, B4i and B4J code is very similar. The main difference is that in B4A the communication is managed in the Starter service.

    Attached Files:

    Last edited: Jun 20, 2017
    gvoulg, rwblinn, DavideV and 8 others like this.
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Very nice Erel,
    I might look into this but parts of my home is already running on MQTT from another supplier, so changing to Adafruit IO will just be time consuming to me for basically the same results as I'm already getting with your MQTT library.

    It does look interesting though, so I'll definitely be learning it and I might even use it for other things in the future, but just not for my personal Smart Home solution.

    Thank you again for yet another awesome solution.
  3. Erel

    Erel Administrator Staff Member Licensed User

    Note that this example is also based on the same MQTT library.

    The main differences between Adafruit IO and a local MQTT broker are:
    - Adafruit IO is accessible over the internet.
    - It stores historic values which are available through the REST API.

    It can be useful if you want to create a smart home solution that is also accessible outside of the house. You can also use both a local broker and Adafruit IO.
    Peter Simpson likes this.
  4. Peter Simpson

    Peter Simpson Expert Licensed User

    Good Morning @Erel,
    I already use a free internet based MQTT broker called, I use your jMQTT library with Android and also your rMQTT library with WeMos. I personally don't use an internal MQTT broker, I don't really want to set one up. I use to interact with devices in my house when I'm not actually there, like some MQTT connected lights and hopefully my blinds sooner rather than later.

    I might look into Adafruit IO when I get some spare time, but I can already control devices in my house from anywhere on the planet through your aforementioned libraries with an app that I've created from my Android devices.

    "- It stores historic values which are available through the REST API", now this does sound rather interesting to me though ;)
    Last edited: Jun 20, 2017
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice