![](/media/cache/group/u-blox_logo_trans.png.50x50_q85.png)
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
MQTTNetwork.h@31:22e7fd7b12b3, 2017-09-28 (annotated)
- Committer:
- philware
- Date:
- Thu Sep 28 15:43:38 2017 +0100
- Revision:
- 31:22e7fd7b12b3
- Parent:
- 20:49c9daf2b0ff
Updated N2xx library links.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jan Jongboom |
20:49c9daf2b0ff | 1 | #ifndef _MQTTNETWORK_H_ |
Jan Jongboom |
20:49c9daf2b0ff | 2 | #define _MQTTNETWORK_H_ |
Jan Jongboom |
20:49c9daf2b0ff | 3 | |
Jan Jongboom |
20:49c9daf2b0ff | 4 | #include "NetworkInterface.h" |
Jan Jongboom |
20:49c9daf2b0ff | 5 | |
Jan Jongboom |
20:49c9daf2b0ff | 6 | class MQTTNetwork { |
Jan Jongboom |
20:49c9daf2b0ff | 7 | public: |
Jan Jongboom |
20:49c9daf2b0ff | 8 | MQTTNetwork(NetworkInterface* aNetwork) : network(aNetwork) { |
Jan Jongboom |
20:49c9daf2b0ff | 9 | socket = new TCPSocket(); |
Jan Jongboom |
20:49c9daf2b0ff | 10 | } |
Jan Jongboom |
20:49c9daf2b0ff | 11 | |
Jan Jongboom |
20:49c9daf2b0ff | 12 | ~MQTTNetwork() { |
Jan Jongboom |
20:49c9daf2b0ff | 13 | delete socket; |
Jan Jongboom |
20:49c9daf2b0ff | 14 | } |
Jan Jongboom |
20:49c9daf2b0ff | 15 | |
Jan Jongboom |
20:49c9daf2b0ff | 16 | int read(unsigned char* buffer, int len, int timeout) { |
Jan Jongboom |
20:49c9daf2b0ff | 17 | return socket->recv(buffer, len); |
Jan Jongboom |
20:49c9daf2b0ff | 18 | } |
Jan Jongboom |
20:49c9daf2b0ff | 19 | |
Jan Jongboom |
20:49c9daf2b0ff | 20 | int write(unsigned char* buffer, int len, int timeout) { |
Jan Jongboom |
20:49c9daf2b0ff | 21 | return socket->send(buffer, len); |
Jan Jongboom |
20:49c9daf2b0ff | 22 | } |
Jan Jongboom |
20:49c9daf2b0ff | 23 | |
Jan Jongboom |
20:49c9daf2b0ff | 24 | int connect(const char* hostname, int port) { |
Jan Jongboom |
20:49c9daf2b0ff | 25 | socket->open(network); |
Jan Jongboom |
20:49c9daf2b0ff | 26 | return socket->connect(hostname, port); |
Jan Jongboom |
20:49c9daf2b0ff | 27 | } |
Jan Jongboom |
20:49c9daf2b0ff | 28 | |
Jan Jongboom |
20:49c9daf2b0ff | 29 | void disconnect() { |
Jan Jongboom |
20:49c9daf2b0ff | 30 | |
Jan Jongboom |
20:49c9daf2b0ff | 31 | } |
Jan Jongboom |
20:49c9daf2b0ff | 32 | |
Jan Jongboom |
20:49c9daf2b0ff | 33 | private: |
Jan Jongboom |
20:49c9daf2b0ff | 34 | NetworkInterface* network; |
Jan Jongboom |
20:49c9daf2b0ff | 35 | TCPSocket* socket; |
Jan Jongboom |
20:49c9daf2b0ff | 36 | }; |
Jan Jongboom |
20:49c9daf2b0ff | 37 | |
Jan Jongboom |
20:49c9daf2b0ff | 38 | #endif // _MQTTNETWORK_H_ |