RemoteXY / RemoteXY-Arduino-library

RemoteXY library for Arduino IDE
http://remotexy.com
GNU Lesser General Public License v2.1
48 stars 19 forks source link

Library not working with BLE-Nano over PlatformIO #9

Open luizvilla opened 3 years ago

luizvilla commented 3 years ago
  Hello everyone, 

 I'm trying to use RemoteXY with PlatformIO to talk to an Arduino Nano BLE. Here are some details of my implementation: 

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

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__DEBUGLOGS Serial

// -----------------------SUGGESTED CODE FROM REMOTEXY FORUM -------------------------
#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
// ----------------------------------------------------------------------------

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

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

void loop() {

  RemoteXY_Handler (); 

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

I've dug deeper and found out that this is what happens when I turn the debug mode on as you can see from the first line. Here are the hex characters shown at the Serial port by the debug.

[    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 doing some reverse engineering, it seems to me that the data sent by the device to the phone is on the good format. At least from the serial port perspective.

I've used the LightBlue app to talk to the Nano-BLE and I've sent the device the same message that the app does. Here's what I've received as it was caught by the LightBlue app.

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

I'm using a Redmi Note 6 Pro phone with a 12.0.1 Stable MIUI version, a 9 pkq1.180904.001 Android version.

Here's my guess: The message being sent from the device to the phone is not coming through as expected. I have tried using another phone, but since it is the same model I still have to confirm it is not the phone.

Apart from that, I have no idea what can be the issue.

Any ideas?

Cheers
     Luiz
luizvilla commented 3 years ago

Small update:

When I turn the debug off, the Serial goes quiet. I verified that the BLE device receives data and it does since the code enters the right function to treat the request and send out the configuration. When I monitor the BLE using another app, I only see data when it is written using the Serial.print() function.