Cannot upload data to ThingSpeak through IOT:bit Expansion Board

Jane 2024년 11월 26일
최근 활동 Vinod답글: 2024년 12월 9일

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 2024년 11월 26일
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 2024년 11월 28일
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 2024년 12월 9일
@Jane: See the response here. Are you still having an issue after updating to the latest version?
Vinod
Vinod 2024년 12월 1일 (2024년 12월 8일에 수정됨)
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.