Using the url package to update the channel on ThingSpeak

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?

//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)
    } 
}

, Ethernet-, - [ , ?], , , [, duh]. , . .

+4
1

, . - ThingSpeak 15 (http://community.thingspeak.com/documentation/api/), 2 . 2 20, . .

: :)

+2

All Articles