Search code examples
cjsonparsingat-command

Sending Data in JSON schema using AT Commands


I am working on MQTT connection establishment to the server. I need to send the data to the server in JSON schema format using AT Commands.
The module used in N58 Neoway module. Using AT Commands connection got established and for publishing data or subscribing data to/from the server, it should happen in JSON format.
The AT Command used is:

AT+MQTTPUB=1,1,<"topic_name">,<"data">

I need to send the JSON schema in the place of data.
Looking for any suggestions/help.

The source code is based on C.


Solution

  • The problem in sending JSON through AT commands is that it contains double quotes ", that are unfortunately interpreted according to AT commands ETSI specification as the beginning of a string parameter. So, what happens in many modules is that it is impossible so send a JSON string as a parameter.

    Some modems vendors solve this issue by starting an online mode in which data can be sent rawly.
    N58 uses a different strategy instead, that consists in escaping the special characters. In the AT command guide it is called data link escape.

    Though the guide could be better (there's not explicit explanation of data link escape), we can infer it from the examples (see for example the one in AT+UDPSEND): in order to escape " character, just write \" as you would do in a C string. Example:

    AT+MQTTPUB=1,1,"topic_name","{\"menu\":{\"id\":\"1\",\"value\":\"2\"}}"