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

HTTP POST with NCS v1.0.0-rc4

Dear

I just tried to run LTE-M/HTTP POST with NCS v1.0.0-rc4 (with nrf git fetch origin pull/943/head:branch1)

but, I COULD NOT POST any more:

**** Booting Zephyr OS build v1.14.99-ncs2-rc4-495-ga8933a2ead01 *****
LTETESTING is starting 
 LTE is connecting........... 
Checking LTE_M signal.............

+COPS: 0,2,"24201",7

OK

OK

+CEREG: 2,1,"765D","0110C303",7

OK


Original String is: +CEREG: 2,1,"765D","0110C303",7

OK

Found the LTE_M signal 
Closing socket

  find LTE_M signal........... 
***** USAGE FAULT *****
  Illegal load of EXC_RETURN into PC
***** Hardware exception *****
Current thread ID = 0x200203a8
Faulting instruction address = 0x0
Fatal fault in thread 0x200203a8! Aborting.
Exception occurred in Secure State
***** HARD FAULT *****
  Fault escalation (see below)
***** BUS FAULT *****
  Precise data bus error
  BFAR Address: 0x50008120
***** Hardware exception *****
Current thread ID = 0x20021ae4
Faulting instruction address = 0x21992
Fatal fault in ISR! Spinning...

It worked normal with the old version v0.4.0

1. when i used the same setup, i got error: 

1> zephyr/subsys/net/ip/libsubsys__net__ip.a(net_if.c.obj): In function `net_if_ipv6_calc_reachable_time':
1> D:/hng/projects/CyCollector/ncs_v1.0.0_rc4/zephyr/subsys/net/ip/net_if.c:2067: undefined reference to `sys_rand32_get'
1> collect2.exe: error: ld returned 1 exit status

2. I added the option: 

# Disable native network stack to save some memory
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=n

then, Build Solution: Build completed

but, I got the error 

My code:

LTE_M_NB-IoT.7z

Thanks so much

Regards, 

hng

