MQTT-STM32

Dependencies:   MbedJSONValue wifi-ism43362 LSM6DSL HTS221 MQTT

MQTTNetwork.h

Committer:
jingege
Date:
2020-09-23
Revision:
0:775536f6b40b

File content as of revision 0:775536f6b40b:

#ifndef _MQTTNETWORK_H_
#define _MQTTNETWORK_H_

#include "NetworkInterface.h"

class MQTTNetwork {
public:
    MQTTNetwork(NetworkStack* aNetwork) : network(aNetwork) {
        socket = new TCPSocket();
    }

    ~MQTTNetwork() 
    {
        delete socket;
    }

    int read(unsigned char* buffer, int len, int timeout) {
        return socket->recv(buffer, len);
    }

    int write(unsigned char* buffer, int len, int timeout) {
        return socket->send(buffer, len);
    }

    int connect(const char* hostname, int port) {
        int ret = socket->open(network);
        printf("ret ===%d\n\n\n",ret);
        ret = socket->connect(hostname, port);
        printf("ret ======== %d\n\n\n", ret);
        return ret;
    }

    int disconnect() {
        return socket->close();
    }

private:
    NetworkStack* network;
    TCPSocket* socket;
};

#endif // _MQTTNETWORK_H_