acastanet / ESP8266_MB_Alex

MakeCode ESP8266 ThingSpeak and http

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MakeCode Extension for ESP8266 Wifi Modules and ThingSpeak IoT Platform

pctdetail 775-090 1 92153_wm_logo

This extension/package is heavily modified from elecfreaks/pxt-esp8266iot, also derived from my first modification and my micro:bit web server project. This version has less blocks and checks the AT responses whenever the ESP8266 tries to connect Wifi, ThingSpeak as well as uplolding data.

This extension is primary targeted for ESP-01/ESP-01S or similar ESP8266 Wifi modules loaded with factory firmware, so that you can make ThingSpeak IoT projects on BBC micro:bits.

You need a account and a channel on ThingSpeak to get the write API key. Please do not share your Wifi and API info online.

Wiring

esp8266-pinout

Connect VCC and CH to 3.3V (sufficint power needed, about 200-400 mA at least; the power from micro:bit's USB port alone is NOT ENOUGH), GND to GND, TX (transmit) and RX (receive) to two I/O pins, ignore the rest. See here for more details. Sometimes you might also need to unplug and re-plug power to start up the ESP8266 properly.

You can also add a USB-to-TTL module to read full AT responses from your ESP8266 via terminal software on your computer: (The LED in the circuit is not needed)

microbit_esp8266_ArNB60xdJd

Noted that the Tx and Rx in the picture above represents the reassigned serial port pins of micro:bit:

  • Tx of micro:bit -> Rx of ESP8266
  • Rx of micro:bit -> Tx of ESP8266

Sample Code

Use initialize block to connect to your Wifi router, and use upload block to update data to your channel on ThingSpeak.

If it failed to connect to Wifi in the first place, the update block would do nothing. If the update block failed to connect to ThingSpeak first, it would not send the data. You can use other blocks to check the status.

Is is also recommended to wait several seconds between each update. Not every connect or update attempt would be successful on ThingSpeak.

microbit-screenshot

ESP8266_ThingSpeak.connectWifi(
SerialPin.P0,
SerialPin.P1,
BaudRate.BaudRate115200,
"your_ssid",
"your_pw"
)
basic.forever(function () {
    ESP8266_ThingSpeak.connectThingSpeak(
    "api.thingspeak.com",
    "your_write_api_key",
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0
    )
    ESP8266_ThingSpeak.wait(5000)
})

In the pic below is the test result of uploading analog readings of MQ7/MQ2 sensors.

1

License

MIT

Supported targets

  • for PXT/microbit

About

MakeCode ESP8266 ThingSpeak and http

License:MIT License


Languages

Language:TypeScript 98.6%Language:Makefile 1.4%