Exemplo n.º 1
0
void ICACHE_FLASH_ATTR
sp_LightPairReportResult(bool res)
{
#if 1
	os_printf("sp_LightPairReportResult %d \r\n",res);
    char data_body[300];
    os_bzero(data_body,sizeof(data_body));
    uint8 mac_sta[6] = {0};
    wifi_get_macaddr(STATION_IF, mac_sta);
    os_sprintf(data_body,"{\"device_mac\":\"%02X%02X%02X%02X%02X%02X\",\"button_mac\":\"%02X%02X%02X%02X%02X%02X\",\"result\":%d,\"path\":\"%s\"}",MAC2STR(mac_sta),MAC2STR(buttonPairingInfo.button_mac),res,PAIR_RESULT);
	//{"device_mac":"...","result":1,"path":"/device/button/pair/result"}
	if (!mesh_json_add_elem(data_body, sizeof(data_body), pair_sip, ESP_MESH_JSON_IP_ELEM_LEN)) {
    	return;
    }
    if (!mesh_json_add_elem(data_body, sizeof(data_body), pair_sport, ESP_MESH_JSON_PORT_ELEM_LEN)) {
	    return;
    }
    char* dev_mac = (char*)mesh_GetMdevMac();
    if (!mesh_json_add_elem(data_body, sizeof(data_body), dev_mac, ESP_MESH_JSON_DEV_MAC_ELEM_LEN)) {
	    return;
    }
    #if ESP_MESH_SUPPORT
	response_send_str((struct espconn*)user_GetUserPConn(),true,data_body,os_strlen(data_body),NULL,0,0,0);
	#else
	response_send_str((struct espconn*)user_GetWebPConn(),true,data_body,os_strlen(data_body),NULL,0,0,0);
	#endif
#endif
}
Exemplo n.º 2
0
void ICACHE_FLASH_ATTR
sp_LightPairRequestPermission()
{
#if 1
    char data_body[200];
    os_bzero(data_body,sizeof(data_body));
    uint8 mac_sta[6] = {0};
    wifi_get_macaddr(STATION_IF, mac_sta);
    os_sprintf(data_body,"{\"device_mac\":\"%02X%02X%02X%02X%02X%02X\",\"button_mac\":\"%02X%02X%02X%02X%02X%02X\",\"path\":\"%s\"}",MAC2STR(mac_sta),MAC2STR(buttonPairingInfo.button_mac),PAIR_FOUND_REQUEST);
	
	if (!mesh_json_add_elem(data_body, sizeof(data_body), pair_sip, ESP_MESH_JSON_IP_ELEM_LEN)) {
    	return;
    }
    if (!mesh_json_add_elem(data_body, sizeof(data_body), pair_sport, ESP_MESH_JSON_PORT_ELEM_LEN)) {
	    return;
    }
    char* dev_mac = (char*)mesh_GetMdevMac();
    if (!mesh_json_add_elem(data_body, sizeof(data_body), dev_mac, ESP_MESH_JSON_DEV_MAC_ELEM_LEN)) {
	    return;
    }
    #if ESP_MESH_SUPPORT
	response_send_str((struct espconn*)user_GetUserPConn(),true,data_body,os_strlen(data_body),NULL,0,0,0);
	#else
	response_send_str((struct espconn*)user_GetWebPConn(),true,data_body,os_strlen(data_body),NULL,0,0,0);
	#endif
#endif
}
void ICACHE_FLASH_ATTR
	light_SendMeshBroadcastCmd(uint32 r,uint32 g,uint32 b,uint32 cw,uint32 ww,uint32 period)
{
    struct espconn* pconn = (struct espconn*)user_GetUserPConn();
	char* bcast_data = (char*)os_zalloc(300);
	if(bcast_data==NULL) return;
	
	os_sprintf(bcast_data,BCAST_CMD,period,r,g,b,cw,ww,0);
	data_send_buf(pconn, true, bcast_data,os_strlen(bcast_data),BCAST_URL,os_strlen(BCAST_URL));
	os_free(bcast_data);
	bcast_data = NULL;
}
Exemplo n.º 4
0
void ICACHE_FLASH_ATTR
sp_LightPairReplyKeepAlive()
{
	char data_resp[100];
	os_bzero(data_resp,sizeof(data_resp));
	os_sprintf(data_resp, "{\"status\":200,\"path\":\"%s\"}",PAIR_KEEP_ALIVE);
	os_printf("response send str...\r\n");
	#if ESP_MESH_SUPPORT
	response_send_str((struct espconn*)user_GetUserPConn(), true, data_resp,os_strlen(data_resp),NULL,0,1,0);
	#else
	response_send_str((struct espconn*)user_GetWebPConn(), true, data_resp,os_strlen(data_resp),NULL,0,1,0);
	#endif
}
void ICACHE_FLASH_ATTR
	light_SendMeshBroadcastUpgrade(uint32 nonce,char* version,int pkt_len)
{
    struct espconn* pconn = (struct espconn*)user_GetUserPConn();

	uint8* pkt_upgrade = (uint8*)os_zalloc(pkt_len);
	if(pkt_upgrade == NULL) return;
	
	os_sprintf(pkt_upgrade,UPGRADE_BROADCAST_CMD,nonce,version);
	//data_send_buf(pconn, true, pkt_upgrade,os_strlen(pkt_upgrade),NULL,0);
	espconn_esp_sent(pconn, pkt_upgrade, os_strlen(pkt_upgrade),0);
	os_free(pkt_upgrade);
	pkt_upgrade = NULL;
}
Exemplo n.º 6
0
void ICACHE_FLASH_ATTR
sp_LightReplyPairedDev()
{
	uint8* MacListBuf = (uint8*)os_zalloc(PairedDev.PairedNum*DEV_MAC_LEN*2+1);
    uint8 cnt=sp_GetPairedNum(&PairedDev);
	
    sp_PairedDevMac2Str(&PairedDev,MacListBuf,sizeof(MacListBuf)-1);
    #if ESP_MESH_SUPPORT
	response_send_str((struct espconn*)user_GetUserPConn(), true, MacListBuf,os_strlen(MacListBuf),NULL,0,1,1);
    #else
	response_send_str((struct espconn*)user_GetWebPConn(), true, MacListBuf,os_strlen(MacListBuf),NULL,0,1,1);
    #endif

	if(MacListBuf){
		os_free(MacListBuf);
		MacListBuf = NULL;
	
	}

}