// added by eqiglii 2015-12-13
int8_t irkit_httpclient_post_temperature_(uint8_t temperature) {
    // send http post request to LAN server  
    char path[82];
    sprintf(path, P("/proxy.php?url=https://irkitrestapi.appspot.com/_ah/api/southbound/v1/temperature?"));    // added "?" by eqiglii 2016-06-13

    char body[POST_TEMPERATURE_BODY_LENGTH+1+4]; // +4, due to change the two "&" to "%26", eqiglii, 2016-06-13
    
    // char array[6];
    // dtostrf(temperature,5, 2, array); // this function works, but takes too much memory KB
    // I know that the Arduino version of sprinf does not support floats, but we're sticking to INTs here so it is fine

    sprintf(body, "irkit_id=%s%ssignal_content=%2d%ssignal_name=%s", gs.hostname(),"%26", temperature,"%26", "temp");    // change the two "&" to "%26", eqiglii 2016-06-13
    
    int8_t cid = gs.post(path, body, POST_TEMPERATURE_BODY_LENGTH, &on_post_messages_response,50 );   
    //int8_t cid = gs.post("/_ah/api/southbound/v1/temperature?", body, POST_TEMPERATURE_BODY_LENGTH, &on_post_messages_response,50 );   // this never worked out!!! eqiglii 2016-06-14, don't try any more!!!
    
    if (cid == polling_cid) {
        // we're polling on this cid, and our response handler is registered with this cid.
        // we already overwritten the response handler, so restart everything.
        // HTTPLOG_PRINTLN("!E30");
        wifi_hardware_reset();
        return -1;
    }
    return cid;
}
int8_t irkit_httpclient_post_door() {
#ifdef USE_INTERNET
    // devicekey=[0-9A-F]{32}&hostname=IRKit%%%%
    char body[POST_DOOR_BODY_LENGTH+1];
    sprintf(body, "devicekey=%s&hostname=%s", keys.getKey(), gs.hostname());
    return gs.post( "/d", body, POST_DOOR_BODY_LENGTH, &on_post_door_response, 50 );
#else
    on_post_door_response(CID_UNDEFINED, 200, GSwifi::GSREQUESTSTATE_RECEIVED);
#endif
}
int8_t irkit_httpclient_post_door() {
    // devicekey=[0-9A-F]{32}&hostname=IRKit%%%%
    // send http post request to LAN server  
    char path[75];
    sprintf(path, P("/proxy.php?url=https://irkitrestapi.appspot.com/_ah/api/southbound/v1/door?")); // path must end up with "?", by eqiglii 2016-06-13
    
    char body[POST_DOOR_BODY_LENGTH+1+2];    // +2, due to change from "&" to "%26", eqiglii, 2016-06-13
    sprintf(body, "devicekey=%s%shostname=%s", keys.getKey(),"%26",gs.hostname()); // in http url encoding, "&" must be replaced by "%26", by eqiglii 2016-06-13
    Serial.println (body); // print log, added by eqiglii
    //return gs.post( "/d", body, POST_DOOR_BODY_LENGTH, &on_post_door_response, 50 );
    //return gs.post( "/_ah/api/southbound/v1/door?", body, POST_DOOR_BODY_LENGTH, &on_post_door_response, 50 );
    return gs.post(path, body, POST_DOOR_BODY_LENGTH, &on_post_door_response, 50 );
}
int8_t irkit_httpclient_post_keys() {
    // devicekey=[0-9A-F]{32}
    char body[POST_KEYS_BODY_LENGTH+1];
    sprintf(body, "devicekey=%s", keys.getKey());
    int8_t result = gs.post( "/k",
                             body, POST_KEYS_BODY_LENGTH,
                             &on_post_keys_response,
                             10 );
    if ( result < 0 ) {
        gs.writeHead( post_keys_cid, 500 );
        gs.writeEnd();
        ring_put( &commands, COMMAND_CLOSE );
        ring_put( &commands, post_keys_cid );
    }
}
int8_t irkit_httpclient_post_door() {
    // devicekey=[0-9A-F]{32}&hostname=IRKit%%%%
    char body[POST_DOOR_BODY_LENGTH+1];
    sprintf(body, "devicekey=%s&hostname=%s", keys.getKey(), gs.hostname());
    return gs.post( "/d", body, POST_DOOR_BODY_LENGTH, &on_post_door_response, 50 );
}