Skip to content

Commit d6caff2

Browse files
committed
Air Quality Sensor support added. SinricProCamera added
1 parent e157172 commit d6caff2

File tree

9 files changed

+306
-7
lines changed

9 files changed

+306
-7
lines changed

changelog.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
# Changelog
2-
## Version 2.5.1
2+
3+
## Version 2.6.0
34
New:
4-
- added IP and MAC address to header
5+
- Devices
6+
- AirQualitySensor
7+
8+
- Examples
9+
- AirQualitySensor
10+
11+
Changed:
12+
- SinricProCamera device type added to support Camera. Camera example updated
513

614
## Version 2.5.0
715
New:
8-
- Speaker device supports SelectInput
16+
- Devices
17+
- Camera
18+
19+
- Examples
20+
- Camera
921

1022
## Version 2.4.0
1123
New:
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Example for how to use SinricPro Air Quality Sensor device
3+
*
4+
* If you encounter any issues:
5+
* - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md
6+
* - ensure all dependent libraries are installed
7+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide
8+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies
9+
* - open serial monitor and check whats happening
10+
* - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
11+
* - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one
12+
*/
13+
14+
// Uncomment the following line to enable serial debug output
15+
//#define ENABLE_DEBUG
16+
17+
#ifdef ENABLE_DEBUG
18+
#define DEBUG_ESP_PORT Serial
19+
#define NODEBUG_WEBSOCKETS
20+
#define NDEBUG
21+
#endif
22+
23+
24+
#include <Arduino.h>
25+
#ifdef ESP8266
26+
#include <ESP8266WiFi.h>
27+
#endif
28+
#ifdef ESP32
29+
#include <WiFi.h>
30+
#endif
31+
32+
#include "SinricPro.h"
33+
#include "SinricProAirQualitySensor.h"
34+
35+
#define WIFI_SSID ""
36+
#define WIFI_PASS ""
37+
#define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
38+
#define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
39+
#define DEVICE_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"
40+
#define BAUD_RATE 9600 // Change baudrate to your need
41+
42+
// Air quality sensor event dispatch time. Min is every 1 min.
43+
#define MIN (1000UL * 60 * 1)
44+
unsigned long dispatchTime = millis() + MIN;
45+
46+
// setup function for WiFi connection
47+
void setupWiFi() {
48+
Serial.printf("\r\n[Wifi]: Connecting");
49+
WiFi.begin(WIFI_SSID, WIFI_PASS);
50+
51+
while (WiFi.status() != WL_CONNECTED) {
52+
Serial.printf(".");
53+
delay(250);
54+
}
55+
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
56+
}
57+
58+
// setup function for SinricPro
59+
void setupSinricPro() {
60+
// add device to SinricPro
61+
SinricProAirQualitySensor& mySinricProAirQualitySensor = SinricPro[DEVICE_ID];
62+
63+
// set callback function to device
64+
65+
66+
// setup SinricPro
67+
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });
68+
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
69+
SinricPro.begin(APP_KEY, APP_SECRET);
70+
}
71+
72+
void setup() {
73+
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
74+
setupWiFi();
75+
setupSinricPro();
76+
}
77+
78+
void loop() {
79+
SinricPro.handle();
80+
81+
if((long)(millis() - dispatchTime) >= 0) {
82+
SinricProAirQualitySensor &mySinricProAirQualitySensor = SinricPro[DEVICE_ID]; // get sensor device
83+
84+
int pm1 =0;
85+
int pm2_5 = 0;
86+
int pm10=0;
87+
88+
mySinricProAirQualitySensor.sendAirQualityEvent(pm1, pm2_5, pm10, "PERIODIC_POLL");
89+
dispatchTime += MIN;
90+
Serial.println("Sending Air Quality event ..");
91+
}
92+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Example for how to use SinricPro Air Quality Sensor with Sharp Dust Sensor (GP2Y1014AU0F) connected to WemosD1 Mini
3+
* More information is here
4+
* https://github.com/sharpsensoruser/sharp-sensor-demos/wiki/Application-Guide-for-Sharp-GP2Y1014AU0F-Dust-Sensor
5+
*
6+
* If you encounter any issues:
7+
* - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md
8+
* - ensure all dependent libraries are installed
9+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide
10+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies
11+
* - open serial monitor and check whats happening
12+
* - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
13+
* - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one
14+
*/
15+
16+
// Uncomment the following line to enable serial debug output
17+
//#define ENABLE_DEBUG
18+
19+
#ifdef ENABLE_DEBUG
20+
#define DEBUG_ESP_PORT Serial
21+
#define NODEBUG_WEBSOCKETS
22+
#define NDEBUG
23+
#endif
24+
25+
#include <GP2YDustSensor.h> // https://github.com/luciansabo/GP2YDustSensor
26+
27+
#include <Arduino.h>
28+
#ifdef ESP8266
29+
#include <ESP8266WiFi.h>
30+
#endif
31+
#ifdef ESP32
32+
#include <WiFi.h>
33+
#endif
34+
35+
#include "SinricPro.h"
36+
#include "SinricProAirQualitySensor.h"
37+
38+
#define WIFI_SSID ""
39+
#define WIFI_PASS ""
40+
#define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
41+
#define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
42+
#define DEVICE_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"
43+
#define BAUD_RATE 9600 // Change baudrate to your need
44+
45+
// Air quality sensor event dispatch time. Min is every 1 min.
46+
#define MIN (1000UL * 60 * 1)
47+
unsigned long dispatchTime = millis() + MIN;
48+
49+
const uint8_t SHARP_LED_PIN = D5; // Sharp Dust/particle sensor Led Pin
50+
const uint8_t SHARP_VO_PIN = A0; // Sharp Dust/particle analog out pin used for reading
51+
52+
GP2YDustSensor dustSensor(GP2YDustSensorType::GP2Y1014AU0F, SHARP_LED_PIN, SHARP_VO_PIN);
53+
54+
// setup function for WiFi connection
55+
void setupWiFi() {
56+
Serial.printf("\r\n[Wifi]: Connecting");
57+
WiFi.begin(WIFI_SSID, WIFI_PASS);
58+
59+
while (WiFi.status() != WL_CONNECTED) {
60+
Serial.printf(".");
61+
delay(250);
62+
}
63+
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
64+
}
65+
66+
// setup function for SinricPro
67+
void setupSinricPro() {
68+
// add device to SinricPro
69+
SinricProAirQualitySensor& mySinricProAirQualitySensor = SinricPro[DEVICE_ID];
70+
71+
// set callback function to device
72+
73+
74+
// setup SinricPro
75+
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });
76+
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
77+
SinricPro.begin(APP_KEY, APP_SECRET);
78+
}
79+
80+
void setupDustSensor() {
81+
//dustSensor.setBaseline(0.4); // set no dust voltage according to your own experiments
82+
//dustSensor.setCalibrationFactor(1.1); // calibrate against precision instrument
83+
dustSensor.begin();
84+
}
85+
86+
87+
void setup() {
88+
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
89+
setupWiFi();
90+
setupSinricPro();
91+
setupDustSensor();
92+
}
93+
94+
95+
void loop() {
96+
SinricPro.handle();
97+
98+
if((long)(millis() - dispatchTime) >= 0) {
99+
Serial.print("Dust density: ");
100+
Serial.print(dustSensor.getDustDensity());
101+
Serial.print(" ug/m3; Running average: ");
102+
Serial.print(dustSensor.getRunningAverage());
103+
Serial.println(" ug/m3");
104+
105+
SinricProAirQualitySensor &mySinricProAirQualitySensor = SinricPro[DEVICE_ID]; // get air q sensor device
106+
107+
int pm1=0;
108+
int pm2_5 = dustSensor.getRunningAverage();
109+
int pm10=0;
110+
111+
mySinricProAirQualitySensor.sendAirQualityEvent(pm1, pm2_5, pm10, "PERIODIC_POLL");
112+
dispatchTime += MIN;
113+
114+
Serial.println("Sending Air Quality event ..");
115+
}
116+
}
613 KB
Loading

