Skip to content

Commit

Permalink
v1.5.9
Browse files Browse the repository at this point in the history
 - added heyOOCSI functionality (OOCSIDevice)
 - fixed connection raising an exception on first fail
 - fixed headers and comments
 - added comments
  • Loading branch information
matsfunk committed Dec 16, 2021
1 parent 311f62d commit 745ea46
Show file tree
Hide file tree
Showing 15 changed files with 480 additions and 27 deletions.
Binary file modified dist/oocsi.zip
Binary file not shown.
5 changes: 3 additions & 2 deletions dist/oocsi/DFDataset.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/***************************************************************************
* The DataFoundry library for the ESP32, ESP8266, and Arduino Nano 33 IoT
* to store and retrieve data from ESPs and Arduino Nano 33 IoT on the Data
* The DataFoundry library for the ESP32, ESP8266, Arduino MKR Wifi 101,
* Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040
* to store and retrieve data from ESPs and Arduinos on the Data
* Foundry platform.
*
* Developed by Mathias Funk
Expand Down
5 changes: 3 additions & 2 deletions dist/oocsi/DFDataset.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/***************************************************************************
* The DataFoundry library for the ESP32, ESP8266, and Arduino Nano 33 IoT
* to store and retrieve data from ESPs and Arduino Nano 33 IoT on the Data
* The DataFoundry library for the ESP32, ESP8266, Arduino MKR Wifi 101,
* Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040
* to store and retrieve data from ESPs and Arduinos on the Data
* Foundry platform.
*
* Developed by Mathias Funk
Expand Down
18 changes: 14 additions & 4 deletions dist/oocsi/OOCSI.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/***************************************************************************
* The OOCSI library for the ESP32 and ESP 8266 is created to connect ESPs
* to the OOCSI platform (https://github.com/iddi/oocsi).
* The OOCSI library for the ESP32, ESP8266, Arduino MKR Wifi 101,
* Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040 to
* connect to the OOCSI platform (https://github.com/iddi/oocsi).
* It allows to send and receive from the OOCSI platform and allows for easy
* set-up of the ESP32 and ESP8266 platforms as OOCSI clients.
* setup of ESPs and Arduinos as OOCSI clients.
*
* Developed by Jort Band, Mathias Funk
**************************************************************************/
Expand Down Expand Up @@ -620,7 +621,7 @@ void OOCSI::printSendMessage() {
serializeJson(jsonMessage, Serial);
}


