Communication between a "micro:bit" and the WWW via MicroBlocks?

Issue #78 resolved
connochaetes created an issue

Hi. I’m looking for a (not too complicated) way to communicate between a “micro:bit” and the WWW. Is there a way to achieve this by using the gpblocks based stand-alone MicroBlocks IDE?

My alternative would be to use the programming environment for MicroBlocks that is integrated into “Snap!” (under development). Once, the data is in the “Snap!” environment, I should be able to use “Snap!”'s features to interact with the WWW. But - as mentioned above - this is still under development. Thanks for your work on this.

This issue is related to this one: https://bitbucket.org/john_maloney/smallvm/issues/31/serial-and-bt-serial-support


Background information: I’m using the “micro:bit”'s sensors. It would be quite neat to monitor the data live via web interface. Furthermore, it would be useful to give commands via web interface to the “micro:bit”. In the past, I used (the quite impressive) snap4arduino which offered me these features for the arduino board.

Greetings.

Comments (12)

  1. Bernat Romagosa

    The Citilab ED1 board is not yet available for sale, but they keep promising it will be very soon. They have very recently passed the CE certification, and I believe the manufacturer is basically ready to start making them in bulk, so the online shop should be set up soon. I’ll let you know when that happens!

  2. John Maloney repo owner

    If you have a RaspberryPI, you might also be interested in the “Mozilla IoT Activity Cards” and videos here:

    http://microblocks.fun/stories

    Using the free, open-source WebThing gateway software from Mozilla, you can communicate with MicroBlocks programs running either on a microcontroller connected to the RPi via a USB cable or, if you have a board with WiFi capabilities, the gateway can talk to it wirelessly. Either way, the WebThings gateway gives you a nice UI for viewing and interacting with your “Thing”. It even allows you to tunnel into the gateway securely so you can interact with your thing from a browser anywhere on the internet. As an example, I just added a remote control system for our building’s heating system. Now, if someone in the building reports that it is cold, I can turn on the heat using my phone, even if I’m not home.

    That gateway can also log sensor data and show you a graph. I’m using that feature to track the temperature in my own unit to see how quickly it responds to the heat coming on. (I live in a 1920’s building with steam radiators. The radiators don’t get hot until about 30-40 minutes of the heat coming on and it takes longer for the temperature in the unit to go up. However, once everything is hot the radiators keep giving off heat for half an hour after the boiler goes off. The temperature graphs are helping me understand all those time constants.

  3. connochaetes reporter

    Hi. Thanks for the inspiration. Just to let you know: This sounds just good. Another nice possibility is to use a combination of different features from the world of “Snap!” & microBlocks for smaller projects. I don’t want to misuse this forum, but for you 're obviously interested in these things…

    ___

    Right now, my purpose is to use “Snap!” and microBlocks as an easy-to-use application for projects that are

    • easy to learn,
    • expandable (“sky is the limit”), and
    • based on a well-known development environment (“Snap!”).

    Inspired by Prof. Eckard Modrow from Göttingen (Germany), I use webspace with a small PHP script that enables “Snap!” zu read and write files online:

    An application using these blocks might be a small chat program. (Imagine pupils that already know this functionality.) With your new microBlocks functionality …

    http://microblocks.fun/blog-2020-01-15-microblocks,-snap!,-and-the-web

    … I 'm capable to interact with interact with sensors and actors. As a first test, I implemented “smart blinds” - blinds that close if it 's dark and open otherwise. As a feature, you can check out the light level online.

    (For it ‘s an educational project on attributes and methods of objects, I used the option “for this sprite only” and the “of”-block. I know, it 's a little more complicated as it has to be.)

    • Obviously, it 's easy to use this block …

    … in order to send commands to the microBit’s actors (e. g. a servo).

    • Or you can implement an online based microworld with a database and RFID cards (a simulation of cashless catering in schools).
    • Or …

    Again: Thanks!

  4. John Maloney repo owner

    Nice!

    It sounds like you are running the “Mozilla WebThings Server” in the MicroBlocks IDE and Snap! is communicating with that via HTTP. Just so you know, if you have one of the WiFi boards that MicroBlocks supports then Snap! can communicate with it directly using the exact same HTTP API. You just need to use the “Web Thing” library to specify the exported variables and have Snap! connect directly to the WiFi board using it’s IP address.

    I’m using this technique to create my own programmable thermostat for our 17 unit condo building. I have an OddWires IoT-Bus Io board (based on the ESP32) in the basement. That is connected to a relay which can turn the steam boiler on an off. I put the board in a basement window about 15 feet from the boiler. My WiFi router – on the third floor of a connected building – is somehow able to communicate with the board in the basement. This was a pleasant surprise since the project would have been much harder if I’d had to run a physical wire from my unit down to the basement.

  5. connochaetes reporter

    This is good news. Thanks for pointing that out.

    • Right now, I can get my hands on a Raspberry Pi and a micro:bit. So, that is an option.
    • In the future, I 'm hoping to buy a “citilab ED1 V2 'Fantàstic'” board that should offer WiFi functionality.

  6. John Maloney repo owner

    I’m running the Mozilla WebThing gateway on a Raspberry Pi. The gatway talks to both the ESP32 board that runs our boiler (over WiFi) and a micro:bit that is monitoring the temperature and light in my unit. Using Mozilla’s secure tunneling system, I can open a web browser on my gateway from anywhere; I don’t need to be connected to my LAN. That allows me to check the temperature from my phone even when I’m away from home and turn on the boiler if necessary. Very useful!

    The gateway can also log and graph sensor data. Here’s a snapshot of my light and temperature data this morning:

    The narrow little blip in the top (light) graph is when I turned on the light in the room that has the micro:bit. In the bottom (temperature) graph, you’ll see a fairly sharp rise in temperature starting at 18:00 when the heat came on yesterday evening and peaking at about 20:30, at which point the thermostat switches to a lower setting overnight. The temperature declines until around 7am, 30 minutes after the heat comes on in the morning. (It takes 30 minutes for the boiler to get going and get steam up to my unit). You’ll also see the light starting to increase with dawn on the right side of the top graph.

    For more info or to download the (free!) WebThing gateway software, check out:

    https://iot.mozilla.org

  7. Log in to comment