I use the following code on Raspberry Pi to continuously download selected temperature and humidity values to the ThingSpeak channel [https://www.thingspeak.com/]. The problem is that only the first value is loaded, and the rest are ignored. What am I doing wrong? values.Set creates a previously not created key, assigns it the first value and, without any problems, replaces each subsequent value. Why don't they load? Is there something wrong with http.PostForm?
type Data struct {
Temperature int
Humidity int
}
var data Data
func httpPost(values url.Values) {
values.Set("field1", fmt.Sprint(data.Temperature))
values.Set("field2", fmt.Sprint(data.Humidity))
log.Println(values)
_, err := http.PostForm("http://api.thingspeak.com/update", values)
if err != nil {
log.Printf("error posting values to thingspeak: %s", err)
}
return
}
func main() {
dataPool := []Data{{28, 41}, {24, 43}, {27, 42}, {21, 40}}
values := make(url.Values)
values.Set("key", "Write API Key")
for _, value := range dataPool {
data = value
httpPost(values)
time.Sleep(2 * time.Second)
}
}
, Ethernet-, - [ , ?], , , [, duh]. , . .
user2665764