Skip to content

Commit

Permalink
优化mqtt及http
Browse files Browse the repository at this point in the history
优化mqtt及http,增加N716模块
  • Loading branch information
luyang14 committed Mar 16, 2022
1 parent 921883e commit 3cc15ad
Show file tree
Hide file tree
Showing 8 changed files with 1,120 additions and 545 deletions.
735 changes: 237 additions & 498 deletions EC20xlib.cpp

Large diffs are not rendered by default.

66 changes: 22 additions & 44 deletions EC20xlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,58 @@
#define EC20xlib_h

#include <Arduino.h>
#include <iolte_base.h>

//#define DEBUG
#ifdef DEBUG
#define log(msg) Serial.print(msg)
#define logln(msg) Serial.println(msg)
#else
#define log(msg)
#define logln(msg)
#ifndef TOPIC_MAX_LEN
#define TOPIC_MAX_LEN 128
#endif

#ifndef PAYLOAD_MAX_LEN
#define PAYLOAD_MAX_LEN 1024
#endif

#define USE_HTTP 1
#define USE_MQTT 1
#define USE_TCP 1

#define countof(a) (sizeof(a) / sizeof(a[0]))

#define EC20x_OK 0
#define EC20x_NOTOK 1
#define EC20x_TIMEOUT 2
#define EC20x_FAILURE 3
#define EC20x_DISCONNECT 4

#define EC20x_CMD_TIMEOUT 2000

#define STSTE_SEND 1
#define STSTE_RE 0

extern "C" {
typedef byte (*recallbackFunction)(char* buf, int buflen,uint8_t connectID);
typedef byte (*subcallbackFunction)(char *topic,char* msg,int buflen,uint8_t qos1);
}
//#define EC20xconn Serial2

class EC20xlib {
class EC20xlib : public IOLTE{
public:
EC20xlib(Stream &serial);
~EC20xlib();

byte begin();
byte blockUntilReady(long baudRate);

void powerCycle(int pin);
void powerOn(int pin);
void powerOff(int pin);

int getSignalStrength();
String getRealTimeClock();

int connect(char *ip, char *port,uint8_t connectID);
int disconnect(uint8_t connectID);
uint8_t connected();
boolean connected();
byte ParseMsg(String data);
int postdata(char* buf, int buflen,uint8_t connectID);
byte connectMqttServer(char *clientID,char *ip,char *port,char *username,char *password,uint8_t keepalive,uint8_t will_qos,char *will,char *will_payload);
byte connectMqttServer(char *clientID,char *ip,char *port,char *username,char *password,uint8_t keepalive);
byte connectMqttServer(char *clientID,char *ip,char *port,char *username,char *password);
byte connectMqttServer(char *clientID,char *ip,char *port);

byte SubTopic(char *topic,uint8_t qos1);
byte PubTopic(char *topic,char* msg,uint8_t qos1);
byte UnSubTopic(char *topic,uint8_t qos1);
byte getMessage(char *topic,char* msg,uint8_t qos1);
byte Read_CCID(char *DataBuf);
byte Read_IMEI(char *DataBuf);

void attachsubcallback(subcallbackFunction newFunction);
void attachtcpcallback(recallbackFunction newFunction);
void attacheventcallback(eventcallbackFunction newFunction);
void loop();
String Read_TimeClock();
int Read_Signal();
byte Read_CCID(char *DataBuf);
byte Read_IMEI(char *DataBuf);
private:
Stream* EC20xconn;
uint8_t resend_state;
char *ip;
char *port;
String read();
byte EC20xcommand(const char *command, const char *resp1, const char *resp2, int timeout, int repetitions, String *response);
byte EC20xcommand(const char *command,uint16_t commandlen, const char *resp1, const char *resp2, int timeout, int repetitions, String *response);
byte EC20xwaitFor(const char *resp1, const char *resp2, int timeout, String *response);
long detectRate();
char setRate(long baudRate);
bool connected_state = false;
recallbackFunction getdatecallback = NULL;
subcallbackFunction subdatecallback = NULL;
eventcallbackFunction eventcallback = NULL;
};
#endif
Loading

0 comments on commit 3cc15ad

Please sign in to comment.