wujiangang / ESP8266_IOT_PLATFORM

A demo that should be run with ESP8266 RTOS SDK
http://bbs.espressif.com
Other
239 stars 122 forks source link

user_plug, how to send data to APP #7

Open ericchan16 opened 7 years ago

ericchan16 commented 7 years ago

Hi All,

I'm using the user_plug example in ESP8266_IOT_PLATFORM. Everything works well, APP can control the plug, and request the plug status. But when I press the key to make plug turns on or turns off, it will not send plug status to APP. So I add below code: `

if(key_pressed_flag == 1)
{
    key_pressed_flag = 0;

    char *pbuf = NULL;
    int nonce = 0;

    pbuf = (char *)zalloc(packet_size);

    if (pbuf != NULL) {
        sprintf(pbuf, RESPONSE_FRAME, user_plug_get_status(), nonce);
        printf("%s\n", pbuf);
        write(client_param.sock_fd, pbuf, strlen(pbuf));
        free(pbuf);
        pbuf = NULL;
    }
}

`

But when execute these code, it will return below error. Does anyone know why? Or is there any method to upload the plug status to APP? Thanks!

[2016-12-09 16:16:48.712 R]read application data user_esp_platform_data_process {"status": 500, "result": "failed", "message": "Internal Server Error"} , 72

tzxespressio commented 7 years ago

I think if plug change its status,the status just upload to server,but server won't push the message to app right now,just when app want to get the status of plug,and it send request to server,server will response plug status to app,but if use it in LAN environment ,use the webserver control the plug,it‘s easy to update the status to APP

Clairehou111 commented 6 years ago

I got the same doubt here, especially via local network,the apps which keep connection with ESP are supposed to get the ESP's latest data, my question is how to implement this . Should the ESP send the data straightforward to apps or apps keep requesting data from the ESP? If it's former, unicast or broadcast should be used? Thanks a lot in advance.

Clairehou111 commented 6 years ago

but if use it in LAN environment ,use the webserver control the plug,it‘s easy to update the status to APP

@tzxespressio , could you give more details about the method please ?