Sample MQTT program - simple send and receive (MQ Telemetry Transport) for GainSpan Wi-Fi module
Dependencies: C12832 GSwifiInterface MQTT mbed-rtos mbed
Fork of HelloMQTT by
mbedのMQTTグループで保守されているMQTTライブラリを GainSpan Wi-Fi モジュールへ対応させたサンプルです。
MQTT (MQ Telemetry Transport) とは、IoTやM2M向け デバイス間通信のためのプロトコルです。
MQTTサーバーには http://iot.eclipse.org/ のサンドボックスを使います。 送信したメッセージをエコーバックしてくるだけの動作をします。
mbed Application Board を使う場合は次の行のコメントアウトを外すとLCDへ表示するようになる。
#define MBED_APPLICATION_BOARD
GainSpanモジュールの接続ピンについては次の行で指定する。
gs = new GSwifiInterface(p9, p10, NC, NC, p30, NC, 9600); //tx, rx, cts, rts, reset, alarm, baud
Wi-Fiアクセスポイントは次の行で指定する。
#define SEC GSwifi::SEC_WPA_PSK #define SSID "SSID" #define PASS "PASSPHRASE"
Diff: Linux-example/LinuxMQTT.h
- Revision:
- 16:fd155e824a80
- Parent:
- 15:d8a31b66a85d
--- a/Linux-example/LinuxMQTT.h Fri Aug 01 23:46:08 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -#if !defined(LINUXMQTT_H) -#define LINUXMQTT_H - -class Countdown -{ -public: - Countdown() - { - - } - - Countdown(int ms) - { - countdown_ms(ms); - } - - - bool expired() - { - struct timeval now, res; - gettimeofday(&now, NULL); - timersub(&end_time, &now, &res); - //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); - //if (res.tv_sec > 0 || res.tv_usec > 0) - // printf("expired %d %d\n", res.tv_sec, res.tv_usec); - return res.tv_sec < 0 || (res.tv_sec == 0 && res.tv_usec <= 0); - } - - - void countdown_ms(int ms) - { - struct timeval now; - gettimeofday(&now, NULL); - struct timeval interval = {ms / 1000, (ms % 1000) * 1000}; - //printf("interval %d %d\n", interval.tv_sec, interval.tv_usec); - timeradd(&now, &interval, &end_time); - } - - - void countdown(int seconds) - { - struct timeval now; - gettimeofday(&now, NULL); - struct timeval interval = {seconds, 0}; - timeradd(&now, &interval, &end_time); - } - - - int left_ms() - { - struct timeval now, res; - gettimeofday(&now, NULL); - timersub(&end_time, &now, &res); - //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); - return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000; - } - -private: - - struct timeval end_time; -}; - - -#endif \ No newline at end of file