hellomqttt to thingspeak mqtt and ifttt

Dependencies:   Servo MQTTPacket FP

Committer:
jasonberry
Date:
Wed May 05 14:48:01 2021 +0000
Revision:
25:ca1b1098c77f
TEST

Who changed what in which revision?

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