examples/Camera/Camera.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <WiFiClient.h>
3131

3232
#include "SinricPro.h"
33-
#include "SinricProSwitch.h"
33+
#include "SinricProCamera.h"
3434

3535
#include "SimStreamer.h"
3636
#include "OV2640Streamer.h"
@@ -75,7 +75,7 @@ bool onPowerState(const String &deviceId, bool &state) {
7575
// setup function for SinricPro
7676
void setupSinricPro() {
7777
// add device to SinricPro
78-
SinricProSwitch& mySwitch = SinricPro[CAMERA_ID];
78+
SinricProCamera& mySwitch = SinricPro[CAMERA_ID];
7979

8080
// set callback function to device
8181
mySwitch.onPowerState(onPowerState);

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"maintainer": true
1414
}
1515
],
16-
"version": "2.5.1",
16+
"version": "2.6.0",
1717
"frameworks": "arduino",
1818
"platforms": [
1919
"espressif8266",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SinricPro
2-
version=2.5.1
2+
version=2.6.0
33
author=Boris Jaeger <sivar2311@gmail.com>
44
maintainer=Boris Jaeger <sivar2311@gmail.com>
55
sentence=Library for https://sinric.pro - simple way to connect your device to alexa

src/SinricProAirQualitySensor.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2019 Sinric. All rights reserved.
3+
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
4+
*
5+
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
6+
*/
7+
8+
#ifndef _SINRICAIRQUALITYSENSOR_H_
9+
#define _SINRICAIRQUALITYSENSOR_H_
10+
11+
#include "SinricProDevice.h"
12+
13+
/**
14+
* @class SinricProAirQualitySensor
15+
* @brief Device to report air quality events
16+
*/
17+
class SinricProAirQualitySensor : public SinricProDevice {
18+
public:
19+
SinricProAirQualitySensor(const char* deviceId, unsigned long eventWaitTime=100);
20+
String getProductType() { return SinricProDevice::getProductType() + String("AIR_QUALITY_SENSOR"); }
21+
22+
// event
23+
bool sendAirQualityEvent(int pm1=0, int pm2_5=0, int pm10=0, String cause = "PERIODIC_POLL");
24+
private:
25+
};
26+
27+
SinricProAirQualitySensor::SinricProAirQualitySensor(const char* deviceId, unsigned long eventWaitTime) : SinricProDevice(deviceId, eventWaitTime) {}
28+
29+
/**
30+
* @brief Sending air quality to SinricPro server
31+
*
32+
* @param pm1 1.0 μm particle pollutant in μg/m3
33+
* @param pm2_5 2.5 μm particle pollutant in μg/m3
34+
* @param pm10 10 μm particle pollutant in μg/m3
35+
* @param cause (optional) `String` reason why event is sent (default = `"PERIODIC_POLL"`)
36+
* @return the success of sending the event
37+
* @retval true event has been sent successfully
38+
* @retval false event has not been sent, maybe you sent to much events in a short distance of time
39+
**/
40+
bool SinricProAirQualitySensor::sendAirQualityEvent(int pm1, int pm2_5, int pm10, String cause) {
41+
DynamicJsonDocument eventMessage = prepareEvent(deviceId, "airQuality", cause.c_str());
42+
JsonObject event_value = eventMessage["payload"]["value"];
43+
44+
event_value["pm1"] = limitValue(pm1, 0, 999);
45+
event_value["pm2_5"] = limitValue(pm2_5, 0, 999);
46+
event_value["pm10"] = limitValue(pm10, 0, 999);
47+
48+
return sendEvent(eventMessage);
49+
}
50+
51+
#endif
52+

src/SinricProCamera.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2019 Sinric. All rights reserved.
3+
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
4+
*
5+
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
6+
*/
7+
8+
#ifndef _SINRICCAMERA_H_
9+
#define _SINRICCAMERA_H_
10+
11+
#include "SinricProDevice.h"
12+
13+
/**
14+
* @class SinricProCamera
15+
* @brief Camera suporting basic on / off command
16+
**/
17+
class SinricProCamera : public SinricProDevice {
18+
public:
19+
SinricProCamera(const char* deviceId, unsigned long eventWaitTime=100);
20+
String getProductType() { return SinricProDevice::getProductType() + String("CAMERA"); }
21+
};
22+
23+
SinricProCamera::SinricProCamera(const char* deviceId, unsigned long eventWaitTime) : SinricProDevice(deviceId, eventWaitTime) {}
24+
25+
26+
#endif
27+

0 commit comments

Comments
 (0)