Commit 130e9881 authored by Serasinghe K.A.E.Y.D's avatar Serasinghe K.A.E.Y.D 😊

Merge branch 'yomal-dev' into 'master'

IOT file create and test done

See merge request !5
parents 788c3a9a 5bafd706
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "Adafruit_GFX.h"
#include "OakOLED.h"
#include "icon.h"
//------------------------------------------------------------------------------
#define WIFI_SSID "Galaxy"
#define WIFI_PASS "00000000"
#define SERVER_API "http://192.168.48.209:5000/record"
#define SERVER_SYNC_DELAY 30 // in seconds
#define DEVICE_ID "15555000"
//------------------------------------------------------------------------------
#define REPORTING_PERIOD_MS 1000
OakOLED oled;
PulseOximeter pox;
float BPM, SpO2;
uint32_t tsLastReport = 0;
int serverSyncDelay=0;
const int oneWireBus = 12;
OneWire oneWire(oneWireBus);
DallasTemperature tempsensor(&oneWire);
float tempC;
void setup()
{
oled.begin();
Serial.begin(9600);
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(40, 32);
oled.println("Initializing");
oled.display();
delay(1000);
pinMode(16, OUTPUT);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
oled.clearDisplay();
oled.setCursor(20, 32);
oled.println("wifi connecting");
oled.display();
}
pox_start();
// if (!pox.begin()){
// oled.clearDisplay();
// oled.setCursor(40, 32);
// oled.println("POX Error");
// oled.display();
// for (;;);
// }
// else
// {
// oled.clearDisplay();
// oled.setTextSize(1);
// oled.setTextColor(1);
// oled.setCursor(40, 32);
// oled.println("POX SUCCESS");
// oled.display();
// }
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// WiFi.begin("yourSSID", "yourPASS");
//
tempsensor.begin();
}
void loop()
{
tempsensor.requestTemperatures();
tempC = tempsensor.getTempCByIndex(0);
pox.update();
BPM = pox.getHeartRate();
SpO2 = pox.getSpO2();
//
if (millis() - tsLastReport > REPORTING_PERIOD_MS)
{
oled.clearDisplay();
if(WiFi.status() != WL_CONNECTED){
oled.drawBitmap( 112, 0, icon_wifi_off, 16, 16, 1);
}
else{
oled.drawBitmap( 112, 0, icon_wifi_on, 16, 16, 1);
if( serverSyncDelay ==SERVER_SYNC_DELAY ){ pox.shutdown();sendDatatoServer(); serverSyncDelay=0;}
serverSyncDelay++;
}
oled.drawBitmap( 0, 0, icon_temperature, 16, 16, 1);
oled.drawBitmap( 40, 25, icon_heart, 28, 28, 1);
oled.setCursor(24, 0);
oled.setTextSize(2);
oled.print((int)tempC);
oled.println("C");
oled.setCursor(0, 29);
oled.setTextSize(1);
oled.println("BPM");
oled.setCursor(76, 29);
oled.println("Oxygen");
oled.setCursor(0, 40);
oled.setTextSize(2);
oled.println((int)pox.getHeartRate());
oled.setCursor(76, 40);
oled.println(pox.getSpO2());
oled.display();
tsLastReport = millis();
//setup_dispaly();
}
//pox.resume();
}
void pox_start(){
if (!pox.begin()){
// oled.clearDisplay();
// oled.setCursor(40, 32);
// oled.println("POX Error");
// oled.display();
for (;;);
}
else
{
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(40, 32);
oled.println("POX SUCCESS");
oled.display();
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
}
void sendDatatoServer(){
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(40, 32);
oled.println("Sending Data");
oled.display();
WiFiClient client;
HTTPClient http;
http.begin(client, SERVER_API); //HTTP
http.addHeader("Content-Type", "application/json");
Serial.print("[HTTP] POST...\n");
// start connection and send HTTP header and body
int httpCode = http.POST("{\"temperature\":\""+(String)tempC+"\", \"bpm\":\""+(String)BPM+"\", \"spo2\":\""+(String)SpO2+"\", \"deviceid\":\""+DEVICE_ID+"\" }");
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] POST... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
const String& payload = http.getString();
Serial.println("received payload:\n<<");
Serial.println(payload);
Serial.println(">>");
}
} else {
Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(40, 32);
oled.println("HTTP Faild");
oled.display();
}
http.end();
delay(2000);
pox_start();
}
const unsigned char icon_wifi_on [] PROGMEM =
{
0b00000000, 0b00000000, //
0b00000111, 0b11100000, // ######
0b00011111, 0b11111000, // ##########
0b00111111, 0b11111100, // ############
0b01110000, 0b00001110, // ### ###
0b01100111, 0b11100110, // ## ###### ##
0b00001111, 0b11110000, // ########
0b00011000, 0b00011000, // ## ##
0b00000011, 0b11000000, // ####
0b00000111, 0b11100000, // ######
0b00000100, 0b00100000, // # #
0b00000001, 0b10000000, // ##
0b00000001, 0b10000000, // ##
0b00000000, 0b00000000, //
0b00000000, 0b00000000, //
0b00000000, 0b00000000, //
};
const unsigned char icon_temperature [] PROGMEM =
{
0b00000001, 0b11000000, // ###
0b00000011, 0b11100000, // #####
0b00000111, 0b00100000, // ### #
0b00000111, 0b11100000, // ######
0b00000111, 0b00100000, // ### #
0b00000111, 0b11100000, // ######
0b00000111, 0b00100000, // ### #
0b00000111, 0b11100000, // ######
0b00000111, 0b00100000, // ### #
0b00001111, 0b11110000, // ########
0b00011111, 0b11111000, // ##########
0b00011111, 0b11111000, // ##########
0b00011111, 0b11111000, // ##########
0b00011111, 0b11111000, // ##########
0b00001111, 0b11110000, // ########
0b00000111, 0b11100000, // ######
};
const unsigned char icon_heart[] PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x18, 0x00, 0x0f, 0xe0, 0x7f, 0x00, 0x3f, 0xf9, 0xff, 0xc0,
0x7f, 0xf9, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xf0,
0xff, 0xf7, 0xff, 0xf0, 0xff, 0xe7, 0xff, 0xf0, 0xff, 0xe7, 0xff, 0xf0, 0x7f, 0xdb, 0xff, 0xe0,
0x7f, 0x9b, 0xff, 0xe0, 0x00, 0x3b, 0xc0, 0x00, 0x3f, 0xf9, 0x9f, 0xc0, 0x3f, 0xfd, 0xbf, 0xc0,
0x1f, 0xfd, 0xbf, 0x80, 0x0f, 0xfd, 0x7f, 0x00, 0x07, 0xfe, 0x7e, 0x00, 0x03, 0xfe, 0xfc, 0x00,
0x01, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x3f, 0xc0, 0x00,
0x00, 0x0f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char icon_wifi_off[] PROGMEM =
{
0b00000000, 0b00000000, //
0b00000011, 0b11100000, // #####
0b00001111, 0b11111000, // #########
0b00011111, 0b11111100, // ###########
0b00111110, 0b00111110, // ##### #####
0b00111000, 0b01111110, // ### ######
0b01110000, 0b11111111, // ### ########
0b01110001, 0b11110111, // ### ##### ###
0b01110011, 0b11000111, // ### #### ###
0b01110111, 0b10000111, // ### #### ###
0b00111111, 0b00001110, // ###### ###
0b00111110, 0b00011110, // ##### ####
0b00011111, 0b11111100, // ###########
0b00001111, 0b11111000, // #########
0b00000011, 0b11100000, // #####
0b00000000, 0b00000000, //
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment