I am working on a Neopixel project that needs to react to music. I have one primary Argon that has a mic, doing some computation on that, and using BLE to advertise out the data. It updates its advertisement every 25ms or so, the advertising rate is the shortest possible setting. This seems to be working fine.
However, the receiving Argons are flaky. I have the loop rendering every 33ms (for 30FPS), which first scans for nearby BLE devices for 20ms using the updateData() method below, and then renders the audio level effect on the strip. Randomly, which can happen as soon as 30 seconds or after 10 minutes, the BLE.scan() call seems to cause a crash. The loop effectively stops, I cannot flash the firmware, it still has the light blue pulsating indicator. It is strange.
There is nothing magical about the code below. I have added logging to show me where it stops, and every time the last log entry is “Begin Scan”.
void updateData()
{
Log.info("Begin Scan");
int count = BLE.scan(scanResults, SCAN_RESULT_MAX);
Log.info("Finished Scan");
for (int i = 0; i < count; i++)
{
len = scanResults[i].advertisingData.customData(blebuf, BLE_MAX_ADV_DATA_LEN);
Log.info("Got Results: %d", len);
if (len == 6)
{
// This is the dummy company id and data type we set from the advertiser
if (blebuf[0] == 0xff && blebuf[1] == 0xff && blebuf[2] == 0x55)
{
Log.info("Matched Signature");
uint16_t level;
memcpy(&level, &blebuf[3], 2);
uint8_t hue;
memcpy(&hue, &blebuf[5], 1);
Log.info("Computed Integers");
cmd.audioLevel = level;
cmd.globalhue = hue;
Log.info("Set Props");
hitCount++;
Log.info("Hit Count++");
break;
}
}
}
}
Any thoughts? While the loop is working, it is quite good.
I would prefer that the secondary Argons driving the LED strips would just make a BLE connection to the primary, I have about 5 devices in the room and I hit that 3 connection limit quick unfortunately. Also open to other thoughts on how to broadcast data in realtime. I tried UDP I think I am running into that Argon UDP lag issue because I cannot get a consistent low enough latency where it is visually out of sync every few seconds.