This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

at command parser library use

Hi,

nRF9160 DK
I have a simple question regarding processing at command responses. I was hoping to extract the individual values from a at command response using the at command parser library
e.g. from the response "+CESQ: 99,99,255,255,11,49" obtain an array of ints 99,99,255 etc. Before I write code to extract sub strings using comma delimiters will the at command parser
library achieve this? I am struggling to find examples of how to use this library. Using the function "at_params_valid_count_get" on the above example string returns 1 and "at_parser_params_from_str" returns a single value of 99,99,255,255,11,49 so I suspect I am not understanding the purpose of the library or using it correctly. A example of how to use the library would be appreciated.

Thank you

Peter

Parents
  • Hi Peter,

    To better understand how to use the AT parser library, you can for example have a look at how CEREG responses are parsed in the LTE link controller:
    https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/lib/lte_link_control/lte_lc.c#L528

    What you need to do is:
    - Initialize a parameter list with the maximum number of parameters in the command response or notification that you wish to decode. So for +CESQ, that is 7, as "+CESQ" also counts as a paramter.
    - Input the response string to the parser using at_parser_max_params_from_str()
    - Read out individual parameter using at_params_string_get() or at_params_int_get() and similar helpper functions. "+CEREG" is the parameter in posiion 0 and can be used to check which response type you're handling.
    - Free the list after you're done with it using at_params_list_free()

    Best regards,
    Jan Tore

  • Hi Jan Tore,

    Thanks for your quick response, I have some test parser code working now. I have enabled registration status URC's using +CEREG=1. I take it that I would then need to enable a "global" URC handler using at_notif_register_handler which accepts all URC's and inputs them to the at parser for processing. Since the register handler needs to accept all URC's while the modem is on it never gets de-registered. Is this approach correct? Or can I assign handlers to particular URC's?

    Cheers

    Peter

  • Hi Jan Tore,

    When I enable a at_notif_register_handler for URC's  I can see the handler being called when URC's are received  but if I try to access the handler's response buffer in any way, the device reset's itself. The same handler used with at command send with callbacks works fine (the at_notif handler is not registered during those tests).

    Also if I setup a simple at socket and poll it I can use a button interrupt to send a at command and get a response but URC's never trigger a POLLIN event. 

    I am unsure of what is happening here, any ideas?

    Thank you.

  • Hi Peter,

    Have you checked if this might be a stack overflowing?
    You can enable stack protection by setting CONFIG_HW_STACK_PROTECTION=y in prj.conf.

    If a stack overflows, you'll get some useful debug information to check which instruction causes the error, and which stack is overflowing.

    If possible, you could share your code to make it easier for others to try to reproduce the issues locally and help out that way.

    Regarding the poll() issue, I can't recall having seen similar issues, so I'll have to check that. 
    Have you tried doing a blocking receive instead? If so, do you see the same issues?

    Best regards,

    Jan Tore

  • Thanks Jan Tore,

    If the stack fix does not work I will get some test code to you.

    I tried enabling stack protection but the project fails to load with the error:

    prj.conf:68: warning: attempt to assign the value 'y' to the undefined symbol GW_STACK_PROTECTION

    Config file below, I am using my own broker so I have redacted the IP address.

    Any help will be appreciated.


    CONFIG_GPIO=y
    CONFIG_SERIAL=y
    CONFIG_MODEM_INFO=y

    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    #CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y

    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

    # BSD library
    CONFIG_BSD_LIBRARY=y

    # enable modem trace
    #CONFIG_BSD_LIBRARY_TRACE_ENABLED=y <<<<<<<<<<<<<

    # logging
    CONFIG_LOG=y
    CONFIG_LOG_IMMEDIATE=y
    CONFIG_LOG_DEFAULT_LEVEL=4
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_DBG=y

    # AT Host
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_AT_HOST_LIBRARY=y

    CONFIG_NEWLIB_LIBC=y # need this for newlib time.h

    # MQTT

    CONFIG_MQTT_LIB=y
    CONFIG_MQTT_LIB_TLS=y # TLS enabled
    CONFIG_MQTT_BROKER_PORT=8884
    CONFIG_SEC_TAG=51966
    CONFIG_PEER_VERIFY=1

    CONFIG_MQTT_PUB_TOPIC="ptopic"
    CONFIG_MQTT_SUB_TOPIC="stopic"
    CONFIG_MQTT_CLIENT_ID="dk"
    CONFIG_MQTT_BROKER_HOSTNAME=XXXXXXXXXX

    CONFIG_MQTT_KEEPALIVE=60

    CONFIG_MQTT_MESSAGE_BUFFER_SIZE=1024
    CONFIG_MQTT_PAYLOAD_BUFFER_SIZE=1024

    # Main thread
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_GW_STACK_PROTECTION=y

    CONFIG_HEAP_MEM_POOL_SIZE=2048

  • Hi Peter, 

    I had a typo in the original answer, it should be:

    CONFIG_HW_STACK_PROTECTION=y

    Sorry about that! 

    Regards, 

    Jan Tore 

  • No problem Jan Tore I did some searching and found the protection config.

    I have enabled the HW stack protection and also increased the stack size:

    CONFIG_MAIN_STACK_SIZE=8192

    CONFIG_HW_STACK_PROTECTION=y

    CONFIG_HEAP_MEM_POOL_SIZE=8192

    But I am getting a hard reset on the at callback with no more information showing. Are there any more steps I need to take? I am only monitoring the DK board with the LTE link monitor. I don't have any j-link hardware if that is required.

    the callback simply prints the response:

    void callback_handler(char * response)
    {
    LOG_DBG("Response: %s",response);
    }

Reply
  • No problem Jan Tore I did some searching and found the protection config.

    I have enabled the HW stack protection and also increased the stack size:

    CONFIG_MAIN_STACK_SIZE=8192

    CONFIG_HW_STACK_PROTECTION=y

    CONFIG_HEAP_MEM_POOL_SIZE=8192

    But I am getting a hard reset on the at callback with no more information showing. Are there any more steps I need to take? I am only monitoring the DK board with the LTE link monitor. I don't have any j-link hardware if that is required.

    the callback simply prints the response:

    void callback_handler(char * response)
    {
    LOG_DBG("Response: %s",response);
    }

Children
Related