Port to different library

I have some code which works fine on a Nordic board - it basically receives some commands via BLE - then displays various symbols on a screen.

I need to port this onto an ESP32-S3 board - BUT - from the example code I've found, the libraries and their commands are different, and I'm struggling to replicate what it's doing.

Any help much appreciated - or even an Example that Receives data and does something with it...I can take it from their.

The original code; (with specifics and display code removed)

#define BLE_DEBUG false

//
// Libraries
#include <SPI.h>
#include <STBLE.h>
#include "BLEtypes.h"
#include <TinyScreen.h>

//
// Used by Arduino - not sure what for
#if defined (ARDUINO_ARCH_AVR)
#define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#endif

//
// BLE Variables 
BLEConn BLEConnection;
BLEServ UARTService;
BLEChar TXchar;
BLEChar RXchar;

#define UARTServiceUUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define UARTRXcharUUID  "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define advertiseName  "mydevice"

//
//Global variables used in the code
unsigned long lastScreenChange = 0;         // Keeps track of millisecond counter (since board reset) so we know when to refresh to Home page 
unsigned long refresh = 5 * 1000;           // Number of milliseconds after which screen will refresh to Home screen (5 * 1000 = 5 seconds)

// Define the space Create a structure that is big enough to contain the 2D array of pixels. 
// The "valid" variable is set to "true" once the structure is filled with actual data for the first time.
bool valid = false;
typedef struct {
  boolean valid;
  char pixels[64][96];                    // px=0-96; py=0-63 when drawing
} Signature;

Signature signature;                 // Create a "Signature" variable and call it "signature"

// Other Variables
char bytein;                    // used to hold Sig byte in
int b1,b2;                      // Values of the 2 halves of the byte coming in
int midimage = 0;               // Flag to use to indicate mid image receiving
int outline = 0;                // Defines what the Outline to the logo should be - 0-none; 1=Green; 2=Red square 
int px = 0;                     // Counters
int py = 0;                     // counters

//
// Initial Setup Function - run once on startup or reset
void setup(void) {
  display.begin();

  SerialMonitorInterface.begin(115200);
  while (!SerialMonitorInterface && millis() < 5000);
  delay(100);
  SerialMonitorInterface.print("Doing setup");
  
  BLEsetup(&BLEConnection, advertiseName, BLEConnect, BLEDisconnect);
  addService(&UARTService, UARTServiceUUID);
  addCharacteristic(&UARTService, &RXchar, UARTRXcharUUID, CHAR_PROP_WRITE_WITHOUT_RESP);
  enableNotifications(&RXchar, RXCharUpdate);
  
  displayHomeScreen();  

  SerialMonitorInterface.print("Done setup"); 
}
//


//
// Main Loop that runs forever or until it resets
void loop() {
  BLEProcess();             //Process any ACI commands or events- main BLE handler.
  handleConnection();        
  
  if (BLEConnection.isConnected) {}

  if (lastScreenChange && (millis()-lastScreenChange > refresh)) {
    displayHomeScreen();
    lastScreenChange = 0;
  }
}
//



// ************** BLE Connection Functions
//
// Connect to BLE 
void BLEConnect() {
  
  SerialMonitorInterface.print("---------Connected to device: ");
  for (int i = 5; i > 0; i--) {
    if (BLEConnection.connectedAddr[i] < 16)SerialMonitorInterface.print('0');
    SerialMonitorInterface.print(BLEConnection.connectedAddr[i], HEX);
    SerialMonitorInterface.print('-');
  }
  if (BLEConnection.connectedAddr[0] < 16)SerialMonitorInterface.print('0');
  SerialMonitorInterface.println(BLEConnection.connectedAddr[0], HEX);
}
//

//
// Handle when ble is connected
bool handleConnection() {
  if (!BLEConnection.isConnected && !BLEConnection.isAdvertising) {
    advertise(advertiseName, UARTServiceUUID);
    SerialMonitorInterface.println("Advertising");
  }
  return false;
}
//

//
// BLE Disconnect
void BLEDisconnect() {
  SerialMonitorInterface.println("---------Disconnected");
}
//
// *********** End of BLE Functions ********* //


//
// ***** Main Event Listener that Receives and processes input data over BLE
void RXCharUpdate(byte * newData, byte length) {
 
    // Message Received 
  if (length>3 && !strncmp ("XXX", (char*)newData, 3)) {
    SerialMonitorInterface.println("VIG Received");
    midimage = 0;                                   // Close off recieving any more image  if we were mid image
    displaySomething();
    return;                                          // Return and wait for another input
  }

 


  // Drop through if we've processed the input OR it's not a recognised block of data
  return;                                          // Return and wait for another input
}
//
// *************End of the Main listener function

// Display 
void displaySomething() {
 // Displays various things
}
//

Is it code that you wrote yourself, or from a 3rd party?

Hi awneil

Most of the logic in it and display stuff is mine. The basic BLE connectivity was from an Arduino example sketch - and it's that part I need to change

The new examples use a different library which seem to do things differently and doesn't give me the same options to process the input data.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.