コード例 #1
0
void ICACHE_FLASH_ATTR get_wifi2_mesh_common_status(const int8_t cid,
	const GetWifi2MeshCommonStatus *data) {
		os_bzero(&gw2mcsr.header, sizeof(gw2mcsr.header));

		gw2mcsr.header = data->header;
		gw2mcsr.header.length = sizeof(GetWifi2MeshCommonStatusReturn);

		gw2mcsr.status = espconn_mesh_get_status();
		gw2mcsr.is_root_node = espconn_mesh_is_root();
		gw2mcsr.is_root_candidate = espconn_mesh_is_root_candidate();
		gw2mcsr.connected_nodes = espconn_mesh_get_sub_dev_count();

		com_send(&gw2mcsr, sizeof(GetWifi2MeshCommonStatusReturn), cid);
}
コード例 #2
0
ファイル: mesh_demo.c プロジェクト: nisen/ESP8266_MESH_DEMO
void ICACHE_FLASH_ATTR mesh_enable_cb(int8_t res)
{
	MESH_DEMO_PRINT("mesh_enable_cb\n");

    if (res == MESH_OP_FAILURE) {
        MESH_DEMO_PRINT("enable mesh fail, re-enable\n");
        espconn_mesh_enable(mesh_enable_cb, MESH_ONLINE);
        return;
    }

    if (espconn_mesh_get_usr_context() &&
        espconn_mesh_is_root() &&
        res == MESH_LOCAL_SUC)
        goto TEST_SCENARIO;

    /*
     * try to estable user virtual connect
     * user can to use the virtual connect to sent packet to any node, server or mobile.
     * if you want to sent packet to one node in mesh, please build p2p packet
     * if you want to sent packet to server/mobile, please build normal packet (uincast packet)
     * if you want to sent bcast/mcast packet, please build bcast/mcast packet
     */
    MESH_DEMO_MEMSET(&g_ser_conn, 0 ,sizeof(g_ser_conn));
    MESH_DEMO_MEMSET(&ser_tcp, 0, sizeof(ser_tcp));

    MESH_DEMO_MEMCPY(ser_tcp.remote_ip, server_ip, sizeof(server_ip));
    ser_tcp.remote_port = server_port;
    ser_tcp.local_port = espconn_port();
    g_ser_conn.proto.tcp = &ser_tcp;

    if (espconn_regist_connectcb(&g_ser_conn, esp_mesh_demo_con_cb)) {
        MESH_DEMO_PRINT("regist con_cb err\n");
        espconn_mesh_disable(NULL);
        return;
    }

    if (espconn_regist_recvcb(&g_ser_conn, esp_recv_entrance)) {
        MESH_DEMO_PRINT("regist recv_cb err\n");
        espconn_mesh_disable(NULL);
        return;
    }

    /*
     * regist the other callback
     * sent_cb, reconnect_cb, disconnect_cb
     * if you donn't need the above cb, you donn't need to register them.
     */

    if (espconn_mesh_connect(&g_ser_conn)) {
        MESH_DEMO_PRINT("connect err\n");
        if (espconn_mesh_is_root())
            espconn_mesh_enable(mesh_enable_cb, MESH_LOCAL);
        else
            espconn_mesh_enable(mesh_enable_cb, MESH_ONLINE);
        return;
    }

TEST_SCENARIO:
    mesh_device_list_init();
    mesh_topo_test_init();
    mesh_json_mcast_test_init();
    mesh_json_bcast_test_init();
    mesh_json_p2p_test_init();
}