Skip to content

Instantly share code, notes, and snippets.

@leinelissen
Created April 25, 2019 07:27
Show Gist options
  • Save leinelissen/e91302979a0ccdb246ae2fa93343d049 to your computer and use it in GitHub Desktop.
Save leinelissen/e91302979a0ccdb246ae2fa93343d049 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include "Adafruit_SGP30.h"
#include "OOCSI.h"
#define REED_PIN 2
// use this if you want the OOCSI-ESP library to manage the connection to the Wifi
// SSID of your Wifi network, the library currently does not support WPA2 Enterprise networks
const char* ssid = "***";
// Password of your Wifi network.
const char* password = "***";
// name for connecting with OOCSI (unique handle)
const char* OOCSIName = "group_3_first_device_2019";
// put the adress of your OOCSI server here, can be URL or IP address string
const char* hostserver = "oocsi.id.tue.nl";
// OOCSI reference for the entire sketch
OOCSI oocsi = OOCSI();
Adafruit_SGP30 sgp;
uint16_t tvoc;
uint16_t eco2;
bool isConnected;
void processOOCSI() {
//
}
void setup() {
Serial.begin(115200);
Serial.println("Startup");
if (! sgp.begin()){
Serial.println("Sensor not found :(");
while (1);
}
pinMode(REED_PIN, INPUT);
Serial.print("Found SGP30 serial #");
Serial.print(sgp.serialnumber[0], HEX);
Serial.print(sgp.serialnumber[1], HEX);
Serial.println(sgp.serialnumber[2], HEX);
// connect wifi and OOCSI to the server
oocsi.connect(OOCSIName, hostserver, ssid, password, processOOCSI);
}
void loop() {
if (! sgp.IAQmeasure()) {
Serial.println("Measurement failed");
return;
}
if(!sgp.getIAQBaseline(&eco2, &tvoc)) {
Serial.println("Failed to get baseline readings");
return;
}
isConnected = !digitalRead(REED_PIN);
Serial.print(sgp.eCO2);
Serial.print("\t");
Serial.print(sgp.TVOC);
Serial.print("\t");
Serial.println(isConnected);
// INSERT your channel name here
oocsi.newMessage("ded-air-quality-group-3");
// INSERT your device id here (from the Foundry website)
oocsi.addString("device_id" , "d1b06807304a2445b");
oocsi.addString("activity" , "EVENT");
oocsi.addInt("eco2", sgp.eCO2);
oocsi.addInt("tvoc", sgp.TVOC);
oocsi.addBool("reed", isConnected);
// this command will send the message; don't forget to call this after creating a message
oocsi.sendMessage();
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment