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
MQTTSNUDP.h
- Committer:
- keystone.electronic.solutions@gmail.com
- Date:
- 2018-08-20
- Revision:
- 1:70b751b7a189
File content as of revision 1:70b751b7a189:
#if !defined(MQTTSOCKET_H) #define MQTTSOCKET_H #include "MQTTmbed.h" #include "udp_interface.h" class MQTTSNUDP { int mSocket; UDPinterface *mInterface; char mHost[128]; int mPort; public: MQTTSNUDP(UDPinterface *interface) : mSocket(-1), mInterface(interface), mPort(-1) { } int connect(char* hostname, int port, int timeout=1000) { strncpy(mHost, hostname, 128); mPort = port; mSocket = mInterface->connect(hostname, port); return mSocket; } int read(unsigned char* buffer, int len, int timeout) { char rxHost[256]; int rxPort; return mInterface->read(mSocket, rxHost, &rxPort, buffer, len, timeout); } int write(unsigned char* buffer, int len, int timeout) { return mInterface->write(mSocket, mHost, mPort, buffer, len, timeout); } int disconnect() { return mInterface->disconnect(mSocket); } }; #endif