简体   繁体   中英

time(NULL) returns 0 on PIC-IoT WG development board

I'm working on a project with the PIC-IoT WG wifi development board. I'm trying to modify the demo code to be able to use it on my own servers. The demo uses code like this in several places:

#include <time.h>
static void connectMQTT()
{
   uint32_t currentTime = time(NULL);

   if (currentTime > 0)
   {
      updateJWT(currentTime + UNIX_OFFSET);   
      MQTT_CLIENT_connect();
   }      
   debug_print("CLOUD: MQTT Connect");

   sendSubscribe = true;
}

and every time I turn it on, for 15-20 minutes it tries connecting to the server, but these parts of the code don't run, as time(NULL) seems to return 0.

As far as I understand, in case of PIC microcontrollers time(NULL) should return the number of instruction cycles.

Why does it return 0? Why does it stop returning 0?

In general, time(NULL) from time.h returns a time_t and represents the number of seconds since the epoch (1970 Jan 1 00:00:00). Putting the output of time() into a uint32 could be causing issues on your "servers". Change it to a time_t and see if it fixes the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM