Added compatibility with ESP8266 platform
This commit is contained in:
parent
3f0dc11008
commit
e751d31aa9
5 changed files with 48 additions and 36 deletions
|
@ -5,6 +5,7 @@ env:
|
|||
- BOARD="arduino:avr:uno"
|
||||
- BOARD="arduino:avr:leonardo"
|
||||
- BOARD="arduino:avr:mega:cpu=atmega2560"
|
||||
- BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K"
|
||||
|
||||
before_install:
|
||||
# install Arduino IDE
|
||||
|
@ -12,6 +13,7 @@ before_install:
|
|||
- tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz
|
||||
- mv arduino-$ARDUINO_IDE_VERSION $HOME/arduino-ide
|
||||
- export PATH=$PATH:$HOME/arduino-ide
|
||||
|
||||
# firewall Arduino IDE noise (https://github.com/per1234/arduino-ci-script/issues/1#issuecomment-504158113)
|
||||
- sudo iptables -P INPUT DROP
|
||||
- sudo iptables -P FORWARD DROP
|
||||
|
@ -20,6 +22,12 @@ before_install:
|
|||
- sudo iptables -A OUTPUT -o lo -j ACCEPT
|
||||
- sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
||||
|
||||
# install 3rd party boards
|
||||
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json,https://dl.espressif.com/dl/package_esp32_index.json" --save-prefs 2>&1
|
||||
- if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then
|
||||
arduino --install-boards esp8266:esp8266;
|
||||
fi
|
||||
|
||||
# create directory to save the library and create symbolic link
|
||||
install:
|
||||
- mkdir -p $HOME/Arduino/libraries
|
||||
|
|
|
@ -39,7 +39,9 @@
|
|||
#include "Module.h"
|
||||
|
||||
#include "modules/CC1101.h"
|
||||
#ifndef ESP8266
|
||||
#include "modules/ESP8266.h"
|
||||
#endif
|
||||
#include "modules/HC05.h"
|
||||
#include "modules/JDY08.h"
|
||||
#include "modules/nRF24.h"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#error "Unsupported Arduino version (< 1.0.0)"
|
||||
#endif
|
||||
|
||||
//#define RADIOLIB_DEBUG
|
||||
|
@ -71,52 +71,52 @@
|
|||
/*!
|
||||
\brief Use 1 bit stop.
|
||||
*/
|
||||
#define UART_STOPBIT_1 0x01
|
||||
#define RADIOLIB_UART_STOPBIT_1 0x01
|
||||
|
||||
/*!
|
||||
\brief Use 1.5 bit stop.
|
||||
*/
|
||||
#define UART_STOPBIT_1_5 0x02
|
||||
#define RADIOLIB_UART_STOPBIT_1_5 0x02
|
||||
|
||||
/*!
|
||||
\brief Use 2 bit stop.
|
||||
*/
|
||||
#define UART_STOPBIT_2 0x03
|
||||
#define RADIOLIB_UART_STOPBIT_2 0x03
|
||||
|
||||
/*!
|
||||
\brief No parity.
|
||||
*/
|
||||
#define UART_PARITY_NONE 0x00
|
||||
#define RADIOLIB_UART_PARITY_NONE 0x00
|
||||
|
||||
/*!
|
||||
\brief Odd parity.
|
||||
*/
|
||||
#define UART_PARITY_ODD 0x01
|
||||
#define RADIOLIB_UART_PARITY_ODD 0x01
|
||||
|
||||
/*!
|
||||
\brief Even parity.
|
||||
*/
|
||||
#define UART_PARITY_EVEN 0x02
|
||||
#define RADIOLIB_UART_PARITY_EVEN 0x02
|
||||
|
||||
/*!
|
||||
\brief No flow control.
|
||||
*/
|
||||
#define UART_FLOW_NONE 0x00
|
||||
#define RADIOLIB_UART_FLOW_NONE 0x00
|
||||
|
||||
/*!
|
||||
\brief RTS only.
|
||||
*/
|
||||
#define UART_FLOW_RTS 0x01
|
||||
#define RADIOLIB_UART_FLOW_RTS 0x01
|
||||
|
||||
/*!
|
||||
\brief CTS only.
|
||||
*/
|
||||
#define UART_FLOW_CTS 0x02
|
||||
#define RADIOLIB_UART_FLOW_CTS 0x02
|
||||
|
||||
/*!
|
||||
\brief Both RTS and CTS.
|
||||
*/
|
||||
#define UART_FLOW_BOTH 0x03
|
||||
#define RADIOLIB_UART_FLOW_BOTH 0x03
|
||||
|
||||
/*!
|
||||
\}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#ifndef ESP8266
|
||||
#include "ESP8266.h"
|
||||
|
||||
ESP8266::ESP8266(Module* module) {
|
||||
|
@ -9,15 +10,15 @@ int16_t ESP8266::begin(long speed) {
|
|||
_mod->AtLineFeed = "\r\n";
|
||||
_mod->baudrate = speed;
|
||||
_mod->init(USE_UART, INT_NONE);
|
||||
|
||||
|
||||
// empty UART buffer (garbage data)
|
||||
_mod->ATemptyBuffer();
|
||||
|
||||
|
||||
// test AT setup
|
||||
if(!_mod->ATsendCommand("AT")) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
|
@ -26,10 +27,10 @@ int16_t ESP8266::reset() {
|
|||
if(!_mod->ATsendCommand("AT+RST")) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
// wait for the module to start
|
||||
delay(2000);
|
||||
|
||||
|
||||
// test AT setup
|
||||
uint32_t start = millis();
|
||||
while (millis() - start < 3000) {
|
||||
|
@ -39,7 +40,7 @@ int16_t ESP8266::reset() {
|
|||
return(ERR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
@ -48,7 +49,7 @@ int16_t ESP8266::join(const char* ssid, const char* password) {
|
|||
if(!_mod->ATsendCommand("AT+CWMODE_CUR=3")) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
// build AT command
|
||||
const char* atStr = "AT+CWJAP_CUR=\"";
|
||||
uint8_t cmdLen = strlen(atStr) + strlen(ssid) + strlen(password) + 4;
|
||||
|
@ -58,19 +59,19 @@ int16_t ESP8266::join(const char* ssid, const char* password) {
|
|||
strcat(cmd, "\",\"");
|
||||
strcat(cmd, password);
|
||||
strcat(cmd, "\"");
|
||||
|
||||
|
||||
// send command
|
||||
bool res = _mod->ATsendCommand(cmd);
|
||||
delete[] cmd;
|
||||
if(!res) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
// disable multiple connection mode
|
||||
if(!_mod->ATsendCommand("AT+CIPMUX=0")) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
|
@ -79,7 +80,7 @@ int16_t ESP8266::openTransportConnection(const char* host, const char* protocol,
|
|||
itoa(port, portStr, 10);
|
||||
char tcpKeepAliveStr[6];
|
||||
itoa(tcpKeepAlive, tcpKeepAliveStr, 10);
|
||||
|
||||
|
||||
// build AT command
|
||||
const char* atStr = "AT+CIPSTART=\"";
|
||||
uint8_t cmdLen = strlen(atStr) + strlen(protocol) + strlen(host) + strlen(portStr) + 5;
|
||||
|
@ -97,14 +98,14 @@ int16_t ESP8266::openTransportConnection(const char* host, const char* protocol,
|
|||
strcat(cmd, ",");
|
||||
strcat(cmd, tcpKeepAliveStr);
|
||||
}
|
||||
|
||||
|
||||
// send command
|
||||
bool res = _mod->ATsendCommand(cmd);
|
||||
delete[] cmd;
|
||||
if(!res) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
|
@ -124,19 +125,19 @@ int16_t ESP8266::send(const char* data) {
|
|||
char* cmd = new char[strlen(atStr) + strlen(lenStr)];
|
||||
strcpy(cmd, atStr);
|
||||
strcat(cmd, lenStr);
|
||||
|
||||
|
||||
// send command
|
||||
bool res = _mod->ATsendCommand(cmd);
|
||||
delete[] cmd;
|
||||
if(!res) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
// send data
|
||||
if(!_mod->ATsendCommand(data)) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
|
@ -148,26 +149,26 @@ int16_t ESP8266::send(uint8_t* data, uint32_t len) {
|
|||
char* cmd = new char[strlen(atStr) + strlen(lenStr)];
|
||||
strcpy(cmd, atStr);
|
||||
strcat(cmd, lenStr);
|
||||
|
||||
|
||||
// send command
|
||||
bool res = _mod->ATsendCommand(cmd);
|
||||
delete[] cmd;
|
||||
if(!res) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
// send data
|
||||
if(!_mod->ATsendData(data, len)) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
size_t ESP8266::receive(uint8_t* data, size_t len, uint32_t timeout) {
|
||||
size_t i = 0;
|
||||
uint32_t start = millis();
|
||||
|
||||
|
||||
// wait until the required number of bytes is received or until timeout
|
||||
while((millis() - start < timeout) && (i < len)) {
|
||||
while(_mod->ModuleSerial->available() > 0) {
|
||||
|
@ -188,7 +189,7 @@ size_t ESP8266::getNumBytes(uint32_t timeout, size_t minBytes) {
|
|||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// read response
|
||||
char rawStr[20];
|
||||
uint8_t i = 0;
|
||||
|
@ -205,17 +206,18 @@ size_t ESP8266::getNumBytes(uint32_t timeout, size_t minBytes) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get the number of bytes in response
|
||||
char* pch = strtok(rawStr, ",:");
|
||||
if(pch == NULL) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
pch = strtok(NULL, ",:");
|
||||
if(pch == NULL) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
return(atoi(pch));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef _RADIOLIB_ESP8266_H
|
||||
#if !defined(_RADIOLIB_ESP8266_H) && !defined(ESP8266)
|
||||
#define _RADIOLIB_ESP8266_H
|
||||
|
||||
#include "Module.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue