Sorry, haven’t mentioned. You need to install latest Totem Boards version.
All is working now. Thanks for your help
Regards, Gerard
What is the meaning of the X11 thru X77 in the sketches???
Regards Gerard
It’s just a 32-bit message ID. You can use any value you want. On “commandValue” events it’s received as “cmd” parameter. 0x11
- 0x77
is accidental values I selected for example code.
E.g.: calling TotemApp.sendValue(0x55, 1000)
will return in callback bool commandValueEvent(int cmd, int value)
as cmd = 0x55
, value = 1000
.
There are some reserved “cmd” values like: 0x1349f298
, 0x1649f751
, 0x1549f5be
, 0x1849fa77
(means functionA
-functionD
). But you can ignore them and send anything you like, especially if return false
is called (command won’t be passed down further to RoboBoard firmware).
Hey! Totem Boards and Totem Library got new release.
Remote communication code has changed once again.
RoboBoard X4:
void appEvent(int evt, int value) {
if (evt == TotemApp.evtConnect) { Serial.println("Remote ESP connected\n"); }
if (evt == TotemApp.evtDisconnect) { Serial.println("Remote ESP disconnected\n"); }
}
// Intercept value sent by sendValue() (from Totem Library)
void onReceiveValue(int id, int value) {
// Print received value
Serial.printf("Got ID: %d, value: %d from ESP\n", id, value);
}
// Intercept string sent by sendString() (from Totem Library)
void onReceiveString(int id, String string) {
// Print received string
Serial.printf("Got ID: %d, string: '%s' from ESP\n", id, string.c_str());
}
void setup() {
Serial.begin(115200);
// Register connection events
TotemApp.addEvent(appEvent);
// Register receive value handlers
TotemApp.addOnSend(onReceiveValue);
TotemApp.addOnSend(onReceiveString);
}
void loop() {
// Send ID: 10, value: 1000 to ESP32
TotemApp.sendValue(10, 1000);
// Send ID: 11, string: "Hello from X4" to ESP32
TotemApp.sendString(11, String("Hello from X4"));
// BUG: wrap message in String() object. Otherwise result will be empty.
delay(1000);
}
ESP32:
#include <TotemRoboBoardX4.h>
// RoboBoard X4 remote control
TotemRoboBoardX4 roboboard;
// Detect connection state change
void onConnectionChange() {
if (roboboard.isConnected()) Serial.println("Connection state: Connected");
else Serial.println("Connection state: Disconnected");
}
// Intercept value sent by TotemApp.sendValue() (from RoboBoard)
void onReceiveValue(int id, int value) {
// Print received value
Serial.printf("Got ID: %d, value: %d from X4\n", id, value);
}
// Intercept string sent by TotemApp.sendString() (from RoboBoard)
void onReceiveString(int id, String string) {
// Print received string
Serial.printf("Got ID: %d, string: '%s' from X4\n", id, string.c_str());
}
// Arduino setup function.
void setup() {
Serial.begin(115200);
// Register connection state event
roboboard.addOnConnectionChange(onConnectionChange);
// Register value receive functions
roboboard.addOnReceive(onReceiveValue);
roboboard.addOnReceive(onReceiveString);
// Connect remotely over Bluetooth
Serial.println("Searching RoboBoard X4...");
roboboard.connect();
// Print connected board name
Serial.printf("Name: %s\n", roboboard.getName().c_str());
}
// Arduino loop function
void loop() {
// Send ID: 0, value: 55 to RoboBoard
roboboard.sendValue(0, 55);
// Send ID: 1, string: "Hello from ESP" to RoboBoard
roboboard.sendString(1, "Hello from ESP");
delay(1000);
}
New update brings:
- Clean and simple API for remote board control
- Each board has C++ functions for available remote features
- Use any (32-bit) “ID” value you want for user data
- Implemented remote read functionality
See documentation for more information:
https://docs.totemmaker.net/modules/ble/
https://docs.totemmaker.net/roboboard/api/totemapp/#totem-library