Esp8266 無法傳送max30100測得的數據至ThingSpeak平台

I changed the ssid 、 pass、apikey, but because of security issues, I replaced it with xxxx
#include <WiFiClient.h>
#include "MAX30100_PulseOximeter.h"
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>
#define REPORTING_PERIOD_MS 1000

const char* apiKey = "xxxx"; // Enter your Write API key from ThingSpeak
const char* ssid = "xxxx"; // Enter your WiFi Network's SSID
const char* pass = "xxxx"; // Enter your WiFi Network's Password
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";
float BPM,SpO2;
WiFiClient client;
PulseOximeter pox;

uint32_t tsLastReport = 0;

void onBeatDetected()
{
Serial.println("Beat!");
}

void setup()
{
Serial.begin(115200);

Serial.print("Initializing pulse oximeter..");

Serial.print("Connecting to: ");
Serial.println(ssid);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected.");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

// 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");
}

// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop()
{
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
tsLastReport = millis();
BPM = pox.getHeartRate();
SpO2 = pox.getSpO2();
Serial.print("Heart rate:");
Serial.print(BPM);
Serial.print("bpm / SpO2:");
Serial.print(SpO2);
Serial.println("%");
}
delay(1000);
// 使用 80 Port 連線
if (client.connect(server, 80)) {
Serial.println(F("connected"));
}
else {
Serial.println(F("connection failed"));
return;
}

Serial.print("Request resource: ");
Serial.println(resource);

client.print(String("GET ") + resource + apiKey + "&field1=" + float(BPM) + "&field2=" + float(SpO2) +
" HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n\r\n");

int timeout = 5 * 10; // 5 seconds
while (!!!client.available() && (timeout-- > 0)) {
delay(100);
}

if (!client.available()) {
Serial.println("No response, going back to sleep");
}
while (client.available()) {
Serial.write(client.read());
}

Serial.println("\nclosing connection");
client.stop();

// 每三分鐘會上傳一筆資料
delay(10000);
}

Can you describe your problem?

Don't forget to put your code in a suitable format with the </> icon

Esp8266 cannot transmit the data measured by max30100 to the ThingSpeak platform

I will try to test with my ESP8266.

Can you give more details about your problem?
What does the serial monitor display?
What is the tutorial?

Hello,

Before testing with your sensor have you tested this?

Just a connection to ThingSpeak without a sensor.

Otherwise, what does the serial monitor display?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.