Code: Select all
LOCAL void ICACHE_FLASH_ATTR
tcp_connect_cb(void *arg){
os_printf("Connected to TCP Server.\n");
struct espconn *conn = (struct espconn*)arg;
char requestText[SIZE];
os_sprintf(requestText,"GET /toggleLED.php?getnumber /HTTP/1.1\r\nUser-Agent: curl/7.37.0\r\nHost: %s\r\nAccept: */*\r\n\r\n",DOMAIN);
espconn_send(conn,requestText,SIZE);
}
LOCAL void ICACHE_FLASH_ATTR
tcp_sent_cb(void *arg){
os_printf("Send command is out.\n");
}
LOCAL void ICACHE_FLASH_ATTR
tcp_recv_cb(void *arg, char *data, unsigned short len){
struct espconn *conn = (struct espconn*)arg;
//do some stuff
}
LOCAL void ICACHE_FLASH_ATTR
tcp_recon_cb(void *arg, sint8 err){
os_printf("TCP reconnected %d\n", err);
}
LOCAL void ICACHE_FLASH_ATTR
tcp_discon_cb(void *arg){
os_printf("TCP disconnected.\n");
}
LOCAL void ICACHE_FLASH_ATTR
getHostByNameCB(const char *name, ip_addr_t *ip,void *arg){
static esp_tcp tcp;
struct espconn *conn = (struct espconn*)arg;
conn->type=ESPCONN_TCP;
conn->state=ESPCONN_NONE;
conn->proto.tcp=&tcp;
conn->proto.tcp->local_port=espconn_port();
conn->proto.tcp->remote_port=80;
os_memcpy(conn->proto.tcp->remote_ip,&ip->addr,4);
espconn_regist_connectcb(conn,tcp_connect_cb);
espconn_regist_recvcb(conn,tcp_recv_cb);
espconn_regist_sentcb(conn,tcp_sent_cb);
espconn_regist_reconcb(conn,tcp_recon_cb);
espconn_regist_disconcb(conn,tcp_discon_cb);
espconn_connect(conn);
}
LOCAL void ICACHE_FLASH_ATTR
check_ip(void){
struct ip_info ipconf;
bool res = wifi_get_ip_info(STATION_IF, &ipconf);
if(!res)
os_printf("No WiFi Connection.");
else{
if(wifi_station_get_connect_status() == STATION_GOT_IP && ipconf.ip.addr != 0){
os_printf("Got IP Address.\n");
static struct espconn con;
static ip_addr_t ip;
espconn_gethostbyname(&con,DOMAIN,&ip,getHostByNameCB);
} else {
os_timer_setfn(&timer,(os_timer_func_t*)check_ip,NULL);
os_timer_arm(&timer,100,0); //recall function after 100ms, don't repeat
}
}
}
LOCAL void ICACHE_FLASH_ATTR
set_station_config(void){
struct station_config stationConf;
char *SSID = "";
char *PW = "";
stationConf.bssid_set = 0;
os_memcpy(&stationConf.ssid,SSID,32);
os_memcpy(&stationConf.password,PW,64);
wifi_station_set_config(&stationConf);
wifi_station_connect();
}
void user_init(void){
wifi_set_opmode(STATION_MODE);
set_station_config();
check_ip();
}
So how can i repeatedly send that http request in the "tcp_connect_cb"? Any help is very much appreciated!