Example project to publish messages to a MQTT-SN broker using the u-blox SARA-N200 NB-IoT modem

Dependencies:   MQTTSNPacket X-NUCLEO-SARA-N200

Committer:
KeystoneElectronic
Date:
Thu Aug 23 11:32:34 2018 +0200
Revision:
12:9a2dab9b927d
Parent:
1:70b751b7a189
Update readme

Who changed what in which revision?

UserRevisionLine numberNew contents of line
keystone.electronic.solutions@gmail.com 1:70b751b7a189 1 #if !defined(MQTT_MBED_H)
keystone.electronic.solutions@gmail.com 1:70b751b7a189 2 #define MQTT_MBED_H
keystone.electronic.solutions@gmail.com 1:70b751b7a189 3
keystone.electronic.solutions@gmail.com 1:70b751b7a189 4 #include "mbed.h"
keystone.electronic.solutions@gmail.com 1:70b751b7a189 5
keystone.electronic.solutions@gmail.com 1:70b751b7a189 6 class Countdown
keystone.electronic.solutions@gmail.com 1:70b751b7a189 7 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 8 public:
keystone.electronic.solutions@gmail.com 1:70b751b7a189 9 Countdown()
keystone.electronic.solutions@gmail.com 1:70b751b7a189 10 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 11 t = new Timer();
keystone.electronic.solutions@gmail.com 1:70b751b7a189 12 interval_end_ms = 0;
keystone.electronic.solutions@gmail.com 1:70b751b7a189 13 }
keystone.electronic.solutions@gmail.com 1:70b751b7a189 14
keystone.electronic.solutions@gmail.com 1:70b751b7a189 15 Countdown(int ms)
keystone.electronic.solutions@gmail.com 1:70b751b7a189 16 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 17 t = new Timer();
keystone.electronic.solutions@gmail.com 1:70b751b7a189 18 countdown_ms(ms);
keystone.electronic.solutions@gmail.com 1:70b751b7a189 19 }
keystone.electronic.solutions@gmail.com 1:70b751b7a189 20
keystone.electronic.solutions@gmail.com 1:70b751b7a189 21 ~Countdown()
keystone.electronic.solutions@gmail.com 1:70b751b7a189 22 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 23 delete t;
keystone.electronic.solutions@gmail.com 1:70b751b7a189 24 }
keystone.electronic.solutions@gmail.com 1:70b751b7a189 25
keystone.electronic.solutions@gmail.com 1:70b751b7a189 26 bool expired()
keystone.electronic.solutions@gmail.com 1:70b751b7a189 27 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 28 return t->read_ms() >= interval_end_ms;
keystone.electronic.solutions@gmail.com 1:70b751b7a189 29 }
keystone.electronic.solutions@gmail.com 1:70b751b7a189 30
keystone.electronic.solutions@gmail.com 1:70b751b7a189 31 void countdown_ms(unsigned long ms)
keystone.electronic.solutions@gmail.com 1:70b751b7a189 32 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 33 t->stop();
keystone.electronic.solutions@gmail.com 1:70b751b7a189 34 interval_end_ms = ms;
keystone.electronic.solutions@gmail.com 1:70b751b7a189 35 t->reset();
keystone.electronic.solutions@gmail.com 1:70b751b7a189 36 t->start();
keystone.electronic.solutions@gmail.com 1:70b751b7a189 37 }
keystone.electronic.solutions@gmail.com 1:70b751b7a189 38
keystone.electronic.solutions@gmail.com 1:70b751b7a189 39 void countdown(int seconds)
keystone.electronic.solutions@gmail.com 1:70b751b7a189 40 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 41 countdown_ms((unsigned long)seconds * 1000L);
keystone.electronic.solutions@gmail.com 1:70b751b7a189 42 }
keystone.electronic.solutions@gmail.com 1:70b751b7a189 43
keystone.electronic.solutions@gmail.com 1:70b751b7a189 44 int left_ms()
keystone.electronic.solutions@gmail.com 1:70b751b7a189 45 {
keystone.electronic.solutions@gmail.com 1:70b751b7a189 46 return interval_end_ms - t->read_ms();
keystone.electronic.solutions@gmail.com 1:70b751b7a189 47 }
keystone.electronic.solutions@gmail.com 1:70b751b7a189 48
keystone.electronic.solutions@gmail.com 1:70b751b7a189 49 private:
keystone.electronic.solutions@gmail.com 1:70b751b7a189 50 Timer *t;
keystone.electronic.solutions@gmail.com 1:70b751b7a189 51 int interval_end_ms;
keystone.electronic.solutions@gmail.com 1:70b751b7a189 52 };
keystone.electronic.solutions@gmail.com 1:70b751b7a189 53
keystone.electronic.solutions@gmail.com 1:70b751b7a189 54 #endif