How to broadcast a command to other node in same mesh

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

How to broadcast a command to other node in same mesh

Postby XiotSamuel » Wed Sep 22, 2021 1:35 pm

I am recently exploring how to broadcast a command to other node in the same mesh, but I found that the received node have pop up a error message "only JSON message is supported in this version".

Code: Select all



            //get number of groups the node belongs to
            size_t group_id_num = 3;
            const uint8_t group_id_list[3][6] = {
                {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
                {0x01, 0x00, 0x5e, 0xaa, 0xaa, 0xaa},
                {0x01, 0x00, 0x5e, 0xac, 0xac, 0xac},
            };

            //format data to multicast  {"request":"set_status","characteristics":[{"cid":0,"value":1}]}
            int nRes = asprintf(&data_on, "{\"request\":\"set_status\",\"characteristics\":[{\"cid\":0,\"value\":1}]}");
            ret = nRes <= 0 ? MDF_ERR_INVALID_ARG : MDF_OK;
            MDF_ERROR_CONTINUE(ret != MDF_OK, "asprintf() failed to format data -> no message sent, continue");

            size = (size_t)nRes;

            //multicasting (unicast transfer to each group id)
            for (int i = 0; i < group_id_num; ++i)
            {
                ret = mwifi_write(group_id_list[i], &data_type, data_on, size, true);
                MDF_ERROR_CONTINUE(ret != MDF_OK, "mwifi_write() failed to send data to group id " MACSTR ", error (%s)", MAC2STR(group_id_list[i]), mdf_err_to_name(ret));
                MDF_LOGW("\tsent to group_id: " MACSTR, MAC2STR(group_id_list[i]));
            }

            MDF_FREE(data_on);

Anyone have idea why the other node have error message pop up?
Is the message {"request":"set_status","characteristics":[{"cid":0,"value":1}]} miss some parameter or header?

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

Re: How to broadcast a command to other node in same mesh

Postby XiotSamuel » Fri Sep 24, 2021 2:47 am

I found that need to make a http request and nest the JSON message in the request. Here is a post in this forum.

https://www.esp32.com/viewtopic.php?t=12268

But, Any example I can look at it?

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

Re: How to broadcast a command to other node in same mesh

Postby XiotSamuel » Mon Sep 27, 2021 3:45 am

I found the solution. Add the httpd_type structure to the data will be ok. Thx.

Code: Select all


            mlink_httpd_type_t header_info = {
                .format = MLINK_HTTPD_FORMAT_JSON,
                .from = MLINK_HTTPD_FROM_DEVICE,
                .resp = false,
            };



Who is online

Users browsing this forum: No registered users and 6 guests