Max30100 sensor not reporting to losant

Hello,

I need help!

I have successfully connected my Esp32 to losant using the unsecured connection method as secured protocol is taking forever to connect.

I can easily send data from my Esp32 to losant. But then I can’t send max30100 sensor data.

The sensor uses i2c communication protocol.

Having spent a huge time tracing where the error is coming from, I realised its coming from the device.connect(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET) method.

Once I comment out this line, the sensor function as expected, but once I add it, it stops working.

Could some one help me fix this issue.

Regards

Hello @Sunday_Ajiroghene,

I see you’ve made several posts about this, so I will reply here and link to this post in your other posts.

I am not familiar with the MAX30100 sensor, but since it does communicate over I2C, it should work just fine with the ESP32.

Would you be able to share a snippet of your code? I may be able to help debug this way.

Also, we updated our Arduino Examples, specifically the ESP32 example so that the connectSecure works. You can read more about it in this post.

Thank you,
Heath

Hi @Heath ,

Thanks for your response and willingness to help.

I have read carefully your input and have attempted to fix the secured connection. Communication to Losant patform is on the secured route now but the max30100 has not being able to coommunicate as expected.

Below is my code snippet:

#include <WiFiClientSecure.h>
#include <Losant.h>

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <OneWire.h>
#include <DallasTemperature.h>


#define DS18B20 5
#define REPORTING_PERIOD_MS     1000
 
float temperature, humidity, BPM, SpO2, bodytemperature;

PulseOximeter pox;
uint32_t tsLastReport = 0;
OneWire oneWire(DS18B20);
DallasTemperature sensors(&oneWire);

/*Put your SSID & Password*/
const char* WIFI_SSID = "xxxxxxx";  // Enter SSID here
const char* WIFI_PASS = "xxxxxxx";  //Enter Password herez

// Losant credentials
const char* LOSANT_DEVICE_ID = "xxxxxxxxxxxxxxxxxxxxxxx";
const char* LOSANT_ACCESS_KEY = "xxxxxxxxxxxxxxxxxxxxxxx";
const char* LOSANT_ACCESS_SECRET = "xxxxxxxxxxxxxxxxxxxxxxx";

const char* rootCABuff = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\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WO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" \
"PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" \
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" \
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" \
"-----END CERTIFICATE-----\n";

WiFiClientSecure wifiClient;
LosantDevice device(LOSANT_DEVICE_ID);

void connect() {

  // Connect to Wifi.
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  wifiClient.setCACert(rootCABuff);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }  

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Connect to Losant.
  Serial.println();
  Serial.print("Connecting to Losant...");

  device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  while(!device.connected()) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("Connected!");
}


// Reconnects if required 
void reconnect(){
 bool toReconnect = false;
  // If the WiFi or HUZZAH is not connected to Losant - we should reconnect
  if(WiFi.status() != WL_CONNECTED || !device.connected()) {
    toReconnect = true;
  }
  if(toReconnect) {
    connect();
  }
}


void report(float BPM,float SpO2, float bodytemperature) {
  StaticJsonDocument<500> jsonBuffer;
  JsonObject root = jsonBuffer.to<JsonObject>();
  
  root["BPM"]             = BPM;
  root["SpO2"]            = SpO2;
  root["bodytemperature"] = bodytemperature;
  
  device.sendState(root);
  Serial.println("Reported to Losant!");
}         
 
void onBeatDetected()
{
  Serial.println("Beat!");
}
 
void setup() {
  Serial.begin(115200);           //  UART setup, baudrate = 115200bps
  pinMode(19, OUTPUT);
  delay(100);   
 
 if (!pox.begin()) {
    Serial.println("FAILED");
    for (;;);
  } else {
    Serial.println("SUCCESS");
    pox.setOnBeatDetectedCallback(onBeatDetected);
  }
 
  pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

  Serial.println("Device Started");
  Serial.println("-------------------------------------");
  Serial.println("e-Health System");
  Serial.println("-------------------------------------");

  connect(); 
}

int timeSinceLastRead = 0;

void loop() {

    bool toReconnect = false;

    if(WiFi.status() != WL_CONNECTED) {
      Serial.println("Disconnected from WiFi");
      toReconnect = true;
    }
  
    if(!device.connected()) {
      Serial.println("Disconnected from MQTT");
      toReconnect = true;
    }
  
    if(toReconnect) {
      connect();
    }
  
    device.loop();
  
    if (timeSinceLastRead > REPORTING_PERIOD_MS){

      pox.update();
      sensors.requestTemperatures();
     
      BPM = pox.getHeartRate();
      SpO2 = pox.getSpO2();
      bodytemperature = sensors.getTempCByIndex(0);
      
      Serial.print("BPM: "); Serial.println(BPM);
      Serial.print("SpO2: ");Serial.print(SpO2);Serial.println("%");
      Serial.print("Body Temperature: ");Serial.print(bodytemperature);Serial.println("°C");
      Serial.println("*********************************");Serial.println();
         
      report(BPM,SpO2,bodytemperature);    
      timeSinceLastRead = 0;
      
    }
    delay(200);
    timeSinceLastRead += 100;
}
 

Below is my output as at now:

Reported to Losant!
BPM: 0.00
SpO2: 0.00%
Body Temperature: 29.87°C


Reported to Losant!
BPM: 0.00
SpO2: 0.00%
Body Temperature: 29.87°C


Reported to Losant!

The max30100 is still not being able to communicate as from the output.

Your fix would be highly appreciated.

Warmest regards,

Ajioz

I’m facing the same problem as you are facing now, Is there any updated solution that I can get it from you now? it really helps me.