aymen ammari
DIIDevHeads IoT Integration Server
•Created by aymen ammari on 7/25/2024 in #edge-networking
MLX90640 Sensor Fails After 3-5 Minutes When Using ArduinoBLE Library
void loop() {
BLEDevice central = BLE.central();
Serial.println("- Discovering central device...");
if (central) {
Serial.println("* Connected to central device!");
Serial.print("* Device MAC address: ");
Serial.println(central.address());
Serial.println(" ");
while (central.connected()) {
delay(500);
if (mlx.getFrame(frame) != 0) {
Serial.println("Failed");
return;
}
Serial.println();
for (uint8_t h=0; h<24; h++) {
for (uint8_t w=0; w<32; w++) {
// float t = frame[h*32 + w];
frame_ble[h*32 + w] = frame[h*32 + w];
Serial.print(frame_ble[h*32 + w]);
Serial.print(", ");
}
Serial.println();
}
sendLargeDataOverBLE();
// delay(1000);
}
Serial.println("* Disconnected to central device!");
}
}
void sendLargeDataOverBLE() {
for (int i = 0; i < sizeof(frame_ble); i += 20) {
// Create a buffer for the chunk
uint8_t chunk[20];
int chunkSize = min(20, sizeof(frame_ble) - i);
// Copy the chunk from the large data array
memcpy(chunk, frame_ble + i, chunkSize);
// Send the chunk
ArduinoMLXResponseCharacteristic.writeValue(chunk, chunkSize);
// Small delay to ensure the BLE stack can handle the next packet
delay(10);
}
}
void loop() {
BLEDevice central = BLE.central();
Serial.println("- Discovering central device...");
if (central) {
Serial.println("* Connected to central device!");
Serial.print("* Device MAC address: ");
Serial.println(central.address());
Serial.println(" ");
while (central.connected()) {
delay(500);
if (mlx.getFrame(frame) != 0) {
Serial.println("Failed");
return;
}
Serial.println();
for (uint8_t h=0; h<24; h++) {
for (uint8_t w=0; w<32; w++) {
// float t = frame[h*32 + w];
frame_ble[h*32 + w] = frame[h*32 + w];
Serial.print(frame_ble[h*32 + w]);
Serial.print(", ");
}
Serial.println();
}
sendLargeDataOverBLE();
// delay(1000);
}
Serial.println("* Disconnected to central device!");
}
}
void sendLargeDataOverBLE() {
for (int i = 0; i < sizeof(frame_ble); i += 20) {
// Create a buffer for the chunk
uint8_t chunk[20];
int chunkSize = min(20, sizeof(frame_ble) - i);
// Copy the chunk from the large data array
memcpy(chunk, frame_ble + i, chunkSize);
// Send the chunk
ArduinoMLXResponseCharacteristic.writeValue(chunk, chunkSize);
// Small delay to ensure the BLE stack can handle the next packet
delay(10);
}
}
7 replies