Now comes the consolidating part.
I've added the following changes to the code:
RemoteXY.h
/* RemoteXY.h
A RemoteXY Library - Remote device control
version 2.3.5ESP32
===========================================================
For use RemoteXY library visit website http://remotexy.com
This website will help you use the library for configuring
a remote control from a smartphone or tablet.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Supported modes:
All boards:
#define REMOTEXY_MODE__HARDSERIAL
#define REMOTEXY_MODE__SOFTSERIAL
#define REMOTEXY_MODE__ETHERNET_LIB
#define REMOTEXY_MODE__ETHERNET_LIB_CLOUD
#define REMOTEXY_MODE__ESP8266_HARDSERIAL
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_CLOUD
#define REMOTEXY_MODE__ESP8266_SOFTSERIAL
#define REMOTEXY_MODE__ESP8266_SOFTSERIAL_POINT
#define REMOTEXY_MODE__ESP8266_SOFTSERIAL_CLOUD
#define REMOTEXY_MODE__WIFI_LIB
Only ESP8266 boards:
#define REMOTEXY_MODE__ESP8266WIFI_LIB
#define REMOTEXY_MODE__ESP8266WIFI_LIB_POINT
#define REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD
Only ESP32 boards:
#define REMOTEXY_MODE__ESP32_BT
#define REMOTEXY_MODE__ESP32_BLE
#define REMOTEXY_MODE__ESP32WIFI_LIB
#define REMOTEXY_MODE__ESP32WIFI_LIB_POINT
Only Nano BLE boards:
#define REMOTEXY_MODE__BLE_NANO
Parameters depending on the selected mode (for example):
#define REMOTEXY_SERIAL Serial // for Hardware Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_SERIAL_RX 2 // for Software Serial
#define REMOTEXY_SERIAL_TX 3 // for Software Serial
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "1234567890"
#define REMOTEXY_ETHERNET_MAC "DE:AD:BE:EF:EF:ED" // for Ethernet modules
#define REMOTEXY_SERVER_PORT 6377
#define REMOTEXY_CLOUD_TOKEN "xxxx" // for Cloud
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com" // for Cloud
#define REMOTEXY_CLOUD_PORT 6376 // for Cloud
#define REMOTEXY_ACCESS_PASSWORD "1"
#define REMOTEXY_BT_DEVICENAME "RemoteXY" // for ESP32 BT & BLE
Debug log info on 115200 (define before include this library):
#define REMOTEXY__DEBUGLOGS Serial
Flag to indicate when something has been changed (define before include this library):
#define REMOTEXY_CHANGED_FLAG
= Version history ========================================
version 2.2.5
- support MPIDE;
version 2.3.1
- Support the device access password;
- Support the cloud server as beta test;
- Fixed a bug where the length of variables more than 255;
- Fixed a bug where ESP module reboot and device did not see it;
- Fixed a bug where the connection was filed and the device
did not see it and reconnection is impossible
version 2.3.4
- Fixed a bug where the length of all input variables more than 256;
- Fixed a bug where millis() overflow in 50 days;
- Fixed some bugs;
version 2.3.5
- Fixed some bugs;
version 2.3.5ESP32
- Support for ESP32 (WiFi, BT, BLE);
- Support for changed_flag;
*/
#ifndef _REMOTEXY_H_
#define _REMOTEXY_H_
//#define REMOTEXY__DEBUGLOGS Serial
#define REMOTEXY__DEBUGLOGS_SPEED 115200
#if defined(REMOTEXY_MODE__HARDSERIAL) || defined(REMOTEXY_MODE__SERIAL) || defined(REMOTEXY_MODE__HC05_HARDSERIAL) || defined(REMOTEXY_MODE__BLE_NANO)
#define REMOTEXY_MOD__SERIAL
#define REMOTEXY_PORT__HARDSERIAL
#elif defined(REMOTEXY_MODE__SOFTSERIAL) || defined(REMOTEXY_MODE__SOFTWARESERIAL) || defined(REMOTEXY_MODE__HC05_SOFTSERIAL)
#define REMOTEXY_MOD__SERIAL
#define REMOTEXY_PORT__SOFTSERIAL
#elif defined(REMOTEXY_MODE__ESP32_BT)
#define REMOTEXY_MOD__SERIAL
#define REMOTEXY_PORT__ESP32_BT
#elif defined(REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT) || defined(REMOTEXY_MODE__ESP8266POINT_HARDSERIAL)
#define REMOTEXY_MOD__ESP8266
#define REMOTEXY_WIFI__POINT
#define REMOTEXY_PORT__HARDSERIAL
#elif defined(REMOTEXY_MODE__ESP8266_SOFTSERIAL_POINT) || defined(REMOTEXY_MODE__ESP8266POINT_SOFTSERIAL)
#define REMOTEXY_MOD__ESP8266
#define REMOTEXY_WIFI__POINT
#define REMOTEXY_PORT__SOFTSERIAL
#elif defined(REMOTEXY_MODE__ESP8266_HARDSERIAL)
#define REMOTEXY_MOD__ESP8266
#define REMOTEXY_PORT__HARDSERIAL
#elif defined(REMOTEXY_MODE__ESP8266_SOFTSERIAL)
#define REMOTEXY_MOD__ESP8266
#define REMOTEXY_PORT__SOFTSERIAL
#elif defined(REMOTEXY_MODE__ESP8266_HARDSERIAL_CLOUD)
#define REMOTEXY_MOD__ESP8266_CLOUD
#define REMOTEXY_PORT__HARDSERIAL
#define REMOTEXY_CLOUD
#elif defined(REMOTEXY_MODE__ESP8266_SOFTSERIAL_CLOUD)
#define REMOTEXY_MOD__ESP8266_CLOUD
#define REMOTEXY_PORT__SOFTSERIAL
#define REMOTEXY_CLOUD
#elif defined(REMOTEXY_MODE__ETHERNET_LIB) || defined(REMOTEXY_MODE__W5100_SPI)
#define REMOTEXY_MOD__ETHERNET_LIB
#elif defined(REMOTEXY_MODE__ETHERNET_LIB_CLOUD)
#define REMOTEXY_MOD__ETHERNET_LIB_CLOUD
#define REMOTEXY_CLOUD
#elif defined(REMOTEXY_MODE__WIFI_LIB)
#define REMOTEXY_MOD__WIFI_LIB
#elif defined(REMOTEXY_MODE__ESP8266WIFI_LIB_POINT) || defined(REMOTEXY_MODE__ESP8266WIFIPOINT_LIB)
#define REMOTEXY_MOD__ESP8266WIFI_LIB
#define REMOTEXY_WIFI__POINT
#elif defined(REMOTEXY_MODE__ESP8266WIFI_LIB)
#define REMOTEXY_MOD__ESP8266WIFI_LIB
#elif defined(REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD)
#define REMOTEXY_MOD__ESP8266WIFI_LIB_CLOUD
#define REMOTEXY_CLOUD
#elif defined(REMOTEXY_MODE__ESP32_BLE)
#define REMOTEXY_MOD__ESP32_BLE_LIB
#elif defined(REMOTEXY_MODE__NRF_BLE)
#define REMOTEXY_MOD__NRF_BLE_LIB
#elif defined(REMOTEXY_MODE__ESP32WIFI_LIB)
#define REMOTEXY_MOD__ESP8266WIFI_LIB
#elif defined(REMOTEXY_MODE__ESP32WIFI_LIB_POINT) || defined(REMOTEXY_MODE__ESP32WIFIPOINT_LIB)
#define REMOTEXY_MOD__ESP8266WIFI_LIB
#define REMOTEXY_WIFI__POINT
#else
#error RemoteXY mode does not defined or defined error: REMOTEXY_MODE__XXXXXXX
#endif
#include <inttypes.h>
#include "classes/RemoteXY_Lib.h"
/*
#if defined(REMOTEXY_PORT__HARDSERIAL) || defined(REMOTEXY__DEBUGLOGS)
#include <HardwareSerial.h>
#endif
*/
#if defined(REMOTEXY_MOD__SERIAL)
#include "modules/serial.h"
#elif defined(REMOTEXY_MOD__ESP8266)
#include "modules/esp8266.h"
#elif defined(REMOTEXY_MOD__ESP8266_CLOUD)
#include "modules/esp8266_cloud.h"
#elif defined(REMOTEXY_MOD__ETHERNET_LIB)
#include "modules/ethernet.h"
#elif defined(REMOTEXY_MOD__ETHERNET_LIB_CLOUD)
#include "modules/ethernet_cloud.h"
#elif defined(REMOTEXY_MOD__WIFI_LIB)
#include "modules/wifi.h"
#elif defined(REMOTEXY_MOD__ESP8266WIFI_LIB)
#include "modules/esp8266wifi.h"
#elif defined(REMOTEXY_MOD__ESP8266WIFI_LIB_CLOUD)
#include "modules/esp8266wifi_cloud.h"
#elif defined(REMOTEXY_MOD__ESP32_BLE_LIB)
#include "modules/esp32_ble.h"
#elif defined(REMOTEXY_MOD__NRF_BLE_LIB)
#include "modules/nrf_ble.h"
#endif
#ifndef REMOTEXY_ACCESS_PASSWORD
#define REMOTEXY_ACCESS_PASSWORD ""
#endif
CRemoteXY *remotexy;
#define RemoteXY_Handler() remotexy->handler ()
#define RemoteXY_CONF const PROGMEM RemoteXY_CONF_PROGMEM
#endif //_REMOTEXY_H_
RemoteXY_Serial.h
#ifndef _REMOTEXY_SERIAL_H_
#define _REMOTEXY_SERIAL_H_
#include "classes/RemoteXY_API.h"
class CRemoteXY_Serial : public CRemoteXY_API {
public:
#if defined(REMOTEXY_PORT__HARDSERIAL)
HardwareSerial * serial;
void initSerial (HardwareSerial * _serial, long _serialSpeed) {
serial = _serial;
#if defined(REMOTEXY_MODE__BLE_NANO)
Serial.begin (_serialSpeed);
#else
serial->begin (_serialSpeed);
#endif
}
#elif defined(REMOTEXY_PORT__SOFTSERIAL)
#if defined(SoftwareSerial_h)
SoftwareSerial * serial;
void initSerial (uint8_t _serialRx, uint8_t _serialTx, long _serialSpeed) {
serial = new SoftwareSerial (_serialRx, _serialTx);
serial->begin (_serialSpeed);
}
#elif defined(SoftSerial_h)
SoftSerial * serial;
void initSerial (uint8_t _serialRx, uint8_t _serialTx, long _serialSpeed) {
serial = new SoftSerial (_serialRx, _serialTx);
serial->begin (_serialSpeed);
}
#endif
#elif defined(REMOTEXY_PORT__ESP32_BT)
BluetoothSerial * serial;
void initSerial ( const char * _btDeviceName) {
String btDeviceName(_btDeviceName);
serial = new BluetoothSerial ();
serial->begin (btDeviceName);
}
#endif
};
#endif //_REMOTEXY_SERIAL_H_
For serial.h:
#ifndef _REMOTEXY_MOD_SERIAL_H_
#define _REMOTEXY_MOD_SERIAL_H_
#include "classes/RemoteXY_Serial.h"
#ifdef REMOTEXY_PORT__ESP32_BT
#define REMOTEXY_SEND_BUFFER_LENGTH 200
#endif
class CRemoteXY : public CRemoteXY_Serial {
public:
#if defined(REMOTEXY_PORT__HARDSERIAL)
CRemoteXY (const void * _conf, void * _var, const char * _accessPassword, HardwareSerial * _serial, long _serialSpeed) {
initSerial (_serial, _serialSpeed);
init (_conf, _var, _accessPassword);
}
#elif defined(REMOTEXY_PORT__SOFTSERIAL)
CRemoteXY (const void * _conf, void * _var, const char * _accessPassword, uint8_t _serialRx, uint8_t _serialTx, long _serialSpeed) {
initSerial (_serialRx, _serialTx, _serialSpeed);
init (_conf, _var, _accessPassword);
}
#elif defined(REMOTEXY_PORT__ESP32_BT)
CRemoteXY (const void * _conf, void * _var, const char * _accessPassword, const char * _btDeviceName) {
initSerial (_btDeviceName);
init (_conf, _var, _accessPassword);
}
#endif
protected:
#ifdef REMOTEXY_PORT__ESP32_BT
uint8_t sendBuffer[REMOTEXY_SEND_BUFFER_LENGTH];
uint16_t sendBufferCount;
uint16_t sendBytesAvailable;
void sendStart (uint16_t len) {
sendBytesAvailable = len;
sendBufferCount = 0;
}
void sendByte (uint8_t b) {
sendBuffer[sendBufferCount++] = b;
sendBytesAvailable--;
if ((sendBufferCount == REMOTEXY_SEND_BUFFER_LENGTH) || (sendBytesAvailable == 0)) {
uint8_t buf[sendBufferCount];
#if defined(REMOTEXY__DEBUGLOGS)
REMOTEXY__DEBUGLOGS.print("[");
#endif
for (uint16_t i = 0; i < sendBufferCount; i++)
{
buf[i] = sendBuffer[i];
#if defined(REMOTEXY__DEBUGLOGS)
REMOTEXY__DEBUGLOGS.print(" ");
REMOTEXY__DEBUGLOGS.print(buf[i], HEX);
#endif
}
serial->write ((uint8_t *)buf, sendBufferCount);
#if defined(REMOTEXY__DEBUGLOGS)
REMOTEXY__DEBUGLOGS.print(" ] ");
#endif
sendBufferCount = 0;
}
}
#else
void sendByte (uint8_t b) {
#if defined(REMOTEXY_MODE__BLE_NANO)
Serial.write (b);
#else
serial->write (b);
#endif
#if defined(REMOTEXY__DEBUGLOGS)
DEBUGLOGS_writeOutputHex (b);
#endif
}
#endif
uint8_t receiveByte () {
#if defined(REMOTEXY_MODE__BLE_NANO)
uint8_t b = Serial.read ();
#else
uint8_t b = serial->read ();
#endif
#if defined(REMOTEXY__DEBUGLOGS)
DEBUGLOGS_writeInputHex (b);
#endif
return b;
}
uint8_t availableByte () {
#if defined(REMOTEXY_MODE__BLE_NANO)
return Serial.available ();
#else
return serial->available ();
#endif
};
};
#if defined(REMOTEXY_PORT__HARDSERIAL)
#define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, REMOTEXY_ACCESS_PASSWORD, &REMOTEXY_SERIAL, REMOTEXY_SERIAL_SPEED)
#elif defined(REMOTEXY_PORT__SOFTSERIAL)
#define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, REMOTEXY_ACCESS_PASSWORD, REMOTEXY_SERIAL_RX, REMOTEXY_SERIAL_TX, REMOTEXY_SERIAL_SPEED)
#elif defined(REMOTEXY_PORT__ESP32_BT)
#define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, REMOTEXY_ACCESS_PASSWORD, REMOTEXY_BT_DEVICENAME)
#endif
#endif //_REMOTEXY_MOD_SERIAL_H_
And here's my main.cpp:
#include <Arduino.h>
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
//#define REMOTEXY__DEBUGLOGS Serial
// // RemoteXY select connection mode and include library
#define REMOTEXY_MODE__BLE_NANO
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600
// ----------------------------------------------------------------------------
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,1,0,0,0,13,0,11,13,0,
1,0,42,24,12,12,2,31,88,0 };
// this structure defines all the variables and events of your control interface
struct {
// output variables
uint8_t button_1; // =1 if button pressed, else =0
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("INITIALIZING");
RemoteXY_Init ();
}
void loop() {
RemoteXY_Handler ();
// uint8_t bte = 0xA;
// Serial.print(bte);
// put your main code here, to run repeatedly:
}
I've created the REMOTEYX_MODE__BLE_NANO. This solves the issue.
I'll prepare a pull request for you guys.
Thanks everyone again for your help!