コード例 #1
0
void irkit_http_loop() {
#ifdef USE_INTERNET
    // long poll
    if (TIMER_FIRED(polling_timer)) {
        TIMER_STOP(polling_timer);

        if (TIMER_RUNNING(suspend_polling_timer)) {
            // suspend GET /m for a while if we have received a POST /messages request from client
            // client is in wifi, we can ignore our server for a while
            TIMER_START(polling_timer, SUSPEND_GET_MESSAGES_INTERVAL);
        }
        else {
            int8_t result = irkit_httpclient_get_messages();
            if ( result < 0 ) {
                HTTPLOG_PRINTLN("!E3");
                // maybe time cures GS? (no it doesn't, let's hardware reset, software reset doesn't work here)
                // don't software reset AVR, because that cuts off serial logging (for debug purpose only)
                wifi_hardware_reset();
            }
            else {
                polling_cid = result;
            }
        }
    }

    if (TIMER_FIRED(suspend_polling_timer)) {
        TIMER_STOP(suspend_polling_timer);
    }
#endif
}
コード例 #2
0
// 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;
}
コード例 #3
0
int8_t irkit_httpclient_post_messages_() {
    // post body is IR data, move devicekey parameter to query, for implementation simplicity
    // /p?devicekey=C7363FDA0F06406AB11C29BA41272AE3&freq=38
    char path[54];
    sprintf(path, P("/p?devicekey=%s&freq=%d"), keys.getKey(), IrCtrl.freq);
    int8_t cid = gs.postBinary( path,
                                (const char*)sharedbuffer, IR_packedlength(),
                                &on_post_messages_response,
                                10 );
    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;
}
コード例 #4
0
ファイル: GSwifi.cpp プロジェクト: pipoop/hobby-device
void GSwifi::loop() {
    TIMER_STOP( timeout_timer_ );

    checkActivity();

    for (uint8_t i=0; i<16; i++) {
        if (! cidIsRequest(i) &&
            TIMER_FIRED(timers_[i])) {
            TIMER_STOP(timers_[i]);

            GSLOG_PRINT("!E4 "); GSLOG_PRINTLN(i);

            // request (from us) timeout means GS is in trouble,
            // and it's easy to just rescue ourselves to reset
            wifi_hardware_reset();
            return;
        }
    }
}