1 (edited by luiz.villa 2021-05-29 22:54:21)

Topic: Using RemoteXY with Arduino BLE and PlatformIO

Hello everyone,

    I've been trying to use RemoteXY with my Arduino BLE without success. Here is my setup:

- I use this board here Link on AliExpress
- It has a TI CC2540 chip for the bluetooth
- The bluetooth is connected to the port D0 (RX) and D1 (TX) of the Arduino
- My code is available here: https://github.com/luizvilla/remoteXY_BLE_nano

    Currently I can compile and flash it using Visual Studio Code and PlatformIO. When I go to the app, my telephone recognises the BLE device and tries to connect to no avail. Here's what the log says: 


App version 4.7.12, API28
Device Started
BLE connection started
Connecting to BLE device XX:XX:XX:XX:XX
BLE device connected
Receiving GUI configurations
Read timeout error
Receiving GUI confirugration, try 2 ... 
Read CRC error
Receiving GUI confirugration, try 3 ... 
Read timeout error
Receiving GUI confirugration, try 4 ... 
Read CRC error
Board no reply.
Disconnect
BLE device disconnected

And just in case, here's my main.cpp:

#include <Arduino.h>

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__HARDSERIAL

#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,0,0,1,0,30,0,11,13,0,
  66,130,41,26,20,16,2,26,129,0,
  42,21,18,3,17,77,111,116,111,114,
  32,83,112,101,101,100,0 };
  
// this structure defines all the variables and events of your control interface 
struct {

    // output variables
  int8_t pwm_out; // =0..100 level position 

    // 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:
   RemoteXY_Init ();  

  Serial.begin(9600);
  Serial.println("INITIALIZING");
}

void loop() {

  RemoteXY_Handler (); 
  RemoteXY.pwm_out = 10;


  // put your main code here, to run repeatedly:
}

Can anybody give me a hand with this issue? Here's what I suspect:
- The declaration of the Serial as Hardware Serial does not work for the board I'm targeting
- Maybe I need to use some other approach, like ArduinoBLE.h or similar.

Let me know your thoughs and if I'm missing something here.

    Cheers
         Luiz

2 (edited by Gunner 2021-05-28 21:22:02)

Re: Using RemoteXY with Arduino BLE and PlatformIO

Your App can clearly connect to the BLE transceiver, so that part is not the issue.

Your issue is common to what I have seen when using these factory made "combo" boards with various Apps... The connection between the transceiver and the MCU, being proprietary and not always clearly documented, is usually the weak or confusing point to code for.

Everything I can see on the website does indicate it uses Serial (GPIO 0/1) which seems odd for a hardwired connection as that would normally interfere with the USB connection.

Try using Software Serial and adjusting the code for your RX/TX using GPIO 0/1 or 1/0 to see if it is an issue with a lack of the needed cross connect (BLE TX -> MCU RX & BLE RX -> MCU TX)

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL_RX 0 // or try 1
#define REMOTEXY_SERIAL_TX 1  // or try 0
#define REMOTEXY_SERIAL_SPEED 9600
"And voila, which is French for.......'and then I found out.'"

3 (edited by luiz.villa 2021-05-29 19:52:55)

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello Gunner,

        Thank you for your answer. I've tried your idea without success for both cases of the RX and TX (0/1 and 1/0). Here's the code I've used:

 

#include <Arduino.h>

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// // RemoteXY select connection mode and include library 
// #define REMOTEXY_MODE__HARDSERIAL

// #include <RemoteXY.h>

// // RemoteXY connection settings 
// #define REMOTEXY_SERIAL Serial
// #define REMOTEXY_SERIAL_SPEED 9600

#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL_RX 1 // or try 1
#define REMOTEXY_SERIAL_TX 0  // or try 0
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,0,0,1,0,30,0,11,13,0,
  66,130,41,26,20,16,2,26,129,0,
  42,21,18,3,17,77,111,116,111,114,
  32,83,112,101,101,100,0 };
  
// this structure defines all the variables and events of your control interface 
struct {

    // output variables
  int8_t pwm_out; // =0..100 level position 

    // 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:
   RemoteXY_Init ();  

