Cannot upload data to ThingSpeak through IOT:bit Expansion Board

Jane on 26 Nov 2024
Latest activity Reply by Vinod on 9 Dec 2024

I am using the ELECFREAKS IOT:bit Expansion Board with micro:bit to record data, it worked normally but in this week I tested again, and discover no data is uploaded to the channel ie.no entries in channel. The code in makecode are the same as before and the wifi is work, I cannot find the reason that cause this failure.
Vinod
Vinod on 26 Nov 2024
Please share the code used on the device. We may be able to provide guidance based on looking at the code. Please replace any API keys in the code with API_KEY_PLACEHOLDER prior to sharing the code.
Jane
Jane on 28 Nov 2024
input.onButtonPressed(Button.A, function () {
if (ESP8266_IoT.wifiState(true)) {
basic.showIcon(IconNames.Yes)
basic.pause(1000)
} else {
basic.showIcon(IconNames.No)
basic.pause(1000)
}
})
input.onButtonPressed(Button.B, function () {
ESP8266_IoT.connectThingSpeak()
ESP8266_IoT.setData(
"API_KEY_PLACEHOLDER",
pins.analogReadPin(AnalogReadWritePin.P1),
Environment.ReadSoilHumidity(AnalogPin.P2)
)
ESP8266_IoT.uploadData()
basic.showIcon(IconNames.Heart)
if (ESP8266_IoT.thingSpeakState(true)) {
basic.showIcon(IconNames.Meh)
}
})
OLED.init(128, 64)
ESP8266_IoT.initWIFI(SerialPin.P8, SerialPin.P12, BaudRate.BaudRate115200)
ESP8266_IoT.connectWifi("your_ssid", "your_pwd")
basic.forever(function () {
OLED.writeStringNewLine("Light: " + pins.analogReadPin(AnalogReadWritePin.P1))
OLED.writeStringNewLine("Soil: " + Environment.ReadSoilHumidity(AnalogPin.P2))
if (pins.analogReadPin(AnalogReadWritePin.P1) < 300) {
pins.digitalWritePin(DigitalPin.P15, 1)
} else {
pins.digitalWritePin(DigitalPin.P15, 0)
}
if (Environment.ReadSoilHumidity(AnalogPin.P2) < 50) {
pins.servoWritePin(AnalogPin.P16, 0)
} else {
pins.servoWritePin(AnalogPin.P16, 180)
}
OLED.writeNumNewLine(Environment.ReadLightIntensity(AnalogPin.P1))
basic.pause(1000)
OLED.writeNumNewLine(Environment.ReadSoilHumidity(AnalogPin.P2))
basic.pause(1000)
})
This is the code that I use, I have checked that the connection with ThingSpeak is successful
Vinod
Vinod on 9 Dec 2024
@Jane: See the response here. Are you still having an issue after updating to the latest version?
Vinod
Vinod on 1 Dec 2024 (Edited on 8 Dec 2024)
I believe the library you are using is this one. It is not setting the requires headers, namely "Host". Without this, the request is being rejected by the server. Note that the "Host" header is required for valid HTTP/1.1 requests, per RFC 2616.
Please get in touch with the author of the library to update it. I have opened an issue in the original library for the authors to fix.