/******************************************************************************
* FunctionName : Send_cmd_server
* посылка GET команды на сервер, тупо без обратки
* пример http://192.168.4.1/?gpio1_out=3
* или http://lvm1976.dyndns.org:1326/?gpio1_out=3
******************************************************************************/
void ICACHE_FLASH_ATTR Send_cmd_server(uint8 *cmd_server) {
if(os_strncmp(&cmd_server, "http://", 7) == 0) cmd_server += 7;
if (cmpcpystr(clntTcp->clnttcp_server_dns, cmd_server, '\0', ':', 16) == 0) {
if (cmpcpystr(clntTcp->clnttcp_server_dns, cmd_server, '\0', '/', 32) == 0) {
LWIP_DEBUGF(SNTP_DEBUG_WARN_STATE, ("Failed to addresses for clntTcp client!\n"));
}
}
if (cmd_server[0] >= '0' && cmd_server[0] <= '9')
if (cmpcpystr(NULL, cmd_server, '\0', '.', 4) != 0) {
clntTcp->clnttcp_server_addresses = strtoip(clntTcp->clnttcp_server_dns);
}
uint8 buf[5] = "80";
cmpcpystr(buf, cmd_server, ':', '/', 32);
clntTcp->clnttcp_server_port = atoi(buf);
cmd_server = (uint8 *)cmpcpystr(NULL, cmd_server, '\0', '/', 32);
os_memset(clntTcp->clnttcp_url, 0, sizeof(clntTcp->clnttcp_url));
os_sprintf(clntTcp->clnttcp_url, cmd_server);
if (clntTcp == NULL) {
clntTcp = (struct sclntTcp *)os_zalloc(sizeof(struct sclntTcp));
if (clntTcp == NULL) {
LWIP_DEBUGF(SNTP_DEBUG_WARN_STATE, ("Failed to allocate mem for clntTcp client!\n"));
}
}
if(clntTcp->clnttcp_pcb == NULL) {
clntTcp->clnttcp_pcb = tcp_new();
if (clntTcp->clnttcp_pcb != NULL) {
tcp_sent(clntTcp->clnttcp_pcb, json_client_sent);
tcp_connect(clntTcp->clnttcp_pcb, &clntTcp->clnttcp_server_addresses, clntTcp->clnttcp_server_port, json_connected);
}
else
LWIP_DEBUGF(SNTP_DEBUG_WARN_STATE, ("Failed to allocate tcp pcb for clntTcp client!\n"));
os_free(clntTcp);
clntTcp = NULL;
}
}
static err_t ICACHE_FLASH_ATTR json_connected(void *arg, struct tcp_pcb *pcb, err_t err)
{
char *string = "{\"hop\": 0}";
os_sprintf(string,"GET /%s HTTP/1.0\r\n\r\n", clntTcp->clnttcp_url);
LWIP_UNUSED_ARG(arg);
if(err == ERR_OK)
{
tcp_write(clntTcp->clnttcp_pcb, string, strlen(string), 0);
tcp_output(clntTcp->clnttcp_pcb);
json_client_close(clntTcp->clnttcp_pcb);
}
return err;
}
static err_t ICACHE_FLASH_ATTR json_client_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
LWIP_UNUSED_ARG(arg);
return ERR_OK;
}