Skip to content

Commit

Permalink
Merge pull request #340 from sinricpro/fix_sensors
Browse files Browse the repository at this point in the history
Update sensors
  • Loading branch information
sivar2311 authored Oct 4, 2023
2 parents 13eb776 + ee5b5bb commit 4918e67
Show file tree
Hide file tree
Showing 40 changed files with 124 additions and 227 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## Version 3.0.0
- BREAKING CHANGE: Remove PowerStateController from Air Quality, Contact, Motion and Temperature sensor.
- Fix examples
- Default Arduino Serial baudrate changed to 115200

## Version 2.11.1
- Support Raspberry Pi Pico W

Expand Down
2 changes: 1 addition & 1 deletion examples/ACUnit/ACUnit.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define APP_KEY "YOUR_APP_KEY_HERE" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR_APP_SECRET_HERE" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define ACUNIT_ID "YOUR_DEVICE_ID_HERE" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

float globalTemperature;
bool globalPowerState;
Expand Down
30 changes: 17 additions & 13 deletions examples/AirQualitySensor/AirQualitySensor/AirQualitySensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define DEVICE_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

// Air quality sensor event dispatch time. Min is every 1 min.
#define MIN (1000UL * 60 * 1)
Expand Down Expand Up @@ -70,7 +70,6 @@ void setupSinricPro() {

// set callback function to device


// setup SinricPro
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
Expand All @@ -86,15 +85,20 @@ void setup() {
void loop() {
SinricPro.handle();

if((long)(millis() - dispatchTime) >= 0) {
SinricProAirQualitySensor &mySinricProAirQualitySensor = SinricPro[DEVICE_ID]; // get sensor device

int pm1 =0;
int pm2_5 = 0;
int pm10=0;

mySinricProAirQualitySensor.sendAirQualityEvent(pm1, pm2_5, pm10, "PERIODIC_POLL");
dispatchTime += MIN;
Serial.println("Sending Air Quality event ..");
}
if((long)(millis() - dispatchTime) >= 0) {
SinricProAirQualitySensor &mySinricProAirQualitySensor = SinricPro[DEVICE_ID]; // get sensor device

int pm1 =0;
int pm2_5 = 0;
int pm10=0;

bool success = mySinricProAirQualitySensor.sendAirQualityEvent(pm1, pm2_5, pm10, "PERIODIC_POLL");
if(success) {
Serial.println("Air Quality event sent! ..");
} else {
Serial.printf("Something went wrong...could not send Event to server!\r\n");
}

dispatchTime += MIN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define DEVICE_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

// Air quality sensor event dispatch time. Min is every 1 min.
#define MIN (1000UL * 60 * 1)
Expand Down Expand Up @@ -76,9 +76,6 @@ void setupSinricPro() {
// add device to SinricPro
SinricProAirQualitySensor& mySinricProAirQualitySensor = SinricPro[DEVICE_ID];

// set callback function to device


// setup SinricPro
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
Expand All @@ -91,34 +88,38 @@ void setupDustSensor() {
dustSensor.begin();
}


void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
setupWiFi();
setupSinricPro();
setupDustSensor();
}


void loop() {
SinricPro.handle();

if((long)(millis() - dispatchTime) >= 0) {
Serial.print("Dust density: ");
Serial.print(dustSensor.getDustDensity());
Serial.print(" ug/m3; Running average: ");
Serial.print(dustSensor.getRunningAverage());
Serial.println(" ug/m3");

SinricProAirQualitySensor &mySinricProAirQualitySensor = SinricPro[DEVICE_ID]; // get air q sensor device

int pm1=0;
int pm2_5 = dustSensor.getRunningAverage();
int pm10=0;

mySinricProAirQualitySensor.sendAirQualityEvent(pm1, pm2_5, pm10, "PERIODIC_POLL");
dispatchTime += MIN;

Serial.println("Sending Air Quality event ..");
}
if((long)(millis() - dispatchTime) >= 0) {
Serial.print("Dust density: ");
Serial.print(dustSensor.getDustDensity());
Serial.print(" ug/m3; Running average: ");
Serial.print(dustSensor.getRunningAverage());
Serial.println(" ug/m3");

SinricProAirQualitySensor &mySinricProAirQualitySensor = SinricPro[DEVICE_ID]; // get air q sensor device

int pm1=0;
int pm2_5 = dustSensor.getRunningAverage();
int pm10=0;

bool success = mySinricProAirQualitySensor.sendAirQualityEvent(pm1, pm2_5, pm10, "PERIODIC_POLL");
if(success) {
Serial.println("Air Quality event sent! ..");
} else {
Serial.printf("Something went wrong...could not send Event to server!\r\n");
}

dispatchTime += MIN;

Serial.println("Sending Air Quality event ..");
}
}
2 changes: 1 addition & 1 deletion examples/Blinds/Blinds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define BLINDS_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

int blindsPosition = 0;
bool powerState = false;
Expand Down
3 changes: 2 additions & 1 deletion examples/Camera/mjpeg-camera/mjpeg-camera.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx". Get it from https://portal.sinric.pro/ -> Credentials
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" . Get it from https://portal.sinric.pro/ -> Credentials
#define CAMERA_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx". Get it from https://portal.sinric.pro/ -> Devices
#define BAUD_RATE 115200 // Change baudrate to your need

void cameraInit(void);
void startCameraServer();
Expand Down Expand Up @@ -71,7 +72,7 @@ void setupSinricPro() {


void setup() {
Serial.begin(115200);
Serial.begin(BAUD_RATE);
Serial.setDebugOutput(true);
Serial.println();

Expand Down
4 changes: 2 additions & 2 deletions examples/Camera/rtsp-camera/rtsp-camera.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ compiler.warning_flags.all=-Wall -Wextra
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx". Get it from https://portal.sinric.pro/ -> Credentials
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" . Get it from https://portal.sinric.pro/ -> Credentials
#define CAMERA_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx". Get it from https://portal.sinric.pro/ -> Devices

#define BAUD_RATE 115200 // Change baudrate to your need

OV2640 cam;
CStreamer *streamer;
Expand Down Expand Up @@ -246,7 +246,7 @@ void handleStreaming() {

void setup()
{
Serial.begin(115200);
Serial.begin(BAUD_RATE);
while (!Serial); //wait for serial connection.

setupCamera();
Expand Down
29 changes: 5 additions & 24 deletions examples/ContactSensor/ContactSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define CONTACT_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

#define CONTACT_PIN 5 // PIN where contactsensor is connected to
// LOW = contact is open
// HIGH = contact is closed

bool myPowerState = true; // assume device is turned on
bool lastContactState = false;
unsigned long lastChange = 0;

Expand All @@ -57,8 +56,6 @@ unsigned long lastChange = 0;
* LOW = contactsensor is open
*/
void handleContactsensor() {
if (!myPowerState) return; // if device switched off...do nothing

unsigned long actualMillis = millis();
if (actualMillis - lastChange < 250) return; // debounce contact state transitions (same as debouncing a pushbutton)

Expand All @@ -69,26 +66,13 @@ void handleContactsensor() {
lastContactState = actualContactState; // update last known state
lastChange = actualMillis; // update debounce time
SinricProContactsensor &myContact = SinricPro[CONTACT_ID]; // get contact sensor device
myContact.sendContactEvent(actualContactState); // send event with actual state
bool success = myContact.sendContactEvent(actualContactState); // send event with actual state
if(!success) {
Serial.printf("Something went wrong...could not send Event to server!\r\n");
}
}
}

/**
* @brief Callback for setPowerState request
*
* @param deviceId String containing deviceId (useful if this callback used by multiple devices)
* @param[in] state bool true=turn on device / false=turn off device
* @param[out] state bool true=device turned on / false=device turned off
* @return true request handled properly
* @return false request can't be handled because some kind of error happened
*/
bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state?"on":"off");
myPowerState = state;
return true; // request handled properly
}


// setup function for WiFi connection
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
Expand Down Expand Up @@ -116,9 +100,6 @@ void setupSinricPro() {
// add device to SinricPro
SinricProContactsensor& myContact = SinricPro[CONTACT_ID];

// set callback function to device
myContact.onPowerState(onPowerState);

// setup SinricPro
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
Expand Down
2 changes: 1 addition & 1 deletion examples/DimSwitch/DimSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define DIMSWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

// we use a struct to store all states and values for our dimmable switch
struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/Fan/Fan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define FAN_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

// we use a struct to store all states and values for our fan
// fanSpeed (1..3)
Expand Down
2 changes: 1 addition & 1 deletion examples/GarageDoor/GarageDoor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define APP_KEY "YOUR_APP_KEY_HERE" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR_APP_SECRET_HERE" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define GARAGEDOOR_ID "YOUR_DEVICE_ID_HERE" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need


bool onDoorState(const String& deviceId, bool &doorState) {
Expand Down
2 changes: 1 addition & 1 deletion examples/Light/Light/Light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LIGHT_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

// define array of supported color temperatures
int colorTemperatureArray[] = {2200, 2700, 4000, 5500, 7000};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LIGHT_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

#define NUM_LEDS 1 // how much LEDs are on the stripe
#define LED_PIN 3 // LED stripe is connected to PIN 3
Expand Down
8 changes: 6 additions & 2 deletions examples/Light/RGB_LED_Stripe_5050/RGB_LED_Stripe_5050.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#endif

#include <Arduino.h>
#include <ESP8266WiFi.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
#include <WiFi.h>
#endif
#include <SinricPro.h>
#include <SinricProLight.h>

Expand All @@ -30,7 +34,7 @@
#define APP_KEY "YOUR-APPKEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APPSECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LIGHT_ID "YOUR-DEVICEID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need for serial log
#define BAUD_RATE 115200 // Change baudrate to your need for serial log

#define BLUE_PIN D5 // PIN for BLUE Mosfet - change this to your need (D5 = GPIO14 on ESP8266)
#define RED_PIN D6 // PIN for RED Mosfet - change this to your need (D6 = GPIO12 on ESP8266)
Expand Down
2 changes: 1 addition & 1 deletion examples/Lock/Lock/Lock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define APP_KEY "YOUR_APP_KEY_HERE" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR_APP_SECRET_HERE" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LOCK_ID "YOUR_DEVICE_ID_HERE" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need


bool onLockState(String deviceId, bool &lockState) {
Expand Down
7 changes: 5 additions & 2 deletions examples/Lock/Lock_with_feedback/Lock_with_feedback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define APP_KEY "YOUR_APP_KEY_HERE" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR_APP_SECRET_HERE" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LOCK_ID "YOUR_DEVICE_ID_HERE" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need

#if defined(ESP8266)
#define LOCK_PIN D1 // PIN where the lock is connected to: HIGH = locked, LOW = unlocked
Expand All @@ -64,7 +64,10 @@ void checkLockState() {
Serial.printf("Lock has been %s manually\r\n", currentLockState?"locked":"unlocked"); // print current lock state to serial
lastLockState = currentLockState; // update last known lock state
SinricProLock &myLock = SinricPro[LOCK_ID]; // get the LockDevice
myLock.sendLockStateEvent(currentLockState); // update LockState on Server
bool success = myLock.sendLockStateEvent(currentLockState); // update LockState on Server
if(!success) {
Serial.printf("Something went wrong...could not send Event to server!\r\n");
}
}

void setupWiFi() {
Expand Down
Loading

0 comments on commit 4918e67

Please sign in to comment.