此代码始终向 UBIDOTS 云平台发送“0”值。但是当我只尝试将值(没有集成 ubidots 代码)打印到串行监视器时,我得到了这些值。请帮帮我..
我试试这个.. 当我尝试将 ubidots 平台与其他传感器(如 DS18b20 或 DHT11)一起使用时,它工作得很好。
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include "Ubidots.h"
#define REPORTING_PERIOD_MS 1000
// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
const char* UBIDOTS_TOKEN = "TOKEN"; // Put here your Ubidots TOKEN
const char* WIFI_SSID = "SSID"; // Put here your Wi-Fi SSID
const char* WIFI_PASS = "PASS";
Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);
PulseOximeter pox;
uint32_t tsLastReport = 0;
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
ubidots.wifiConnect(WIFI_SSID, WIFI_PASS);
Serial.print("Initializing pulse oximeter..");
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop()
{
// Make sure to call update as fast as possible
pox.update();
// Asynchronously dump heart rate and oxidation levels to the serial
// For both, a value of 0 means "invalid"
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
ubidots.add("BPM",pox.getHeartRate());
ubidots.add("SpO2",pox.getSpO2());
bool bufferSent = false;
bufferSent = ubidots.send();
tsLastReport = millis();
}
}