Version of HelloMQTT with u-blox cellular (C027 and C030) boards added.
Dependencies: C12832 MQTT easy-connect ublox-at-cellular-interface-ext ublox-cellular-base ublox-cellular-driver-gen ublox-ppp-cellular-interface ublox-at-cellular-interface-n2xx ublox-cellular-base-n2xx
Fork of HelloMQTT by
LinuxMQTT.h
00001 #if !defined(LINUXMQTT_H) 00002 #define LINUXMQTT_H 00003 00004 class Countdown 00005 { 00006 public: 00007 Countdown() 00008 { 00009 00010 } 00011 00012 Countdown(int ms) 00013 { 00014 countdown_ms(ms); 00015 } 00016 00017 00018 bool expired() 00019 { 00020 struct timeval now, res; 00021 gettimeofday(&now, NULL); 00022 timersub(&end_time, &now, &res); 00023 //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); 00024 //if (res.tv_sec > 0 || res.tv_usec > 0) 00025 // printf("expired %d %d\n", res.tv_sec, res.tv_usec); 00026 return res.tv_sec < 0 || (res.tv_sec == 0 && res.tv_usec <= 0); 00027 } 00028 00029 00030 void countdown_ms(int ms) 00031 { 00032 struct timeval now; 00033 gettimeofday(&now, NULL); 00034 struct timeval interval = {ms / 1000, (ms % 1000) * 1000}; 00035 //printf("interval %d %d\n", interval.tv_sec, interval.tv_usec); 00036 timeradd(&now, &interval, &end_time); 00037 } 00038 00039 00040 void countdown(int seconds) 00041 { 00042 struct timeval now; 00043 gettimeofday(&now, NULL); 00044 struct timeval interval = {seconds, 0}; 00045 timeradd(&now, &interval, &end_time); 00046 } 00047 00048 00049 int left_ms() 00050 { 00051 struct timeval now, res; 00052 gettimeofday(&now, NULL); 00053 timersub(&end_time, &now, &res); 00054 //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); 00055 return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000; 00056 } 00057 00058 private: 00059 00060 struct timeval end_time; 00061 }; 00062 00063 00064 #endif
Generated on Tue Jul 12 2022 21:12:58 by 1.7.2