  Serial.begin(9600);
  Serial.println("INITIALIZING");
}

void loop() {

  RemoteXY_Handler (); 
  RemoteXY.pwm_out = 10;


  // put your main code here, to run repeatedly:
}

        Looking at the manufacture's datasheet, I see they provide a dirver for their chip, but only for Windows. Here's their repository https://github.com/keywish/keywish-nano … 467743i98O

        Any other ideas?

Thanks a lot
    Luiz

4

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello,

To keep providing some clues, here's the compilation of my original code:

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328new; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (3.3.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr 5.1.0 
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 10 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <RemoteXY> 0.0.0+20210528173046.sha.f5a26d1
|   |-- <ArduinoBLE> 1.2.1
|   |-- <BLEPeripheral> 0.4.0
|   |   |-- <SPI> 1.0
|-- <HardwareBLESerial> 1.0.0
|   |-- <ArduinoBLE> 1.2.1
|-- <BLEPeripheral> 0.4.0
|   |-- <SPI> 1.0
|-- <ArduinoBLE> 1.2.1
Building in release mode
Compiling .pio/build/nanoatmega328/src/main.cpp.o
In file included from .pio/libdeps/nanoatmega328/RemoteXY/classes/RemoteXY_Serial.h:4:0,
                 from .pio/libdeps/nanoatmega328/RemoteXY/modules/serial.h:4,
                 from .pio/libdeps/nanoatmega328/RemoteXY/RemoteXY.h:160,
                 from src/main.cpp:72:
.pio/libdeps/nanoatmega328/RemoteXY/classes/RemoteXY_API.h: In member function 'void CRemoteXY_API::init(const void*, void*, const char*)':
.pio/libdeps/nanoatmega328/RemoteXY/classes/RemoteXY_API.h:60:14: warning: unused variable 'ms' [-Wunused-variable]
     uint32_t ms;
              ^~
.pio/libdeps/nanoatmega328/RemoteXY/classes/RemoteXY_API.h: In member function 'void CRemoteXY_API::handler()':
.pio/libdeps/nanoatmega328/RemoteXY/classes/RemoteXY_API.h:132:18: warning: unused variable 'kp' [-Wunused-variable]
     uint8_t *p, *kp;
                  ^~
Linking .pio/build/nanoatmega328/firmware.elf
Checking size .pio/build/nanoatmega328/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.3% (used 232 bytes from 2048 bytes)
Flash: [=         ]  13.4% (used 4120 bytes from 30720 bytes)
======================================================================================================================= [SUCCESS] Took 0.81 seconds =======================================================================================================================

It gives away some warnings, but otherwise it compiles.

5 (edited by luiz.villa 2021-05-29 21:29:56)

Re: Using RemoteXY with Arduino BLE and PlatformIO

Another try on my side, I've included :

#define REMOTEXY__DEBUGLOGS Serial

Which gives me the following logs:

[ 0.000] RemoteXY started
[    1.235] <- 55 06 00 00 F1 E9
[    1.243] -> 55 24 00 00 0B 0D 00 42 82 29 1A 14 10 02 1A 81
               00 2A 15 12 03 11 4D 6F 74 6F 72 20 53 70 65 65
               64 00 E7 E4
[    2.589] <- 55 06 00 00 F1 E9
[    2.596] -> 55 24 00 00 0B 0D 00 42 82 29 1A 14 10 02 1A 81
               00 2A 15 12 03 11 4D 6F 74 6F 72 20 53 70 65 65
               64 00 E7 E4
[    3.988] <- 04 00 00 FC 55 06 00 00 F1 E9
[    9.105] -> 55 24 00 00 0B 0D 00 42 82 29 1A 14 10 02 1A 81
               00 2A 15 12 03 11 4D 6F 74 6F 72 20 53 70 65 65
               64 00 E7 E4

I don't know how to interpret them. But if anyone does and this helps, here it is.

As a recall, here's the configuration table :

uint8_t RemoteXY_CONF[] =
  { 255,0,0,1,0,30,0,11,13,0,
  66,130,41,26,20,16,2,26,129,0,
  42,21,18,3,17,77,111,116,111,114,
  32,83,112,101,101,100,0 };

For confirmation: I'm using the SoftSerial with RX = 0 and TX = 1

6 (edited by luiz.villa 2021-05-29 22:01:08)

Re: Using RemoteXY with Arduino BLE and PlatformIO

I've tried something else to try to understand the remoteXY message. I've used the following configuration:

uint8_t RemoteXY_CONF[] =
  { 255,1,0,0,0,13,0,11,13,0,
  1,0,42,24,12,12,2,31,88,0 }; 

Which is the configuration for a simple button.
Here's the message that was exchanged:

[    8.236] <- 55 06 00 00 F1 E9
[    8.243] -> 55 13 00 00 0B 0D 00 01 00 2A 18 0C 0C 02 1F 58
               00 B5 85
[   21.266] <- 55 06 00 00 F1 E9
[   21.273] -> 55 13 00 00 0B 0D 00 01 00 2A 18 0C 0C 02 1F 58
               00 B5 85
[   22.529] <- 55 06 00 00 F1 E9
[   22.536] -> 55 13 00 00 0B 0D 00 01 00 2A 18 0C 0C 02 1F 58
               00 B5 85
[   23.702] <- 04 00 00 FC 55 06 00 00 F1 E9
[   28.808] -> 55 13 00 00 0B 0D 00 01 00 2A 18 0C 0C 02 1F 58
               00 B5 85

By simple comparison I deduce the second number after the 55 is the length of the message.

In the previous case, it was 24, which is 16*2+4 for hex, giving 36. If all characters of the message are counted (including the 55) it should work.
In the case in this message, the number is 13, which is 16*1+3 for hex, giving 19. Again, if all the characters of the message are counted, including the 55, it should work. 

Reading more into the message, I've realized that the answer from the device corresponds exactly with the confirguration that was given with a few extra characters:

         55 13 00 00 0B 0D 00 01 00 2A 18 0C 0C 02 1F 58 00 B5 85
                  -----------------------------------------
255,1,0,0,0,13,   00,11,13,00,01,00,42,24,12,12,02,31,88,00

In close inspection it seems the Arduino is sending back the whole configuration to the cell phone. Why is this not working? Is the app on the phone expecting a stop message hex that never arrives? Does my code lack something?

7 (edited by Gunner 2021-05-29 22:09:49)

Re: Using RemoteXY with Arduino BLE and PlatformIO

First off, I use the Arduino IDE and have no experience with PlatformIO.  So can't help there is that was part of the issue... but I still don't think so.

BTW, this is my first time discovering the debug option... no documentation that I can find and not too much availed about it via forum search.  So I too am unable to decipher it.

However, the fact that you can run the debug, and see results, tells me that your are fully engaging the Serial port via the USB... Thus there should be NO way for the BLE module to also use it simultaneously... hence, no worky smile

Silly thought here... have you tried testing WITHOUT having the Nano/BLE plugged into the USB, or at least running off a USB powerbank?  Perhaps there is some form of internal switching between Serial and USB/BLE based on detection of USB Serial use.

"And voila, which is French for.......'and then I found out.'"

8 (edited by luiz.villa 2021-05-29 22:11:07)

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello Gunner,

    Thanks again for the reply. I haven't tried communicating with it while connected to a powerbank. However I don't think that may be the issue. It is clear from the messages the that the app on the phone asks for the configuration of the BLE and the configuration is correctly sent to the phone. This means they are talking to each other correctly.
     I have also done the test recommended by the manufacturer using the LightBlue app, and I manage to send data to the Serial port while displaying it on the Serial Monitor.
      My feeling is that the issue is somewhere else. The data exchange seems to be working fine, but maybe something is missing from the code.

       Luiz

9 (edited by Gunner 2021-05-29 22:22:51)

Re: Using RemoteXY with Arduino BLE and PlatformIO

Another wacky idea.  Try with just a simple label element... something that needs to be sent to the phone, but has NO communication needs with the MCU once there.

I suspect that the whole proprietary merger of this product is what is making it so complicated.  I have seen this before with other apps (most notably to me, Blynk) and other non-official (and some official if new to market) Arduino/WiFi/BT/BLE all-in ones. 

One thing about open source standards is that everyone has their own tongue

"And voila, which is French for.......'and then I found out.'"

10

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello Gunner,

       Thanks, I'll try something simple as you said.
       In the meanwhile, here's what I think the issue may be at:

 void sendPackage (uint8_t command, uint8_t *p, uint16_t length, uint8_t itConf) {
    uint16_t crc = initCRC ();
    uint16_t packageLength = length+6;
    sendStart (packageLength);
    sendByteUpdateCRC (REMOTEXY_PACKAGE_START_BYTE, &crc);
    sendByteUpdateCRC (packageLength, &crc);
    sendByteUpdateCRC (packageLength>>8, &crc);
    sendByteUpdateCRC (command, &crc);  
    uint8_t b;
    while (length--) {
      if (itConf) b=getConfByte (p++);
      else b=*p++;
      sendByteUpdateCRC (b, &crc);
    }
    sendByte (crc);  
    sendByte (crc>>8);
  }

void sendByteUpdateCRC (uint8_t b, uint16_t *crc) {
    sendByte (b); 
    updateCRC (crc, b);
  }  

void updateCRC (uint16_t *crc, uint8_t b) {
    *crc ^= b;
    for (uint8_t i=0; i<8; ++i) {
      if ((*crc) & 1) *crc = ((*crc) >> 1) ^ 0xA001;
      else *crc >>= 1;
    }
  } 

     Above is the code for the sending bytes. This is called with the configuration as the command. The issue may be at the end, on the calculation of b and the update of crc. I still have not tried to really understand the calculation going on here, but if there is an issue it should be on these functions. I think they are returning a value that is not expected by the app on the phone.

11 (edited by Gunner 2021-05-29 22:49:40)

Re: Using RemoteXY with Arduino BLE and PlatformIO

Well, you are digging into the library more then I have the current mindset for, so I think you are already well ahead on the diagnosis.  But my theory about the strangeness of how your new Nano/BLE MCU handles both USB and the add-on BLE on the same Serial (1/0) pins may very well be causing CRC issues.

After testing (and generally discarding over time) a few "unique" new MCUs (C.H.I.P, Light Blue Bean, and once a generic Nano/BLE combo from years back but it used dedicated pins), I basically stick with "tried and true" now for when I need an IoT MCU.  I like learning and diagnosing new stuff... but not when it becomes "head banging work" smile

BTW, ESP32 is cheap and works well with BLE and/or WiFi (haven't tried USB yet) and RemoteXY

"And voila, which is French for.......'and then I found out.'"

12

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello Gunner,

     I've just tried your idea. I've powered the Nano-BLE with a battery and tried to connect to it. Still the same issue. I suppose it is not the Serial interfering with the system. I suppose this requires an answer from the developers. But thanks for your support.

13

Re: Using RemoteXY with Arduino BLE and PlatformIO

Yes... it is unique-nuf that proper library support may be needed.  The question is, is it a widespread enough device to justify their efforts?  Only they can say.

I will keep watching and hope something works out.

"And voila, which is French for.......'and then I found out.'"

14 (edited by Gunner 2021-05-29 23:04:42)

Re: Using RemoteXY with Arduino BLE and PlatformIO

OK, one final idea... Try another model phone/tablet that supports BLE, if possible. 

Reason I say, is that my last project I posted here only works (using ESP32 BLE) with my daily driver phone.  When I try to use my "App Project" phone, it connects, but gives a timeout error when trying to load the GUI.  Ergo, it is the phone (particularly its compatibility with some BLE devices) and not the MCU, Library, etc. in my case

"And voila, which is French for.......'and then I found out.'"

15

Re: Using RemoteXY with Arduino BLE and PlatformIO

I was thinking exactly the same. I'll try to hunt the house for another phone. I actually only have one. tongue

16 (edited by luiz.villa 2021-05-30 01:21:29)

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello,

    I've tried another phone, but since it is the same model it is not conclusive as a test.
    However, since I ran out of options, I did try one last thing. I used the LightBlue app to communicate with the device and I sent to the device exactly the same message the remoteXY app does:

55 06 00 00 F1 E9

Here's the result from the log of the LightBlue:

Sun May 30 01:25:37 GMT+02:00 2021: Writing to characteristic 0000ffe1-0000-1000-8000-00805f9b34fb: 55 06 00 00 F1 E9

Sun May 30 01:25:37 GMT+02:00 2021: Wrote to characteristic 0000ffe1-0000-1000-8000-00805f9b34fb | value: 55 06 00 00 F1 E9

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 0D 0A 5B 20 20 32 31 38 2E 37 32 39 5D 20 3C 2D 20 35 35 20

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 36 20 30 30 20 30 30 20 46 31 20 45 39 0D 0A 5B 20 20 32 31

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 2E 37 33 36 5D 20 2D 3E 20 35 35 20 31 33 20 30 30 20 30 30

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 30 42 20 30 44 20 30 30 20 30 31 20 30 30 20 32 41 20 31 38

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 30 43 20 30 43 20 30 32 20 31 46 20 35 38 0D 0A 20 20 20 20

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 20 20 20 20 20 20 20 20 20 20 30 30 20 42 35 20 38 35

So this got me thinking... as long as the debug is on, all I'm receiving is the actual debug data rather than the sent data.

So, I turned off the debug and watched what is written on the serial using the app and the serial monitor. It seems that for some reason the send byte routines do not address the appropriate serial. Nothing is written to the hard serial unless the Serial.print() function is explicitly used.
Maybe this is a conflict due to the fact that everything is on the same Serial?

Either way, this should be visible using the hardware serial option. Still, nothing gets written on the serial port. The code does read it fine though. It just does not write to it correctly.

17 (edited by Gunner 2021-05-30 05:09:32)

Re: Using RemoteXY with Arduino BLE and PlatformIO

luiz.villa wrote:

Maybe this is a conflict due to the fact that everything is on the same Serial?

Not sure if I can explain this as it is in my head... but Serial is simply sending (TX) data to a receiver (RX)... twice... one in the opposite direction of the other.  Thus it is possible that with two competing signals sharing the same pair of TX/RX lines that depending on what is speaking vs listening, you could have a clear signal on one pair (direction) when only one device is transmitting at the time, but a garbled up signal if both devices are transmitting

Think two people talking on one end of a phone link and one person on the other end.  The two will always understand the one, but the one may have confusion when listening if the two talk at the same time... especially if the two are each talking about different topics.

Try removing any and all Serial code in your sketch, including debug, and try again.  This should eliminate any Serial data coming from the sketch, except what the library is sending.

  Serial.begin(9600);
  Serial.println("INITIALIZING");
"And voila, which is French for.......'and then I found out.'"

18

Re: Using RemoteXY with Arduino BLE and PlatformIO

1. If you have chosen a Serial for RemoteXY then you should not use it anywhere else.
Remove any Serial from your code.

2. We have not tested this board. Unfortunately I cannot give you a working example.

3. It's just as bad to put the DEBUGLOG tracker on the same port where the RemoteXY works.

19

Re: Using RemoteXY with Arduino BLE and PlatformIO

luiz.villa wrote:
 void sendPackage (uint8_t command, uint8_t *p, uint16_t length, uint8_t itConf) {
    uint16_t crc = initCRC ();
    uint16_t packageLength = length+6;
    sendStart (packageLength);
    sendByteUpdateCRC (REMOTEXY_PACKAGE_START_BYTE, &crc);
    sendByteUpdateCRC (packageLength, &crc);
    sendByteUpdateCRC (packageLength>>8, &crc);
    sendByteUpdateCRC (command, &crc);  
    uint8_t b;
    while (length--) {
      if (itConf) b=getConfByte (p++);
      else b=*p++;
      sendByteUpdateCRC (b, &crc);
    }
    sendByte (crc);  
    sendByte (crc>>8);
  }

void sendByteUpdateCRC (uint8_t b, uint16_t *crc) {
    sendByte (b); 
    updateCRC (crc, b);
  }  

void updateCRC (uint16_t *crc, uint8_t b) {
    *crc ^= b;
    for (uint8_t i=0; i<8; ++i) {
      if ((*crc) & 1) *crc = ((*crc) >> 1) ^ 0xA001;
      else *crc >>= 1;
    }
  } 

     Above is the code for the sending bytes. This is called with the configuration as the command. The issue may be at the end, on the calculation of b and the update of crc. I still have not tried to really understand the calculation going on here, but if there is an issue it should be on these functions. I think they are returning a value that is not expected by the app on the phone.

This code always works for any board. It works. The problem is not here.

20

Re: Using RemoteXY with Arduino BLE and PlatformIO

luiz.villa wrote:

Hello,

    I've tried another phone, but since it is the same model it is not conclusive as a test.
    However, since I ran out of options, I did try one last thing. I used the LightBlue app to communicate with the device and I sent to the device exactly the same message the remoteXY app does:

55 06 00 00 F1 E9

Here's the result from the log of the LightBlue:

Sun May 30 01:25:37 GMT+02:00 2021: Writing to characteristic 0000ffe1-0000-1000-8000-00805f9b34fb: 55 06 00 00 F1 E9

Sun May 30 01:25:37 GMT+02:00 2021: Wrote to characteristic 0000ffe1-0000-1000-8000-00805f9b34fb | value: 55 06 00 00 F1 E9

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 0D 0A 5B 20 20 32 31 38 2E 37 32 39 5D 20 3C 2D 20 35 35 20

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 36 20 30 30 20 30 30 20 46 31 20 45 39 0D 0A 5B 20 20 32 31

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 2E 37 33 36 5D 20 2D 3E 20 35 35 20 31 33 20 30 30 20 30 30

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 30 42 20 30 44 20 30 30 20 30 31 20 30 30 20 32 41 20 31 38

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 30 43 20 30 43 20 30 32 20 31 46 20 35 38 0D 0A 20 20 20 20

Sun May 30 01:25:37 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 20 20 20 20 20 20 20 20 20 20 30 30 20 42 35 20 38 35

So this got me thinking... as long as the debug is on, all I'm receiving is the actual debug data rather than the sent data.

So, I turned off the debug and watched what is written on the serial using the app and the serial monitor. It seems that for some reason the send byte routines do not address the appropriate serial. Nothing is written to the hard serial unless the Serial.print() function is explicitly used.
Maybe this is a conflict due to the fact that everything is on the same Serial?

Either way, this should be visible using the hardware serial option. Still, nothing gets written on the serial port. The code does read it fine though. It just does not write to it correctly.

It is very interesting. Yes, for some reason the log is written, but the data from the RemoteXY is not written to this port.
Yes, you have to remove debug log to Serial port.
To write to the port, the library file RemoteXYStream_HardSerial.h is used.
try changing this file:

#ifndef RemoteXYStream_HardSerial_h
#define RemoteXYStream_HardSerial_h

#include "RemoteXYStream.h"


class CRemoteXYStream_HardSerial : public CRemoteXYStream {
  
  private:
  HardwareSerial * serial;
  
  public:
  CRemoteXYStream_HardSerial (HardwareSerial * _serial, long _serialSpeed) : CRemoteXYStream () {
    serial = _serial;
    //serial->begin (_serialSpeed);   //   <---------------------------------
    Serial.begin (_serialSpeed);       //   <+++++++++++++++++++++
#if defined(REMOTEXY__DEBUGLOG)
    RemoteXYDebugLog.write("Init hardware serial ");
    RemoteXYDebugLog.writeAdd(_serialSpeed);
    RemoteXYDebugLog.writeAdd(" baud");
#endif
  }              
  
  void handler () override {   
    //while (serial->available ()) notifyReadByteListener (serial->read ());   //   <---------------------------------
    while (Serial.available ()) notifyReadByteListener (Serial.read ());   //   <++++++++++++++++++++
  }

  void write (uint8_t byte) override {
    //serial->write (byte);  //   <---------------------------------
    Serial.write (byte);   //   <++++++++++++++++++++
  }
  
};

#endif //RemoteXYStream_HardSerial_h

21

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello remoteXY team,

      Thank you so much for your update. I've just implemented your changes. However I do not have the RemoteXYStream_HardwareSerial.h file. I had to manually change RemoteXY_Serial.h and serial.h.

Here's my code for 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;                            //<+++++++++++++
    // serial->begin (_serialSpeed); //<------------------------
    Serial.begin (_serialSpeed);
  }
#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_



Here is my code 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) {
      // serial->write (b); <-----------------------
      Serial.write (b);   <+++++++++++++++
#if defined(REMOTEXY__DEBUGLOGS)
    DEBUGLOGS_writeOutputHex (b);
#endif
    }