Parents
  • I was able to post to a webserver, with ncs v1.0.0 and modem v1.0.0. Could you test my attached example?

    http_post.zip

    Best regards,

    Simon

  • Hi @Simon

    Thanks so much, I just backed from vocation, I will try your suggestion and contact with you soon

    Mvh, 

    Hoang Nguyen 

  • Hi Simon, 

    I tried with a simple example to test snprintf() function. 1 with LTE and without LTE

    1. Without LTE: 

    # LTE link control
    #CONFIG_LTE_LINK_CONTROL=y

    #include <zephyr.h>
    #include <net/socket.h>
    #include <stdio.h>
    #include <uart.h>
    #include <string.h>
    
    #define MAXLINE 4096
    #define HTTP_HOST "142.93.37.192"
    #define HTTP_PATH "/"
    #define TEST_STRING  "Hello from nRF9160 DK"
    
    #define POST_TEMPLATE "POST %s? HTTP/1.1\r\n"\
    		"Host: %s\r\n"\
    		"Connection: keep-alive\r\n"\
    	        "Content-type: application/x-www-form-urlencoded\r\n"\
    		"Content-length: %d\r\n\r\n"\
    		"%s"
    int main(void)
    {
    
         char tmp_str[MAXLINE + 1];
         snprintf(tmp_str,500,
    		"$GPGGA,%02d%02d%02d.200,%8.3f,N,%09.3f,W,1," 
    		"12,1.0,0.0,M,0.0,M,,*", 2019, 07, 23, 59.3033, 10.454);
         printf("tmp_string is: %s \n",tmp_str); 
         
    
         char send_buf[MAXLINE + 1];
         int send_data_len_post = snprintf(send_buf,
    				         500, 
    				         POST_TEMPLATE, HTTP_PATH,
    				         HTTP_HOST, strlen(TEST_STRING),
    				         TEST_STRING);
    
         printf("send_buf is: %s \n",send_buf);
         printk("send err: %d\n\r", send_data_len_post);
         while (1) {
              //5 seconds delay
              k_sleep(5000);
              
              }
    	
    }

    it works, 

    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    tmp_string is: $GPGGA,20190723.200,  59.303,N,00010.454,W,1,12,1.0,0.0,M,0.0,M,,* 
    send_buf is: POST /? HTTP/1.1
    
    Host: 142.93.37.192
    
    Connection: keep-alive
    
    Content-type: application/x-www-form-urlencoded
    
    Content-length: 21
    
    
    
    Hello from nRF9160 DK 
    send err: 155

    and Now, without LTE:

    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y

    and error:

    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    tmp_string is: $GPGGA,201907***** HARD FAULT *****
      Fault escalation (see below)
    ***** BUS FAULT *****
      Precise data bus error
      BFAR Address: 0x61000064
    ***** Hardware exception *****
    Current thread ID = 0x61000000
    Faulting instruction address = 0xd998
    Fatal fault in ISR! Spinning...
    

    snprintf() and LTE_LINK_CONTROL conflict !?

    Thanks, 

    Mvh

    Hoang Nguyen

  • Try using snprintk() instead, that worked for me.

    Best regards,

    Simon

  • Hi Simon, 

    I tried to use snprintk(), but it did NOT work, the same error came with me

    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    tmp_string is: $GPGGA,2019072***** HARD FAULT *****
      Fault escalation (see below)
    ***** BUS FAULT *****
      Precise data bus error
      BFAR Address: 0x61000064
    ***** Hardware exception *****
    Current thread ID = 0x61000000
    Faulting instruction address = 0xd998
    Fatal fault in ISR! Spinning...
    
    

    can you send me the full setup. thanks

    Mvh

    Hoang Nguyen

  • I am sorry, I was too quick to answer and gave you wrong information. The change that made it work was to set CONFIG_NO_OPTIMIZATION=y in prj.conf. I am attaching main.c and prj.conf down below.

    prj.conf

    CONFIG_BSD_LIBRARY=y
    CONFIG_TEST_RANDOM_GENERATOR=y
    CONFIG_NETWORKING=y
    CONFIG_NET_BUF_USER_DATA_SIZE=1
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_NET_RAW_MODE=y
    CONFIG_HEAP_MEM_POOL_SIZE=1024
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_NO_OPTIMIZATIONS=y

    main.c

    #include <zephyr.h>
    #include <net/socket.h>
    #include <stdio.h>
    #include <uart.h>
    #include <string.h>
    
    #define MAXLINE 4096
    #define HTTP_HOST "142.93.37.192"
    #define HTTP_PATH "/"
    #define TEST_STRING  "Hello from nRF9160 DK"
    
    #define POST_TEMPLATE "POST %s? HTTP/1.1\r\n"\
    		"Host: %s\r\n"\
    		"Connection: keep-alive\r\n"\
    	        "Content-type: application/x-www-form-urlencoded\r\n"\
    		"Content-length: %d\r\n\r\n"\
    		"%s"
    int main(void)
    {
         printk("Hello from start of main");
         char tmp_str[MAXLINE + 1];
         snprintf(tmp_str,500,
    		"$GPGGA,%02d%02d%02d.200,%8.3f,N,%09.3f,W,1," 
    		"12,1.0,0.0,M,0.0,M,,*", 2019, 07, 23, 59.3033, 10.454);
         //printf("tmp_string is: %s \n",tmp_str); 
         
    
         char send_buf[MAXLINE + 1];
         int send_data_len_post = snprintk(send_buf,
                                             500,
    				         POST_TEMPLATE, HTTP_PATH,
    				         HTTP_HOST, strlen(TEST_STRING),
    				         TEST_STRING);
    
         printf("send_buf is: %s \n",send_buf);
         printk("send err: %d\n\r", send_data_len_post);
         while (1) {
              //5 seconds delay
              k_sleep(5000);
              
              }
    	
    }

    Best regards,

    Simon

  • Hi Simon

    CONFIG_NO_OPTIMIZATION=y in prj.conf

    Ja, thats what i am looking for. 

    Thanks so much 

    Mvh

    Hoang Nguyen