// return client list
String OOCSI::getClients() {
//basically send a message and then wait for the response client list.
//first read the standard messages
Expand All @@ -639,6 +640,7 @@ String OOCSI::getClients() {
return message;
}

// return channel list
String OOCSI::getChannels() {
//basically send a message and then wait for the response channels list.
//first read the standard messages
Expand All @@ -656,6 +658,7 @@ String OOCSI::getChannels() {
return message;
}

// check whether client is included in client list
bool OOCSI::containsClient(const char* clientName) {
//check for the client.
String clientlist = getClients();
Expand All @@ -667,35 +670,42 @@ bool OOCSI::containsClient(const char* clientName) {
return true;
}

// print message if logging is activated
void OOCSI::print(const String &message) {
if(logging)
Serial.print(message);
}

// print message if logging is activated
void OOCSI::print(char message) {
if(logging)
Serial.print(message);
}

// print message if logging is activated
void OOCSI::println() {
if(logging)
Serial.println();
}

// print message if logging is activated
void OOCSI::println(const String &message) {
if(logging)
Serial.println(message);
}

// print message if logging is activated
void OOCSI::println(char message) {
if(logging)
Serial.println(message);
}

// set activity pin
void OOCSI::setActivityLEDPin(int ledPin) {
activityLEDPin = ledPin;
}

// activate or deactivate logging
void OOCSI::setLogging(bool log) {
logging = log;
}
11 changes: 7 additions & 4 deletions dist/oocsi/OOCSI.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/***************************************************************************
* The OOCSI library for the ESP32 and ESP 8266 is created to connect ESPs
* to the OOCSI platform (https://github.com/iddi/oocsi).
* The OOCSI library for the ESP32, ESP8266, Arduino MKR Wifi 101,
* Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040 to
* connect to the OOCSI platform (https://github.com/iddi/oocsi).
* It allows to send and receive from the OOCSI platform and allows for easy
* set-up of the ESP32 and ESP8266 platforms as OOCSI clients.
* setup of ESPs and Arduinos as OOCSI clients.
*
* Developed by Jort Band, Mathias Funk
**************************************************************************/
Expand Down Expand Up @@ -35,7 +36,8 @@
#endif
#include <ArduinoJson.h>

class OOCSI{
class OOCSIDevice;
class OOCSI {
typedef void(*oocsiCallbackFunction_t)(void*);

public:
Expand All @@ -53,6 +55,7 @@ class OOCSI{
void keepAlive();
void subscribe(const char* chan);
void unsubscribe(const char* chan);
OOCSIDevice heyOOCSI(const char* name);

// sending data
OOCSI newMessage(const char* receiver);
Expand Down
154 changes: 154 additions & 0 deletions dist/oocsi/OOCSIDevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/***************************************************************************
* The OOCSIDevice library for the ESP32, ESP8266, Arduino MKR Wifi 101,
* Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040 to
* connect to the OOCSI platform (https://github.com/iddi/oocsi).
* It allows to register ESP and Arduino-based OOCSI clients as annotated
* devices on the OOCSI platform (and HomeAssistant).
*
* Developed by Diede van Marle, Mathias Funk
**************************************************************************/

#include "OOCSIDevice.h"

// create a prototype:
OOCSIDevice::OOCSIDevice(const char* prototypeName, OOCSI &client, const char* OOCSIName) {
oocsi = &client;
oocsi->newMessage("heyOOCSI!");
device = oocsi->addJsonObject(prototypeName);
properties = device.createNestedObject("properties");
properties["device_id"] = OOCSIName;
components = device.createNestedObject("components");
location = device.createNestedObject("location");
}

// Add device properties
void OOCSIDevice::addProperty(const char* property, const char* propertyValue) {
properties[property] = propertyValue;
}

// Location initialisation
void OOCSIDevice::addLocation(const char* locationName, const char* latitude,const char* longitude) {
location[locationName][0] = latitude;
location[locationName][1] = longitude;
}

// Sensor configuration
void OOCSIDevice::addSensor(const char* sensorName, const char* sensorChannel, const char* sensorType, const char* sensorDefaultValue, const char* sensorUnit, const char* icon) {
JsonObject sensor = components.createNestedObject(sensorName);
sensor["channel_name"] = sensorChannel;
sensor["type"] = "sensor";
sensor["value"] = sensorDefaultValue;
sensor["sensor_type"] = sensorType;
sensor["unit"] = sensorUnit;
sensor["icon"] = icon;
}

// Number input configuration
void OOCSIDevice::addNumber(const char* numberName, const char* numberChannel, const char* numberMin, const char* numberMax, const char* numberDefaultValue, const char* numberUnit, const char* icon) {
JsonObject number = components.createNestedObject(numberName);
number["channel_name"] = numberChannel;
number["type"] = "number";
number["max"] = numberMax;
number["min"] = numberMin;
number["value"] = numberDefaultValue;
number["sensor_type"] = "number";
number["unit"]=numberUnit;
number["icon"] = icon;
}

// Binary sensor configuration
void OOCSIDevice::addBinarySensor(const char* sensorName, const char* sensorChannel, const char* sensorType, const char* sensorDefaultState, const char* icon) {
JsonObject sensor = components.createNestedObject(sensorName);
sensor["channel_name"] = sensorChannel;
sensor["type"] = "binary_sensor";
sensor["state"] = sensorDefaultState;
sensor["sensor_type"] = sensorType;
sensor["icon"] = icon;
}

// Switch configuration
void OOCSIDevice::addSwitch(const char* switchName, const char* switchChannel, const char* switchDefaultState, const char* icon) {
JsonObject switchConfig = components.createNestedObject(switchName);
switchConfig["channel_name"] = switchChannel;
switchConfig["type"] = "switch";
switchConfig["state"] = switchDefaultState;
switchConfig["icon"] = icon;
}

// light configuration
void OOCSIDevice::addLight(const char* lightName, const char* lightChannel, const char* ledType, int spectrum, const char* lightDefaultState, int defaultBrightness, const char* icon) {
JsonObject light = components.createNestedObject(lightName);
light["channel_name"] = lightChannel;
light["type"] = "light";
light["state"] = lightDefaultState;
light["ledType"] = ledType;
light["brightness"] = defaultBrightness;
light["icon"] = icon;
JsonArray spectrums = light.createNestedArray("spectrum");
switch(spectrum) {
case 1:
case 4:
case 6:
case 7:
spectrums.add("RGB");
}
switch(spectrum) {
case 2:
case 4:
case 5:
case 7:
spectrums.add("CCT");
}
switch(spectrum) {
case 3:
case 5:
case 6:
case 7:
spectrums.add("WHITE");
}
}

//light configuration incase of CCT lights
void OOCSIDevice::addLight(const char* lightName, const char* lightChannel, const char* ledType, int spectrum, const char* lightDefaultState, int defaultBrightness, int miredMax, int miredMin, const char* icon) {
JsonObject light = components.createNestedObject(lightName);
light["channel_name"] = lightChannel;
light["type"] = "light";
light["state"] = lightDefaultState;
light["ledType"] = ledType;
light["brightness"] = defaultBrightness;
light["icon"] = icon;
JsonArray spectrums = light.createNestedArray("spectrum");
switch(spectrum) {
case 1:
case 4:
case 6:
case 7:
spectrums.add("RGB");
}
switch(spectrum) {
case 2:
case 4:
case 5:
case 7:
spectrums.add("CCT");
}
switch(spectrum) {
case 3:
case 5:
case 6:
case 7:
spectrums.add("WHITE");
}
light["max"] = miredMax;
light["min"] = miredMin;
}

// send configured interview
void OOCSIDevice::sayHi() {
oocsi->sendMessage();
}

// return OOCSIDevice with given name
OOCSIDevice OOCSI::heyOOCSI(const char* name) {
return OOCSIDevice(name, *this, OOCSIName);
}
49 changes: 49 additions & 0 deletions dist/oocsi/OOCSIDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/***************************************************************************
* The OOCSIDevice library for the ESP32, ESP8266, Arduino MKR Wifi 101,
* Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040 to
* connect to the OOCSI platform (https://github.com/iddi/oocsi).
* It allows to register ESP and Arduino-based OOCSI clients as annotated
* devices on the OOCSI platform (and HomeAssistant).
*
* Developed by Diede van Marle, Mathias Funk
**************************************************************************/

#ifndef OOCSIDevice_h
#define OOCSIDevice_h
#include "OOCSI.h"
#include <ArduinoJson.h>

#define LIGHT_SPECTRUM_RGB 1
#define LIGHT_SPECTRUM_CCT 2
#define LIGHT_SPECTRUM_WHITE 3
#define LIGHT_SPECTRUM_RGB_CCT 4
#define LIGHT_SPECTRUM_CCT_WHITE 5
#define LIGHT_SPECTRUM_RGB_WHITE 6
#define LIGHT_SPECTRUM_RGB_CCT_WHITE 7

class OOCSI;
class OOCSIDevice {
public:
// setup, connection, subscription
OOCSIDevice(const char* prototypeName, OOCSI &client, const char* OOCSIName);

void addProperty(const char* property, const char* propertyValue);
void addLocation(const char* locationName, const char* latitude,const char* longitude);
void addSensor(const char* sensorName , const char* sensorChannel, const char* sensorType, const char* sensorDefaultValue, const char* sensorUnit, const char* icon);
void addNumber(const char* numberName , const char* numberChannel, const char* numberMin, const char* numberMax, const char* numberDefaultValue, const char* numberUnit, const char* icon);
void addBinarySensor(const char* sensorName , const char* sensorChannel, const char* sensorType, const char* sensorDefaultState, const char* icon);
void addSwitch(const char* switchName , const char* switchChannel, const char* switchDefaultState, const char* icon);
void addLight(const char* lightName , const char* lightChannel, const char* ledType, int spectrum, const char* lightDefaultState, int defaultBrightness, int miredMax, int miredMin, const char* icon);
void addLight(const char* lightName , const char* lightChannel, const char* ledType, int spectrum, const char* lightDefaultState, int defaultBrightness, const char* icon);

void sayHi();

private:
OOCSI* oocsi;
JsonObject device;
JsonObject properties;
JsonObject components;
JsonObject location;
};

#endif
19 changes: 18 additions & 1 deletion dist/oocsi/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#######################################

OOCSI KEYWORD1
OOCSIDevice KEYWORD1


#######################################
Expand Down Expand Up @@ -70,9 +71,25 @@ getClients KEYWORD2
getChannels KEYWORD2
containsClient KEYWORD2

heyOOCSI KEYWORD2
addProperty KEYWORD2
addLocation KEYWORD2
addSensor KEYWORD2
addNumber KEYWORD2
addBinarySensor KEYWORD2
addSwitch KEYWORD2
addLight KEYWORD2
sayHi KEYWORD2


#######################################
# Constants (LITERAL1)
#######################################

# LITERAL1
LIGHT_SPECTRUM_RGB LITERAL1
LIGHT_SPECTRUM_CCT LITERAL1
LIGHT_SPECTRUM_WHITE LITERAL1
LIGHT_SPECTRUM_RGB_CCT LITERAL1
LIGHT_SPECTRUM_CCT_WHITE LITERAL1
LIGHT_SPECTRUM_RGB_WHITE LITERAL1
LIGHT_SPECTRUM_RGB_CCT_WHITE LITERAL1
4 changes: 2 additions & 2 deletions dist/oocsi/library.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name=OOCSI
version=1.5.8
version=1.5.9
author=Jort Band, Mathias Funk
maintainer=Mathias Funk <m.funk@tue.nl>
sentence=OOCSI client library for the ESP32, ESP8266 and Arduino NANO 33 IoT
sentence=OOCSI client library for the ESP32, ESP8266, Arduino MKR Wifi 101, Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040
paragraph=Library for easy connection and communication with the ESP32, ESP8266 and Arduino NANO 33 IoT modules over the OOCSI platform
category=Communication
url=https://github.com/iddi/oocsi-esp
Expand Down
5 changes: 3 additions & 2 deletions src/DFDataset.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/***************************************************************************
* The DataFoundry library for the ESP32, ESP8266, and Arduino Nano 33 IoT
* to store and retrieve data from ESPs and Arduino Nano 33 IoT on the Data
* The DataFoundry library for the ESP32, ESP8266, Arduino MKR Wifi 101,
* Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040
* to store and retrieve data from ESPs and Arduinos on the Data
* Foundry platform.
*
* Developed by Mathias Funk
Expand Down
Loading

0 comments on commit 745ea46

Please sign in to comment.