#endif

    uint8_t receiveByte () {
      // uint8_t b = serial->read (); <--------------------
      uint8_t b = Serial.read (); <+++++++++++++
#if defined(REMOTEXY__DEBUGLOGS)
    DEBUGLOGS_writeInputHex (b); 
#endif
      return b;
    }


    uint8_t availableByte () {
      // return serial->available (); <--------------
      return Serial.available ();  <+++++++++
    };


};


#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_

Here's the result form the communication log of the LIghtBlue app:

Sun May 30 13:14:57 GMT+02:00 2021: Writing to characteristic 0000ffe1-0000-1000-8000-00805f9b34fb: 55 06 00 00 F1 E9

Sun May 30 13:14:57 GMT+02:00 2021: Wrote to characteristic 0000ffe1-0000-1000-8000-00805f9b34fb | value: 55 06 00 00 F1 E9

Sun May 30 13:14:57 GMT+02:00 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 55 13 00 00 0B 0D 00 01 00 2A 18 0C 0C 02 1F 58 00 B5 85

As a recall, here's wath the debugger would give me :

[   23.702] <- 04 00 00 FC 55 06 00 00 F1 E9
[   28.808] -> 55 13 00 00 0B 0D 00 01 00 2A 18 0C 0C 02 1F 58
               00 B5 85

