BayEOSArduino Library
BayTCP.h
1 
10 #ifndef BayTCP_h
11 #define BayTCP_h
12 
13 
14 #ifndef BayTCP_BUFFER
15 #define BayTCP_BUFFER 138
16 #endif
17 
18 #define BayTCP_CONFIG_SERVER 0
19 #define BayTCP_CONFIG_PORT 1
20 #define BayTCP_CONFIG_PATH 2
21 #define BayTCP_CONFIG_USER 3
22 #define BayTCP_CONFIG_PASSWORD 4
23 #define BayTCP_CONFIG_SENDER 5
24 #define BayTCP_CONFIG_APN 6
25 #define BayTCP_CONFIG_PROVPW 7
26 #define BayTCP_CONFIG_PROVUSER 8
27 #define BayTCP_CONFIG_PIN 9
28 #define BayTCP_CONFIG_MAC 6
29 #define BayTCP_CONFIG_IP 7
30 #define BayTCP_CONFIG_MASK 8
31 #define BayTCP_CONFIG_DEFAULT_GW 9
32 
33 #define BayTCP_CONFIG_SIZE 140
34 #define BayTCP_EEPROM_OFFSET 400
35 
36 #define BayTCP_DEBUG_OUTPUT 0
37 #define BayTCP_DEBUG_INPUT 0
38 
39 #define BayTCP_DEBUG_INTERFACE Serial
40 
41 #define printP(x) printPGM(PSTR(x))
42 #define printlnP(x) printlnPGM(PSTR(x))
43 #define wait_for(x,y) wait_forPGM(PSTR(x),y)
44 #define SerialprintP(x) serialprintPGM(PSTR(x))
45 #define SerialprintlnP(x) serialprintlnPGM(PSTR(x))
46 
47 
48 #include <inttypes.h>
49 #include <BayEOS.h>
50 #include "Base64.h"
51 #include <Arduino.h>
52 #include <EEPROM.h>
53 #include "../BayEOSBuffer/BayEOSBuffer.h"
54 
55 
56 class BayTCPInterface : public Stream, public BayEOS {
57 protected:
58 // virtual uint8_t i_init() = 0;
59  virtual int i_available() = 0;
60 public:
61  using Print::write; // pull in write(str) and write(buf, size) from Print
69  uint8_t sendPayload(void);
70 
71 
79  virtual uint8_t connect(void)=0;
80 
84  virtual void disconnect(void)=0;
85 
86 
87 
88 
96  uint8_t sendMultiFromBuffer(uint16_t maxsize=5000);
97  uint8_t sendMultiFromBufferWithAckPayload(uint16_t maxsize=5000);
98 
102  void setConfig(const char *str,uint8_t index);
103 
109  void readConfigFromStringPGM(const char* string);
110 
114  void readConfigFromEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET);
118  void writeConfigToEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET);
119 
124  const char* getConfig(void);
125 
126  const uint8_t* parseMAC(const char* str);
127  const uint8_t* parseIP(const char* str);
128  uint8_t hex2int(const char c);
129 
134  char** getConfigPointer(uint8_t index);
135 
139  boolean _urlencode;
140 protected:
141  virtual void flushMTU(void)=0;
142  virtual void finishTransmissionMode(void)=0;
143  void printPostHeader(uint16_t size);
144  void setConfigPointers(void);
145  uint8_t addToConfigBuffer(uint8_t offset,const char* str);
146 
147  void skipChars(void);
148  uint8_t wait_forOK(uint16_t timeout);
149  uint8_t wait_forPGM(const char* str, uint16_t timeout,uint8_t bytes=0, char* buffer=NULL);
150  uint8_t wait_for_available(uint16_t* timeout,int bytes=1);
151  void printPGM(const char *str);
152  void printlnPGM(const char *str);
153  void serialprintPGM(const char *str);
154  void serialprintlnPGM(const char *str);
155 
156  uint8_t _mac_ip[6];
157  char _config_buffer[BayTCP_CONFIG_SIZE];
158 // char _pgm_buffer[20];
159  char* _server; //0
160  char* _port; //1
161  char* _path; //2
162  char* _user; //3
163  char* _password; //4
164  char* _sender; //5
165  char* _apn; //6
166  char* _prov_pw; //7
167  char* _prov_user; //8
168  char* _pin; //9
169  char _base64buffer[BayTCP_BUFFER];
170  uint8_t _tx_error_count;
171  uint16_t _mtu;
172  void urlDecode(char *str);
173  int strlenURLencoded(const char *str);
174  void printURLencoded(const char *str);
175  static const char* const _urlencodedChars;
176 
177 };
178 
179 
180 
181 
182 
183 
184 #endif
Definition: BayEOS.h:188
Definition: BayTCP.h:56
void readConfigFromStringPGM(const char *string)
Definition: BayTCP.cpp:448
uint8_t sendPayload(void)
Definition: BayTCP.cpp:393
boolean _urlencode
Definition: BayTCP.h:139
void readConfigFromEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET)
Definition: BayTCP.cpp:467
void setConfig(const char *str, uint8_t index)
Definition: BayTCP.cpp:539
const char * getConfig(void)
Definition: BayTCP.cpp:484
char ** getConfigPointer(uint8_t index)
Definition: BayTCP.cpp:488
uint8_t sendMultiFromBuffer(uint16_t maxsize=5000)
Definition: BayTCP.cpp:195
void writeConfigToEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET)
Definition: BayTCP.cpp:478
virtual void disconnect(void)=0
virtual uint8_t connect(void)=0