Reply Children
  • Dear Simon, 

    Ja, it works, but I got another "funny" error ( because I dont know why!!!) 

    I removed: 

    printk("Hello from start of main");
         char tmp_str[MAXLINE + 1];
         snprintf(tmp_str,500,
    		"$GPGGA,%02d%02d%02d.200,%8.3f,N,%09.3f,W,1," 
    		"12,1.0,0.0,M,0.0,M,,*", 2019, 07, 23, 59.3033, 10.454);
         //printf("tmp_string is: %s \n",tmp_str); 
         

    and just ran:

    int main(void){
    
         printk("Hello from start of main \n");
         char send_buf[MAXLINE + 1];
         int send_data_len_post = snprintk(send_buf,
                                             500,
    				         POST_TEMPLATE, HTTP_PATH,
    				         HTTP_HOST, strlen(TEST_STRING),
    				         TEST_STRING);
    
         printf("send_buf is: %s \n",send_buf);
         printk("send err: %d\n\r", send_data_len_post);
        
         //snprintk_post("OMG whyyyyyyyyyyyy \n"); 
         while (1) {
              //5 seconds delay
              k_sleep(5000);
              
              }
       }

    it didnt work:

    SPM: NS image at 0xc000
    SPM: NS MSP at 0x20024cf8
    SPM: NS reset vector at 0xec1d
    SPM: prepare to jump to Non-Secure image.
    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    Hello from start of main %
    ***** USAGE FAULT *****
      Illegal use of the EPSR
    ***** Hardware exception *****
    Current thread ID = 0x20021e9c
    Faulting instruction address = 0xec1c
    Fatal fault in essential thread! Spinning...
    

    then, I tried to add an extra variable (but i will not use it !!!!)

    char tmp[MAXLINE + 1];

    and, it works:

    SPM: NS image at 0xc000
    SPM: NS MSP at 0x20024cf8
    SPM: NS reset vector at 0xec1d
    SPM: prepare to jump to Non-Secure image.
    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    Hello from start of main 
    send_buf is: POST /? HTTP/1.1
    
    Host: 142.93.37.192
    
    Connection: keep-alive
    
    Content-type: application/x-www-form-urlencoded
    
    Content-length: 19
    
    
    
    111 from nRF9160 DK 
    send err: 153
    

    I dont know why!!!????

    Thanks,

    mvh

    Hoang 

  • I am sorry for the delay. The support staff is reduced during the summer holidays, and you may experience delayed answers. Have you been able to resolve this issue?

    Best regards,

    Simon

  • Hi Simon, 

    I understand it, not yet Disappointed

    Mvh

    Hoang

  • Hmm.. That is really strange. I was able to recreate the error message. I tried to minimize the project to try to locate the problem, and I eventually ended up with the following project, which was giving the same error:

    #include <zephyr.h>
    #include <net/socket.h>
    #include <stdio.h>
    
    int main(void)
    {
         //char tmp_str2[2];
         char send_buf[4096];
    
         while (1) {
              
              }
    	
    }

    However, if I set CONFIG_SIZE_OPTIMIZATION=y (and removed the optimize nothing config), then it worked fine. 

    I will report the problem internally. In the mean time, I guess you have to declare tmp_str as a temporary solution.

    Best regards,

    Simon

  • The solution to this is to set CONFIG_NO_OPTIMIZATIONS to y, and increase the main stack size through CONFIG_MAIN_STACK_SIZE or place it in the data section instead of on the stack by declaring and initializing it outside of the main function.

    Best regards,

    Simon

Related