I am using the following part of code on a Raspberry Pi in order to continuously upload sampled [temperature & humidity] values onto a channel at ThingSpeak [https://www.thingspeak.com/]. The problem is that only the first value gets uploaded while the rest are ignored. What am i doing wrong? values.Set creates a not-previously created key, assigns to it a first value and replaces every next value without any problem. Why don't they get uploaded? Is there anything wrong with http.PostForm?
//imports
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
//ThingSpeak update
httpPost(values)
time.Sleep(2 * time.Second)
}
}
I don't know much off networks but right now i am accessing internet via an Ethernet port that connects on a hub-based satellite internet connection [i guess not a normal router connection?] so maybe it's a administrative problem [dormitories, duh]. I should ask my network administrator about that but in any case i am putting this out here. Any feedback are welcome.