http_client network error on thingy91

Hello,

I am trying to use http requests on Thingy91 and therefore I tried with the sample from zephyr/samples/net/sockets/http_client.

I can build the project without any problem but when I try to run it, I get the following error when I open a putty terminal:

I did not change anything in the code, and I was supposing it was not a network problem since I activated my SIM card and I can run the asset_tracker and see the data in nrFcloud without any issue.

I am using the nrfConnectSDK 2.0.0, and the SIM is from twilio.

Best regards,

C

  • Hello Carole, 

    rupcar said:
    Actually, for now I just edited the https_client so that what was in the main() is in a new function called network_connection().

    You have placed network_connection() and its content into a while(1) loop, which now explains the behaviour you are facing. 

    Please revert these changes immediately, the function calls inside the main() function of the HTTPS Client are not supposed to be called more than once! 

    The modem is not designed for being initialised/enabled and shutdown during each iteration of the main function. That will wear out its non-volatile memory. Referring to the CAUTION part in +CFUN. 

    CFUN=0 causes writing to NVM. When using CFUN=0, take NVM wear into account. 


    The same applies to sockets, they are not intended to be opened and closed during each iteration neither. 

    Additionally, it might be good to know that all samples within the nRF Connect SDK are based on the Zephyr framework, which is a RTOS. This implies that a main() function always is a scheduled thread. Referring to the Threads and Scheduling documentation for more information. 

    Cheers, 

    Markus 

  • Hello,

    Thank you again for the answer!

    I revert those changes and I don't get the err 116 coming from connect() anymore.

    But 115 from getAddrInfo() is still there... I am guessing then it is more a network problem? it is, is there a way to choose which network provider's it connects to and see how strong the connection is ?

    Also, I had my while() loop because I intent to do a POST request every hour (to a database). What is then the best way to proceed ?

    Carole

  • Hello Carole, 

    rupcar said:
    Also, I had my while() loop because I intent to do a POST request every hour (to a database). What is then the best way to proceed ?

    You probably need to find that out for yourself, as I do not know according to which requirements your application is expected to work. I can only come up with a fairly simple suggestion :-) 

    Once modem is initialised and set to normal mode, it will connect to a carrier and keep that connection until further notice, as long as the requirements to do so are fulfilled.  

    Sockets are operating in a similar way. So, if I would add a while(1) in main, then it would be after the HTTP response was printed and before the clean_up will be performed, in other words here. That way you can always initialise a new send() event, but at a certain point you might want to introduce a semaphore to keep you application in sync. 

    rupcar said:
    But 115 from getAddrInfo() is still there... I am guessing then it is more a network problem? it is, is there a way to choose which network provider's it connects to and see how strong the connection is ?

    I see that you have changed the server from 'example.com' to 'google.com'.  

    #define HTTPS_PORT 443 // https port 
    #define HTTPS_HOSTNAME "google.com"
    #define HTTP_HEAD                                                              \
    	"HEAD / HTTP/1.1\r\n"                                                  \
    	"Host: " HTTPS_HOSTNAME ":443\r\n"                                     \
    	"Connection: close\r\n\r\n"
    #define HTTP_HEAD_LEN (sizeof(HTTP_HEAD) - 1)
    #define HTTP_HDR_END "\r\n\r\n"
    #define RECV_BUF_SIZE 2048
    #define TLS_SEC_TAG 42

    Have you updated the certificate accordingly? 

    Regards, 

    Markus 

  • Hello,

    Thank you for the suggestion!

    I think that the code I sent you was with the wrong certificate but I was trying to connect without it for now anyway. As it was still working half of the time I think it was not the issue for now.

    I don't know how it made the difference but I put the SIM card in my phone to see how the connection on it was, and now when I put it back in the Thingy I don't have the error anymore...

    Carole

  • Thanks a lot for the feedback, Carole :-) 

    rupcar said:
    I think that the code I sent you was with the wrong certificate but I was trying to connect without it for now anyway. As it was still working half of the time I think it was not the issue for now.

    Well, if you would like to use the HTTPS protocol with port 443, then a certificate is required. Otherwise, the connection should always be rejected by the server. 

    rupcar said:
    I don't know how it made the difference but I put the SIM card in my phone to see how the connection on it was, and now when I put it back in the Thingy I don't have the error anymore...

    I’m not sure if I would recommend putting a cellular IoT SIM card into a mobile phone. That is not supposed to work anyway, as the network protocols are different. 

    Cheers, 

    Markus 

Related