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.
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)
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
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.
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.
MIT
- for PXT/microbit