FreematicsNetwork.h
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*************************************************************************
* Freematics Hub Client implementations for ESP8266-AT, SIM800, SIM5360
* Distributed under BSD license
* Visit http://freematics.com/products/freematics-one for more information
* (C)2017-2019 Stanley Huang <stanley@freematics.com.au
*************************************************************************/
#pragma once
#include <Arduino.h>
#include "FreematicsBase.h"
class NullClient
{
public:
virtual GPS_DATA* getLocation() { return m_gps; }
virtual bool startGPS() { return false; }
virtual void stopGPS() {}
protected:
GPS_DATA* m_gps = 0;
};
class UDPClientESP8266AT : public NullClient
{
public:
bool begin(CFreematics* device, bool nocheck = false);
void end();
bool setup(const char* ssid, const char* password, unsigned int timeout = 15000);
String getIP();
float getSignal() { return 0; }
bool open(const char* host, uint16_t port);
void close();
bool send(const char* data, unsigned int len);
char* receive(int* pbytes = 0, unsigned int timeout = 5000);
char* getBuffer() { return buffer; }
private:
bool sendCommand(const char* cmd, unsigned int timeout = 2000, const char* expected = "OK");
char* rxBuf = 0;
int rxLen = 0;
CFreematics* m_device = 0;
char buffer[128];
};
class UDPClientSIM800 : public NullClient
{
public:
bool begin(CFreematics* device, bool nocheck = false);
void end();
bool setup(const char* apn, unsigned int timeout = 30000, bool gps = false, const char* pin = 0);
String getIP();
int getSignal();
String getOperatorName();
bool checkSIM();
bool open(const char* host, uint16_t port);
bool send(const char* data, unsigned int len);
void close();
char* receive(int* pbytes = 0, unsigned int timeout = 5000);
String queryIP(const char* host);
GPS_DATA* getLocation();
char* getBuffer() { return m_buffer; }
private:
bool sendCommand(const char* cmd, unsigned int timeout = 1000, const char* expected = "\r\nOK", bool terminated = false);
char* checkIncoming(int* pbytes);
char m_buffer[80] = {0};
uint8_t m_stage = 0;
CFreematics* m_device = 0;
};
class UDPClientSIM5360 : public NullClient
{
public:
bool begin(CFreematics* device, bool nocheck = false);
void end();
bool setup(const char* apn, unsigned int timeout = 30000, bool gps = false, const char* pin = 0);
String getIP();
int getSignal();
String getOperatorName();
bool checkSIM();
bool startGPS();
void stopGPS();
bool open(const char* host, uint16_t port);
void close();
bool send(const char* data, unsigned int len);
char* receive(int* pbytes = 0, unsigned int timeout = 5000);
char* getBuffer() { return m_buffer; }
private:
// send command and check for expected response
bool sendCommand(const char* cmd, unsigned int timeout = 1000, const char* expected = "\r\nOK");
char* checkIncoming(char* ipd, int* pbytes);
long parseDegree(const char* s);
void checkGPS();
char m_buffer[160] = {0};
byte udpIP[4] = {0};
uint16_t udpPort = 0;
uint8_t m_stage = 0;
CFreematics* m_device = 0;
};