This library provides the driver for ESP8266 WiFi Grove Module. This extension is tested with Espressif ESP-AT Firmware v2.2.0.
Initialize the ESP8266 module (Tx = P16, Rx = P15, Baudrate = 115200).
esp8266.init(SerialPin.P16, SerialPin.P15, BaudRate.BaudRate115200)
Show happy face if successful.
Show sad face if failed.
if (esp8266.isESP8266Initialized()) {
basic.showIcon(IconNames.Happy)
} else {
basic.showIcon(IconNames.Sad)
}
Connect to WiFi router.
esp8266.connectWiFi("my_ssid", "my_password")
Show happy face if connected successfully.
Show sad face if failed.
if (esp8266.isWifiConnected()) {
basic.showIcon(IconNames.Happy)
} else {
basic.showIcon(IconNames.Sad)
}
Upload data to Thingspeak (Data can only be uploaded every 15 seconds).
esp8266.uploadThingspeak("my_write_api_key", 0, 1, 2, 3, 4, 5, 6, 7)
Show happy face if data is uploaded successfully.
Show sad face if failed.
if (esp8266.isThingspeakUploaded()) {
basic.showIcon(IconNames.Happy)
} else {
basic.showIcon(IconNames.Sad)
}
Read from Blynk.
let value = esp8266.readBlynk("my_blynk_token", "V0")
Write to Blynk.
esp8266.writeBlynk("my_blynk_token", "V1", "100")
Show happy face if Blynk was read/written successfully.
Show sad face if failed.
if (esp8266.isBlynkUpdated()) {
basic.showIcon(IconNames.Happy)
} else {
basic.showIcon(IconNames.Sad)
}
Initialize internet time to timezone +8.
Show sad face if failed.
esp8266.initInternetTime(8)
if (!(esp8266.isInternetTimeInitialized())) {
basic.showIcon(IconNames.Sad)
}
Update the internet time and show the time.
Show sad face if failed.
esp8266.updateInternetTime()
if (!(esp8266.isInternetTimeUpdated())) {
basic.showIcon(IconNames.Sad)
} else {
basic.showString(esp8266.getHour() + ":" + esp8266.getMinute() + ":" + esp8266.getSecond())
}
MIT
- for PXT/microbit