Ethernet

Dependencies:   MQTT

Dependents:   MilkcocoaSample_Eth_K64F

Fork of Milkcocoa_EthernetIF by Junichi Katsu

Milkcocoa.h

Committer:
jksoft
Date:
2015-12-15
Revision:
0:23e533c4b1ec
Child:
1:4a634c06c5dc

File content as of revision 0:23e533c4b1ec:

#ifndef _MILKCOCOA_H_
#define _MILKCOCOA_H_

#include "mbed.h"
#include "MQTTESP8266.h"
#include "MQTTClient.h"

#define RECV_TIMEOUT	500

class DataElement {
  public:
    DataElement();
    DataElement(char *json_string);
    void setValue(const char *key, const char *v);
    void setValue(const char *key, int v);
    void setValue(const char *key, double v);
    char *toCharArray();
    char *getString(const char *key);
    int getInt(const char *key);
    float getFloat(const char *key);

  private:
	char json_msg[256];
};

typedef void (*GeneralFunction) (MQTT::MessageData& elem);

class Milkcocoa {
 public:
 
  Milkcocoa(MQTTESP8266 *ipstack, const char *host, uint16_t port, const char *_app_id, const char *client_id);
  Milkcocoa(MQTTESP8266 *ipstack, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session);
  static Milkcocoa* createWithApiKey(MQTTESP8266 *ipstack, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret);
  void connect();
  void loop();
  bool push(const char *path, DataElement dataelement);
  bool send(const char *path, DataElement dataelement);
  bool on(const char *path, const char *event, GeneralFunction cb);

private:
  char servername[64];
  int16_t portnum;
  char _clientid[64];
  char username[32];
  char password[32];
  const char *app_id;

  MQTTESP8266 *_ipstack;
  MQTT::Client<MQTTESP8266, Countdown> client;
  GeneralFunction _cb;
};


#endif