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 Reply Children
  • Dear Simon

    I tried with your suggestion: ncs v1.0.0

    and your example: ( change to my webserver address)

     char send_buf[] = "POST /? HTTP/1.1\r\n"\
    		"Host: 142.93.37.192\r\n"\
    		"Connection: keep-alive\r\n"\
    	    "Content-type: application/x-www-form-urlencoded\r\n"\
    		"Content-length: 50\r\n\r\n"\
    		"hng12 34 566 678899 01233 345678 99876543 2765432654";

    and it works, 

    your code, you did NOT use function snprintf() 

    char send_buf[MAXLINE + 1];
    	      
    int send_data_len_post = snprintf(send_buf,
    				         500, 
    				         POST_TEMPLATE, HTTP_PATH,
    				         HTTP_HOST, strlen(PostString),
    				         PostString);

    snprintf() does NOT work !! 

    I want to use snprintf() because I want to assign my "PostString" to send_buf() 

    I am confusing: why snprintf() does NOT work? if i use your suggestion, how can i assign my data to send_buf()

    Thanks so much, 

    Yeah, 1 more thing, about NCS v1.0.0-rc4, I will tell you why I used this version: We ( my company) got the support from Nordicsemi and  came to help us. and we tried ncs v1.0.0, asset_tracker DIDNT work, it didnt show the real data of GPS, so Bjørn suggested use ncs v.1.0.0-rc4, then asset_tracker WORKs. 

    Thanks again 

    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

Related