So, now, the answer is spot on!

Now comes the drums ........................

.
..
.
.
.
.
.
.
.



And it works!
I can actually get the interface for a button working!

Thank you a lot!

22 (edited by luiz.villa 2021-05-30 12:02:02)

Re: Using RemoteXY with Arduino BLE and PlatformIO

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!

23

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello everyone,

   I've made a pull request of these changes onto the ofificial RemoteXY Arduino library. Here's the link to the pull request:

https://github.com/RemoteXY/RemoteXY-Ar … ry/pull/10

     Thanks everyone for this. Hope this can help other people as well.

Cheers
Luiz

24

Re: Using RemoteXY with Arduino BLE and PlatformIO

Hello again,

      I've played around a little bit with the code. I do get it to work, but I need to try 5 to 10 times in average to connect to the Nano BLE device. I'm going to try this out with other devices to see if it is a glitch or not. The errors it receives are basically the same timeout, CRC and timeout. If you integrate support for this board into your code, maybe you have to give it a little more time for the timeout. I will let you know how this goes as I run some tests.

    Cheers
     Luiz

25 (edited by Gunner 2021-05-30 19:54:39)

Re: Using RemoteXY with Arduino BLE and PlatformIO

luiz.villa wrote:

I do get it to work, but I need to try 5 to 10 times in average to connect to the Nano BLE device

Perhaps because you are still doing this "bad thing" over a shared Serial connection smile

luiz.villa wrote:

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  Serial.println("INITIALIZING");

  RemoteXY_Init (); 

}

I didn't follow the changes you did in the library... admittedly due to TL:DR  My bad.

However, there are some indisputable facts going on here...

- Your MCU shares the same Serial pins as the USB link. 

- And then you enable the Serial functionality, followed by the string "INITIALIZING" that also communicates that data across those same Serial Pins

- Therefore, both the USB (to your IDE Serial monitor) and the BLE module (to the App) are transmitting that string of data.  And if that happens at the same time as the library is doing it's thing in the background (transmitting GUI data and whatnot) over the same Serial link to the App... well, then glitches happen, timeouts occur, etc.

"Fixing" a library "issue" so it may sometimes allow bad coding to get away with something (assuming that is what you did, again TL:DR) is not what I would recommend, when the simple rule of "Don't use the same Serial channel for more than one thing at a time" has always been around as long as Serial communication has.

But that is just my two bits tongue

"And voila, which is French for.......'and then I found out.'"