Ive been using BLE across several particle platforms ( P2, Boron, Tracker and Monitor One) with great success scanning for and relaying data to my back end.
However the Muron seems to have a issue with BLE.
This code for example, causes a crash/fault after running breifly but runs perfectly on Tracker and Monitor One platforms.
I have disabled the wifi to prevent wifi and BLE fighting over the same antenna.
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler(LOG_LEVEL_TRACE);
void scanForDevices();
void discoverServicesAndCharacteristics(BlePeerDevice &peerDevice);
const std::chrono::milliseconds scanInterval = 30s;
unsigned long scanLastMillis = 0;
void setup()
{
WiFi.off();
Cellular.prefer();
BLE.on(); // Turn on BLE
BLE.setScanTimeout(5000); // Set scan timeout to 5 seconds
}
void loop()
{
if (millis() - scanLastMillis >= scanInterval.count()) {
scanLastMillis = millis();
Log.info("Starting BLE scan...");
scanForDevices(); // Scan for BLE devices
}
}
// Function to scan for nearby BLE devices
void scanForDevices()
{
BleScanResult scanResults[20]; // Array to hold scan results
int foundDevices = BLE.scan(scanResults, 20); // Scan for up to 20 devices
if (foundDevices > 0)
{
Log.info("Found %d devices", foundDevices);
for (int i = 0; i < foundDevices; i++)
{
BleAddress address = scanResults[i].address();
Log.info("Device %d: %s", i + 1, address.toString().c_str());
// Try connecting to the device
BlePeerDevice peerDevice = BLE.connect(scanResults[i].address());
if (peerDevice.connected())
{
Log.info("Connected to device %d", i + 1);
// Discover all services and characteristics
discoverServicesAndCharacteristics(peerDevice);
// Disconnect after discovering the services and characteristics
peerDevice.disconnect();
Log.info("Disconnected from device %d", i + 1);
}
else
{
Log.error("Failed to connect to device %d", i + 1);
}
}
}
else
{
Log.error("No BLE devices found");
}
}
// Function to discover services and characteristics of a connected BLE device
void discoverServicesAndCharacteristics(BlePeerDevice &peerDevice)
{
// Loop through all discovered services
for (BleService &service : peerDevice.services())
{
BleUuid serviceUUID = service.UUID();
Log.info("Service UUID: %s", serviceUUID.toString().c_str());
Vector<BleCharacteristic> characteristics = peerDevice.discoverAllCharacteristics();
// Loop through all characteristics in this service
for (BleCharacteristic &characteristic : characteristics)
{
BleUuid characteristicUUID = characteristic.UUID();
Log.info(" Characteristic UUID: %s", characteristicUUID.toString().c_str());
}
}
}
Have you isolated which part is causing the SOS? For example comment out the whole if (foundDeviuces > 0)
block, and so on to narrow down where the issue may be? Or maybe start from the bottom with commenting out the call to discoverServicesAndCharacteristics first and see if the code runs.
Do you get any log messages before the SOS?
Does this code work on the P2? The Boron, Tracker, and Monitor One have a completely different MCU with a different BLE stack. The P2 and M-SoM/Muon have very similar Realtel RTL872x MCUs so it would be a little unusual for it to SOS on the M-SoM and not the P2/Photon 2.
1 Like
Rick
Didnt try this on P2 as it doesnt support Code PHY but can set it to BLE_PHYS_1MBPS and try it.
Tracker and Montior One its ok.
I have commented out the discoverServices code and it still crashed
There are no messages before it crashes.
S
The M-SoM/Muon don't support Coded PHY either.
I'd also try commenting out the connect block and see if it's the scanning or connecting that's crashing.
Also which version of Device OS are you running?
P2 runs ok, just misses all the Coded PHY devices ( as expected)
commented out connect and discover blocks , still crashes
Muron is running 6.3.2
Hey @magchecks can you provide a photo of how you are powering the Muon and have the antennas configured?
Can you also confirm the Muon's version number via the top side silkscreen?
1 Like
Also, are you actually getting a SOS panic code? Which one?
Or does the device just reset? What was the status LED state before reset or SOS?
Does the problem also occur if you use SYSTEM_MODE(SEMI_AUTOMATIC) and not connect to cellular?
And you said there were no log messages on serial at all? Not even in the 30 seconds before the first BLE scan?
Rick
the Semi_Automatic version seems to have helped. its been running fro a few minutes( far longer than before) ...
This prior to BLE Scan":
Connected to USB serial
0000001237 [hal] INFO: WiFi on
0000001276 [hal.ble] TRACE: Going to stop the stack...
0000001598 [hal] INFO: WiFi off
0000001608 [system.nm] INFO: State changed: NONE -> DISABLED
0000001624 [system.nm] TRACE: Interface 5 power state: DOWN
0000001640 [system.nm] TRACE: Interface 4 power state: UP
0000001676 [comm] INFO: channel inited
0000001688 [system.nm] TRACE: Request to power off interface 5
0000001711 [hal] INFO: rltk_wlan_set_netif_info: 0, 94:94:4a:07:4c:1c
0000001862 [hal] INFO: WiFi on
0000002017 [sys.power] INFO: Enable auxiliary power
0000002264 [system.nm] TRACE: Interface 3 power state changed: UP
Battery is connected and fully charged.
Powering for a desktop supply 12VDC @ 1.5A
Rick, Still resetting afer a few minutes.
Dispite setting while in SEMI_AUTOMATIC:
WiFi.prefer(false);
WiFi.off();
log shows Wifi turning back on at the beginning of every BLE scan
0000165967 [hal] INFO: WiFi off
0000165976 [app] INFO: BLE Off
0000166985 [app] INFO: Starting BLE scan...
0000167006 [hal] INFO: rltk_wlan_set_netif_info: 0, 94:94:4a:07:4c:1c
0000167156 [hal] INFO: WiFi on
0000217504 [app] INFO: Found 38 devices
0000217516 [app] INFO: Device 1: 15:39:35:66:3B:0F
0000217530 [app] INFO: Device 2: 6B:84:1D:6E:5D:03
0000217545 [app] INFO: Device 3: 11:67:DB:A4:16:44
0000217559 [app] INFO: Device 4: 1D:62:49:7F:60:D9
0000217573 [app] INFO: Device 5: 38:33:4C:14:75:C0
0000217587 [app] INFO: Device 6: 0E:EE:A1:30:4C:26
0000217601 [app] INFO: Device 7: 64:D4:5B:E2:08:79
0000217615 [app] INFO: Advertising name: P MAG C0424C
0000217630 [app] INFO: Device 8: ED:9A:80:39:86:16
0000217644 [app] INFO: Device 9: 56:49:6F:F7:88:7A
0000217659 [app] INFO: Advertising name: gst-010003617304
0000217674 [app] INFO: Device 10: E2:11:BA:8A:18:41
0000217689 [app] INFO: Advertising name: DM1198501
0000217703 [app] INFO: Device 11: 60:EF:AB:F7:DF:65
0000217717 [app] INFO: Advertising name: P DI 0020B8
0000217732 [app] INFO: Device 12: E3:76:5A:E3:D0:6F
0000217746 [app] INFO: Device 13: 2A:18:3B:54:52:23
0000217760 [app] INFO: Advertising name: P MAG C04244
0000217775 [app] INFO: Device 14: C7:5C:5C:6B:42:96
0000217789 [app] INFO: Advertising name: P DI 0020BC
0000217804 [app] INFO: Device 15: D4:D9:24:28:4C:E4
0000217818 [app] INFO: Advertising name: gst-010002879202
0000217834 [app] INFO: Device 16: F5:49:DC:9D:91:0F
0000217849 [app] INFO: Device 17: FC:98:CE:E5:88:5C
0000217859 [app] INFO: Advertising name: L ID 004A57
0000217874 [app] INFO: Device 18: E1:68:74:3A:C0:8A
0000217888 [app] INFO: Advertising name: BridgeConfig
0000217903 [app] INFO: Device 19: 34:85:18:2D:86:D1
0000217917 [app] INFO: Device 20: 4C:9A:11:AF:28:95
0000217932 [app] INFO: Advertising name: P DI 00208A
0000217946 [app] INFO: Device 21: D1:E1:28:39:45:38
0000217960 [app] INFO: Advertising name: P DI 0020BE
0000217975 [app] INFO: Device 22: C0:79:F3:49:C9:F2
0000217989 [app] INFO: Device 23: DC:EB:BD:E1:7D:5D
0000218004 [app] INFO: Advertising name: gst-010002863982
0000218019 [app] INFO: Device 24: D8:74:8C:CA:8F:EE
0000218033 [app] INFO: Device 25: F0:72:EA:41:DE:61
0000218048 [app] INFO: Advertising name: P DI 0020BB
0000218062 [app] INFO: Device 26: CA:34:AA:5C:33:BC
0000218076 [app] INFO: Device 27: 38:26:14:8D:C0:B1
0000218090 [app] INFO: Device 28: 2B:A4:FF:68:6D:FF
0000218103 [app] INFO: Advertising name: P MAG C04247
0000218117 [app] INFO: Device 29: EC:20:71:34:6D:97
0000218131 [app] INFO: Advertising name: P DI 001A10
0000218145 [app] INFO: Device 30: F6:43:DB:0F:0C:BF
0000218159 [app] INFO: Advertising name: P DI 0020C0
0000218174 [app] INFO: Device 31: EB:70:1A:7B:1C:EC
0000218188 [app] INFO: Device 32: 67:16:73:76:2A:B6
0000218203 [app] INFO: Advertising name: P MAG C0424B
0000218218 [app] INFO: Device 33: E4:AA:DA:93:30:42
0000218232 [app] INFO: Device 34: E4:B7:FD:E0:D3:78
0000218247 [app] INFO: Advertising name: P DI 0020BA
0000218262 [app] INFO: Device 35: CE:62:F5:C7:19:9E
0000218276 [app] INFO: Advertising name: P DI 0020B9
0000218291 [app] INFO: Device 36: D2:0A:55:4F:41:08
0000218306 [app] INFO: Advertising name: P ID 00D551
0000218320 [app] INFO: Device 37: F2:16:7B:EC:2F:11
0000218335 [app] INFO: Device 38: 03:B3:EC:8C:F5:D6
0000218350 [hal.ble] TRACE: Going to stop the stack...
0000218774 [hal] INFO: WiFi off
0000218783 [app] INFO: BLE Off
0000219792 [app] INFO: Starting BLE scan...
0000219814 [hal] INFO: rltk_wlan_set_netif_info: 0, 94:94:4a:07:4c:1c
0000219964 [hal] INFO: WiFi on
Wait - the timestamp did not reset to 0 so the system did not reset. Is the problem that the scans stop working after the end of that log? Those messages might be from automatic connection management. Does the status LED change when that happens?
It looks like four flashes between SOS ?
I can't attatch the video here but I'll email it.
Stew
[https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/45/8681_2.png]
rickkas7https://community.particle.io/u/rickkas7 Particle Technical Documentation Writer
May 14
Wait - the timestamp did not reset to 0 so the system did not reset. Is the problem that the scans stop working after the end of that log? Those messages might be from automatic connection management. Does the status LED change when that happens?
(Attachment 20250514_063808.mp4 is missing)
Oh, I see, the reset occurs after the end of that log. But something is happening in the rest of the system right before the SOS, which explains why it happens on the M-SoM and not the P2. It might be related to an interaction between automatic connection management and BLE.
Ive set :
SYSTEM_MODE(MANUAL);
Cellular.prefer(false);
WiFi.prefer(false);
in an attempt to disable other radios but "[hal] INFO: WiFi on" continues to pop up and eventually it crashes