DA16200MOD MQTT JSON Formate AT Command communication.

Hello Team,

                  I am going to use the MQTT Protocol, and i want to send data on JSON format is this possible. Because this i read your documents in that JSON formate AT command is only for HTTP and HTTPS protocol. if i want to use MQTT protocol then which language should we use to design the IOT page.

              and another information required i am not using RTC then RTC sensor should give ground or VDD.

because my SDK is not load in module they stuck in middle i think this is because of RTC is goes in SLEEP mode so what should we do to WAKE UP this RTC.

Best Regard's

AK.  

Parents
  • Hello,

    Using MQTT with JSON

    Yes, you can definitely send data in JSON format over MQTT. While you mentioned that the AT commands you read only reference JSON for HTTP and HTTPS, MQTT can also handle JSON payloads. You just need to format your data as a JSON string before publishing it to the MQTT broker. Here's a basic example in Python:

    import paho.mqtt.client as mqtt
    import json

    # Define the MQTT settings
    broker_address = "your_broker_address"
    client = mqtt.Client("ClientID")

    # Connect to the broker
    client.connect(broker_address)

    # Prepare your data in JSON format
    data = {
    "temperature": 22.5,
    "humidity": 60
    }
    json_data = json.dumps(data)

    # Publish the JSON data
    client.publish("your/topic", json_data)

    # Disconnect
    client.disconnect()

    You can use any programming language that supports MQTT libraries (like Python, Java, C/C++, JavaScript, etc.) to design your IoT application.

    RTC Connection

    Regarding the RTC (Real-Time Clock) connection:

    • If you're not using an RTC, typically, the RTC sensor should be connected to either GND (ground) or VDD (power), depending on how the sensor is designed.
    • If your RTC is in sleep mode and preventing your SDK from loading, you may need to wake it up. Here are some general approaches:
      • Check Datasheet: Review the RTC's datasheet to understand how to wake it up. Some RTCs have a specific pin or command for waking.
      • Interrupt Pin: If the RTC has an interrupt pin, you may be able to use a microcontroller GPIO to wake it.
      • Power Cycle: Sometimes, simply cycling the power to the RTC can wake it up.

    Next Steps

    • Ensure that your code correctly handles the initialization of the RTC.
    • Double-check the wiring and power supply to the RTC module to ensure it's functioning correctly.
    • If you continue to experience issues, consider reaching out to the manufacturer or looking into their forums for troubleshooting specific to your RTC model.

    Feel free to ask if you have any more questions or need further assistance!

    Best regards,

  • Hello,

              i want make connection of two LED to this DA16200MOD for when transmission will happen that red will glow and receive time blue will glow so tell what to do in SDK file to this operation.

    thanks and regard's

    AK.

  • Hi Ak,

    Thank you for the reply.

      i want make connection of two LED to this DA16200MOD for when transmission will happen that red will glow and receive time blue will glow so tell what to do in SDK file to this operation.

    Are you talking about Wi-Fi transmission or AT cmd transmissions?
    Generally for controlling LED, please refer on UM-WI-046 DA16200 DA16600 FreeRTOS SDK Programmer Guide (renesas.com) , on section 17.2 GPIO page:263


    Best Regards,
    OV_Renesas

  • hello,

         Tell me for both wifi transmission and AT command transmission what to do in SDK.i read for GPIO just tell me for wifi transmission and AT command transmission.

           i want to say when AT Command is send that time led glow same for receive side also. means we can get clarification of our data transmission not lost that the reason i am applying this. just like take example of HC05 Bluetooth LED function before connection state and after connection state and during transmission. 

    best regard's

    AK.

  • hello,

                         kindly answer the question as soon as possible i am waiting your replay.

                          i read the GPIO API example but where to call in this function means in which file main.c,user.c or system start.c i am bit confuse.

    thanks and regard's

    AK

  • Hi AK,

    Thank you for the replies.
    It is not exactly clear what you are trying to achieve.
    However, for MQTT AT Commands you should use the following:

    When you send this AT command the following part will be executed in the atcmd.c file:

       // AT+NWMQMSG
        else if (strcasecmp(argv[0] + 5, "MQMSG") == 0) {
            char *top;
    
            if (argc == 2 || argc == 3) {
                int rsp_val;
    
                /* AT+NWMQMSG=<msg>(,<topic>) (set only) */
                if (strlen(argv[1]) > MQTT_MSG_MAX_LEN) {
                    err_code = AT_CMD_ERR_NW_MQTT_PUB_MESSAGE_LEN;
                    goto atcmd_network_end;
                }
    
                if (argc == 2) {
                    top = NULL;
                } else if (argc == 3) {
                    if (strlen(argv[2]) > MQTT_TOPIC_MAX_LEN) {
                        err_code = AT_CMD_ERR_NW_MQTT_PUB_TOPIC_LEN;
                        goto atcmd_network_end;
                    } else {
                        top = argv[2];
                    }
                }
    
                rsp_val = mqtt_client_send_message(top, argv[1]);
    
                if (rsp_val == -1) {
                    err_code = AT_CMD_ERR_NW_MQTT_NOT_CONNECTED;
                } else if (rsp_val == -2) {
                    // in-flight message is in progress
                    err_code = AT_CMD_ERR_NW_MQTT_PUB_TX_IN_PROGRESS;
                } else if (rsp_val == -3) {
                    // no topic in mqtt configuration
                    err_code = AT_CMD_ERR_NW_MQTT_PUB_TOPIC_NOT_EXIST;
                } else if (rsp_val == 9 /* MOSQ_ERR_PAYLOAD_SIZE */) {
                    // paylod too long
                    err_code = AT_CMD_ERR_NW_MQTT_PUB_MESSAGE_LEN;
                } else {
                    // pre-check passed ...
                    if (dpm_mode_is_enabled() == pdTRUE) {
                        if (mqtt_client_get_qos() > 0) { // qos 1 or 2
                            if (rsp_val != 0) {
                                mqtt_client_convert_to_atcmd_err_code(&rsp_val, &err_code);
                            }
                        } else {                          // qos 0
                            if (rsp_val != 0) {
                                mqtt_client_convert_to_atcmd_err_code(&rsp_val, &err_code);
                            } else {
                                // make async +NWMQMSGSND:1 to sync print
                                atcmd_mqtt_qos0_msg_send_done_in_dpm = TRUE;
                                atcmd_mqtt_qos0_msg_send_rc = 0;
                            }
                        }
                    }
                }
            } else {
                err_code = AT_CMD_ERR_INSUFFICENT_ARGS;
            }
        }

    You can either turn ON the LED when it enters in that if statement, or directly inside the mqtt_client_send_message API.
    Then after the if statement controlling the rsp_val is being handled you can turn the LED off. Or you can do this on the same file on the following APIs:

    void mqtt_client_convert_to_atcmd_err_code(int* err_code, int* atcmd_err_code)
    {
        int mosq_err_code = *err_code;
    
        if (mosq_err_code == MOSQ_ERR_INVAL || mosq_err_code == MOSQ_ERR_PAYLOAD_SIZE) {
            *atcmd_err_code = AT_CMD_ERR_WRONG_ARGUMENTS;
        } else if (mosq_err_code == MOSQ_ERR_NO_CONN || mosq_err_code == MOSQ_ERR_CONN_LOST) {
            *atcmd_err_code = AT_CMD_ERR_NOT_CONNECTED;
        } else {
            *atcmd_err_code = AT_CMD_ERR_UNKNOWN;
        }
    }
    
    void atcmd_asynchony_event_for_mqttmsgpub(int result, int err_code)
    {
        int atcmd_err;
    
        if (result == 1) {
            PRINTF_ATCMD("\r\n+NWMQMSGSND:1\r\n");
        } else if (result == 0) {
            mqtt_client_convert_to_atcmd_err_code(&err_code, &atcmd_err);
            PRINTF_ATCMD("\r\n+NWMQMSGSND:0,%d\r\n", atcmd_err);
        }
    }
    

    This way, when you try to publish a MQTT message you will turn on the LED while the MQTT transmission is in progress, and when you receive the MQTT result (so no Wi-Fi transmission is on going) you will turn the LED OFF.

    If you want to implement this behavior for every AT command:
    On the atcmd.c file you can see that we have multiple functions to control the AT commands based on their features.
    Those are:
    1. help_command 
    2. atcmd_standard
    3. atcmd_uartconf
    4. atcmd_basic
    5. atcmd_dpm
    6. atcmd_wifi
    7. atcmd_network
    8. atcmd_transport
    9. atcmd_transport_ssl
    10. atcmd_testmode
    11. atcmd_rftest
    12. atcmd_rftx
    13. atcmd_tfcwttest
    14. atcmd_rf_per
    15. atcmd_rf_cont
    16. atcmd_chan
    etc. 

    At the start of these functions you can turn on the LED and when these functions return the status (Error Code or OK) you can turn the LED off.
    If you do not want to edit all those functions, you can just directly edit the command_parser API (on the atcmd.c file) and open the LED on there and turn it OFF when you have received the response message.


    Best Regards,
    OV_Renesas


  • hello,

            I understand.

                          now i am take one example of DA16200MOD for GPIO and i did build project it gives me error in wifi stack i am attaching the image just give me the solution.

    Best Regards,

    AK 

                 

  • Hi AK,

    Thank you for the reply.
    Apologies for the delay but I was OOO.
    You are getting this kind of error on one of our default example projects?
    If yes, could you please shorten the path of your workspace? 
    If you have modified the example, could you please share the modifications you have made?

    Best Regards,
    OV_Renesa

  • Hello ,

                  I have created IOT page on thingboard and try your command to send data it works but when i want to send my project data but it not work,


    send_command("AT+NWMQMSG={temperature:86},v1/devices/me/telemetry\r\n",53); <--->this command is working when i directly put value "temperature:86" like that, but in below code i idid using sprintf but it not working.

    just check and give me solution which data type this command support.
    snprintf is not support to RX71 so i used sprintf.


    and one more question how much delay will be required while send and get response of command because it gives me error most of the time. i also try for long delay but issue i get remain. gives me this error :-1 which is

    -1

    AT_CMD_ERR_UNKNOWN_CMD

    Unknown command



    ERROR:-1....+NWMQCL:1..:-1...52.153....OK..K-CCMP][ESS].IOT.c0:c1:c0:a6:7f:2a.2462.-80.[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS].Cisco-D.f8:c4:f3:94:eb:01.2457.-90.[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS].Foro.dc:ef:09:0d:70:70.2472.-91."

    this is my MQTT thingboard link :-

     mosquitto_pub -d -q 1 -h mqtt.thingsboard.cloud -p 1883 -t v1/devices/me/telemetry -i "clientid" -u "username" -P "password" -m "{temperature:25}"

    this red part is JSON formate data.

    #include "r_cg_macrodriver.h"
    #include "r_cg_cgc.h"
    #include "r_cg_sci.h"
    #include "r_cg_s12ad.h"
    /* Start user code for include. Do not edit comment generated here */
    #include <stdbool.h>
    #include <stddef.h>
    #include <string.h>

    #include <stdio.h> 

    /* End user code. Do not edit comment generated here */
    #include "r_cg_userdefine.h"
    #include "r_cg_s12ad.h"

    /***********************************************************************************************************************
    Global variables and functions
    ***********************************************************************************************************************/
    /* Start user code for global. Do not edit comment generated here */
    void send_command(uint8_t * const tx_buf, uint16_t tx_num);
    void delay(int t);
    void wifi_init();
    void wifi_scan();
    void LED_status();
    void LED_status_blinking();
    void LED_status_off();
    void LED_status_on();
    void LED_status_blinking_infinite();
    void mqtt_publish();
    bool check_for_string(const char* scan_result);
    void mqtt_setup();
    void LED_status_on_off();
    void wifi_status();
    void delay1(int t);

    #define size 1000
    char receive_buffer[size];
    //bool flag=0;
    //uint8_t length=0;
    MD_STATUS responsStatus;
    int i=0;
    uint16_t ADC=0;
    uint8_t j=0;
    uint16_t g_data00=0;
    //uint16_t temperature=0;
    uint16_t min_value=1500;
    uint16_t max_value=2153;
    char *scan_result;
    char mqtt_message[100];
    uint8_t INC=0;
    char array2[300];
    char array3[600];
    char command[10];

    #define BUFFER_SIZE 512 // Define an appropriate buffer size

    static uint8_t buffer[BUFFER_SIZE]; // Buffer to store received data
    static uint16_t var = 0;
    uint16_t temperature=0;
    uint16_t g_data0=0;
    int attempt = 0;

    /////Response///
    bool flag1=0;
    bool flag2=0;



    void main(void)
    {
    R_MAIN_UserInit();
    /* Start user code. Do not edit comment generated here */
    R_SCI0_Start();
    R_S12AD0_Start();


    wifi_scan();
    mqtt_setup();

    while(1)

    {
     

    sprintf(store,"%d",temperature);
    sprintf(command, "AT+NWMQMSG={temperature:%d},v1/devices/me/telemetry\r\n", store);
    send_command(command, strlen(command));
    //delay(6000);
    // wifi_status();

    // g_data0 = (uint16_t)(S12AD.ADDR0);

    // temperature = (g_data0 - 1973)*0.179;
    // sprintf(store,"%d",temperature); // Correct sprintf usage

    //sprintf(command, "%d",temperature);

    send_command("AT+NWMQMSG={temperature:63},v1/devices/me/telemetry\r\n",53);
    delay(100);

    // if(0x45==receive_buffer[2] &&0x52==receive_buffer[3]&&0x52==receive_buffer[4]&&
    // 0x4F==receive_buffer[5]&&0x52==receive_buffer[6]&&0x3A==receive_buffer[7]
    // &&0x2D==receive_buffer[8]&&0x36==receive_buffer[9]&&0x33==receive_buffer[10]
    // &&0x34==receive_buffer[11])
    // {
    // send_command("AT+LEDCTRL=1,off\r\n",18);
    // delay(50);
    // }
    // sprintf(command, "AT+NWMQMSG={temperature:%s},v1/devices/me/telemetry\r\n", command);
    // send_command(command, strlen(command));
    // delay(100);
    //mqtt_publish();

    }


    /* End user code. Do not edit comment generated here */
    }

  • Hi AK,

    Thank you for the reply.
    IF you are trying to connect to AWS Server via MQTT, please refer here: DA16200 DA16600 Getting Started with AWS IoT Core (renesas.com)
    You will need the AWS IoT Reference for FreeRTOS SDK or the AWS IoT ATCMD Image for FreeRTOS SDK which can be found on the DA16200/DA16200MOD/DA16600MOD product pages under Software Downloads;

    Please follow the ReadMe files on how to integrate the AWS features into the FreeRTOS SDK.

    If you are still facing issues, please attach a logic analyzer on the UART/SPI lines being used for AT command transport and share the capture with us.
    We would also like the full UART0 log files.

    Best Regards,
    OV_Renesas

  • hello,

                Yes i will try with this SDK images.

    Best Regard's
    AK

Reply Children
No Data