diff --git a/.gitignore b/.gitignore
index 0ea47b081..a19c9951c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+firmware/**
firmware/v*/**
firmware/releaseNote.txt
firmware/ezlopi/firmware/**
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e0ed1709c..c0e0e0101 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,8 +57,10 @@ foreach(component ${external_components_list})
LIST(APPEND ALL_COMPONENTS ${SUBDIRS})
endforeach()
-set(EXTRA_COMPONENT_DIRS ${ALL_COMPONENTS} ezlopi-user-config ezlopi-main) # add the list of directories 'SUBDIRS' to 'EXTRA_COMPONENT_DIRS'(ESP32 VARIABLES), links the external components
-message(STATUS "EXTRA_COMPONENTS_DIRS: ${EXTRA_COMPONENTS_DIRS}\r\n")
+LIST(APPEND ALL_COMPONENTS ezlopi-user-config ezlopi-main)
+
+set(EXTRA_COMPONENT_DIRS ${ALL_COMPONENTS} ) # add the list of directories 'SUBDIRS' to 'EXTRA_COMPONENT_DIRS'(ESP32 VARIABLES), links the external components
+message(STATUS "EXTRA_COMPONENTS_DIRS: ${EXTRA_COMPONENT_DIRS}\r\n")
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ##
project(Ezlo_Pi_v3x)
diff --git a/README.md b/README.md
index 62142465e..ed97f5555 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,11 @@
[![GitHub issues](https://img.shields.io/github/issues/ezloteam/Ezlo_Pi)](https://github.com/ezloteam/Ezlo_Pi/issues) [![GitHub forks](https://img.shields.io/github/forks/ezloteam/Ezlo_Pi)](https://github.com/ezloteam/Ezlo_Pi/network)
-# ezlopi
+
+
+# EzloPi
EzloPi is a collaborative open-source project developed by Ezlo Innovation to enhance the functionalities of devices and platforms powered by the ESP32 chipset. It offers exceptional features that allow seamless configuration and control of ESP-based devices, empowering you to transform your automation concepts into reality.
Checkout our [website](https://www.ezlopi.com/) for further guide and examples
@@ -20,11 +24,11 @@ Checkout our [website](https://www.ezlopi.com/) for further guide and examples
# 1. Getting started
EzloPi features a [web-based configurator](https://config.ezlopi.com/) that allows you to easily configure your ESP32 device for various supported features. The web interface provides a user-friendly platform to set up relays, analog inputs, digital inputs, and I2C-based sensors on your ESP32 device with ease. Once configured, you can leverage our cloud and mobile app services to remotely control your device in real-time.
-![EzloPi web configurator](ezlop-doc/ezlopi_web_flasher.png)
+![EzloPi web configurator](ezlopi-doc/ezlopi_web_flasher.png)
# 2. Customizing and building EzloPi firmware in your local setup
It is required to have [ESP-IDF](https://github.com/espressif/esp-idf) installed in your machine.
-Install ESP-IDF with taking help from the docs [here](https://docs.espressif.com/projects/esp-idf/en/v4.4.4/esp32/). ESP-IDF version [v4.4.4-292-g7894f032f6-dirty](https://github.com/espressif/esp-idf/releases/tag/v4.4.4).
+Install ESP-IDF with taking help from the docs [here](https://docs.espressif.com/projects/esp-idf/en/v4.4.4/esp32/). ESP-IDF version [v4.4.6](https://github.com/espressif/esp-idf/releases/tag/v4.4.6).
### 1. Clone the Ezlo-Pi Repository from GitHub
@@ -34,9 +38,9 @@ Navigate to your terminal or bash shell and execute the following commands:
git clone --recursive git@github.com:ezloteam/Ezlo_Pi.git ezlopi
cd ezlopi/firmware/ezlopi
```
-### 3. Configure the Projec
+### 2. Configure the Projec
You need to configure the project as per the chip type you are using. It needs to be modified the file ```sdkconfig``` , equivalent to making changes with ```idf.py menuconfig```.
-EzloPi needs to have constant set of configurations which are defined for different variants of chips and saved in the file such that ```sdkconfig..```. Copy the content of the chip you are using and paste it into ```sdkconfig```. For example if I want to build and run this firmware on ESP32C3 with 4MB of memory, I need to copy content of ```[sdkconfig.esp32c3.4mb](sdkconfig.esp32c3.4mb)``` into ```sdkconfig``` or rename the file ```sdkconfig.esp32c3.4mb``` to ```sdkconfig```, clean the existing build with ```idf.py fullclean``` and then build as mentioned at #2. The list of pre-defined ```sdkconfig``` for different varients of ESP32 are listed as :
+EzloPi needs to have constant set of configurations which are defined for different variants of chips and saved in the file such that ```sdkconfig..```. Copy the content of the chip you are using and paste it into ```sdkconfig```. For example if I want to build and run this firmware on ESP32C3 with 4MB of memory, I need to copy content of [sdkconfig.esp32c3.4mb](sdkconfig.esp32c3.4mb) into ```sdkconfig``` or rename the file ```sdkconfig.esp32c3.4mb``` to ```sdkconfig```, and then build as mentioned at #2. The list of pre-defined ```sdkconfig``` for different variants of ESP32 are listed as :
* __[ESP32 4MB Standard](sdkconfig.esp32.4mb)__
* __[ESP32-S3 4MB ](sdkconfig.esp32s3.4mb)__
@@ -44,7 +48,7 @@ EzloPi needs to have constant set of configurations which are defined for differ
* __[ESP32-C3 4MB](sdkconfig.esp32c3.4mb)__
-### 2. Build the Project
+### 3. Build the Project
Execute the following command to build the project:
@@ -52,7 +56,7 @@ Execute the following command to build the project:
idf.py build
```
-### 3. Flash the Firmware
+### 4. Flash the Firmware
To flash the firmware, use the following command:
@@ -60,7 +64,7 @@ To flash the firmware, use the following command:
idf.py -p -b flash
```
-### 4. Open Serial Monitor
+### 5. Open Serial Monitor
To open the serial monitor, use the following command:
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
new file mode 100644
index 000000000..3725b33ca
--- /dev/null
+++ b/RELEASE_NOTES.md
@@ -0,0 +1,190 @@
+
+
+
+# RELEASE NOTES
+
+## Supported Ezlo Cloud APIs
+
+1. [Items](https://api.ezlo.com/hub/items_api/index.html)
+ - [hub.items.list](https://api.ezlo.com/hub/items_api/index.html#hubitemslist)
+ - [hub.item.value.set (single item)](https://api.ezlo.com/hub/items_api/index.html#hubitemvalueset-single-item)
+
+2. [Devices](https://api.ezlo.com/hub/devices_api/index.html)
+ - [hub.devices.list](https://api.ezlo.com/hub/devices_api/index.html#hubdeviceslist)
+ - [hub.device.name.set](https://api.ezlo.com/hub/devices_api/index.html#hubdevicenameset)
+ - [hub.device.room.set](https://api.ezlo.com/hub/devices_api/index.html#hubdeviceroomset)
+
+3. [Device Settings](https://api.ezlo.com/hub/settings_api/index.html)
+ - [hub.device.settings.list](https://api.ezlo.com/hub/settings_api/index.html#hubdevicesettingslist)
+ - [hub.device.setting.value.set](https://api.ezlo.com/hub/settings_api/index.html#hubdevicesettingvalueset)
+ - [hub.device.setting.reset](https://api.ezlo.com/hub/settings_api/index.html#hubdevicesettingreset)
+
+4. [Room](https://api.ezlo.com/hub/room/index.html)
+ - [hub.room.list](https://api.ezlo.com/hub/room/index.html#hubroomlist)
+ - [hub.room.create](https://api.ezlo.com/hub/room/index.html#hubroomcreate)
+ - [hub.room.name.set](https://api.ezlo.com/hub/room/index.html#hubroomnameset)
+ - [hub.room.get](https://api.ezlo.com/hub/room/index.html#hubroomget)
+ - [hub.room.delete](https://api.ezlo.com/hub/room/index.html#hubroomdelete)
+
+5. [Common commands](https://api.ezlo.com/hub/common/index.html)
+ - [hub.info.get](https://api.ezlo.com/hub/common/index.html#hubinfoget)
+ - [hub.reboot](https://api.ezlo.com/hub/common/index.html#hubreboot)
+
+6. [Network](https://log.ezlo.com/new/hub/network/)
+ - [hub.network.get](https://log.ezlo.com/new/hub/network/#hubnetworkget)
+ - [hub.network.wifi.scan.start](https://log.ezlo.com/new/hub/network/#hubnetworkwifiscanstart)
+ - [hub.network.wifi.scan.stop](https://log.ezlo.com/new/hub/network/#hubnetworkwifiscanstop)
+
+
+7. [House Modes commands](https://api.ezlo.com/hub/house_modes_manager/index.html#house-modes-commands)
+ - [hub.modes.get](https://api.ezlo.com/hub/house_modes_manager/index.html#hubmodesget)
+ - [hub.modes.current.get](https://api.ezlo.com/hub/house_modes_manager/index.html#hubmodescurrentget)
+ - [hub.modes.switch](https://api.ezlo.com/hub/house_modes_manager/index.html#hubmodesswitch)
+
+
+8. [Broadcasts](https://api.ezlo.com/hub/broadcasts/index.html)
+ - [hub.item.updated](https://api.ezlo.com/hub/broadcasts/index.html#hubitemupdated)
+ - [hub.room.created](https://api.ezlo.com/hub/broadcasts/index.html#hubroomcreated)
+ - [hub.room.deleted](https://api.ezlo.com/hub/broadcasts/index.html#hubroomdeleted)
+ - [hub.room.reordered](https://api.ezlo.com/hub/broadcasts/index.html#hubroomreordered)
+ - [hub.room.edited](https://api.ezlo.com/hub/broadcasts/index.html#hubroomedited)
+ - [hub.scene.added](https://api.ezlo.com/hub/broadcasts/index.html#hubsceneadded)
+ - [hub.scene.deleted](https://api.ezlo.com/hub/broadcasts/index.html#hubscenedeleted)
+ - [hub.scene.changed](https://api.ezlo.com/hub/broadcasts/index.html#hubscenechanged)
+ - [hub.scene.run.progress](https://api.ezlo.com/hub/broadcasts/index.html#hubscenerunprogress)
+ - [hub.network.wifi.scan.progress](https://api.ezlo.com/hub/broadcasts/index.html#hubnetworkwifiscanprogress)
+ - [hub.device.setting.updated](https://api.ezlo.com/hub/broadcasts/index.html#hubdevicesettingupdated)
+
+9. [Scenes](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html)
+ - [hub.scenes.create](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenescreate)
+ - [hub.scenes.get](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesget)
+ - [hub.scenes.list](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubsceneslist)
+ - [hub.scenes.edit](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesedit)
+ - [hub.scenes.delete](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesdelete)
+ - [hub.scenes.block.data.list](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesblockdatalist)
+ - [hub.scenes.enabled.set](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesenabledset)
+ - [hub.scenes.notification.add](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesnotificationadd)
+ - [hub.scenes.notification.remove](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesnotificationremove)
+ - [hub.scenes.run](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesrun)
+ - [hub.scenes.name.set](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesnameset)
+ - [hub.scenes.expressions.set](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesexpressionsset)
+ - [hub.scenes.expressions.delete](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesexpressionsdelete)
+ - [hub.scenes.expressions.list](https://api.ezlo.com/hub/scenes/local_scenes_api/index.html#hubscenesexpressionslist)
+
+
+10. [Scenes : When blocks](https://api.ezlo.com/hub/scenes/when_blocks/index.html)
+ - [isItemState](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isitemstate)
+ - [isItemStateChanged](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isitemstatechanged)
+ - [isInterval](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isinterval)
+ - [isSunState](https://api.ezlo.com/hub/scenes/when_blocks/index.html#issunstate)
+ - [isOnce](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isonce)
+ - [isDateRange](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isdaterange)
+ - [isDeviceState](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isdevicestate)
+ - [isSceneState](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isscenestate)
+ - [isCloudState](https://api.ezlo.com/hub/scenes/when_blocks/index.html#iscloudstate)
+ - [compareNumbers](https://api.ezlo.com/hub/scenes/when_blocks/index.html#comparenumbers)
+ - [compareNumberRange](https://api.ezlo.com/hub/scenes/when_blocks/index.html#comparenumberrange)
+ - [compareStrings](https://api.ezlo.com/hub/scenes/when_blocks/index.html#comparestrings)
+ - [stringOperation](https://api.ezlo.com/hub/scenes/when_blocks/index.html#stringoperation)
+ - [inArray](https://api.ezlo.com/hub/scenes/when_blocks/index.html#inarray)
+ - [compareValues](https://api.ezlo.com/hub/scenes/when_blocks/index.html#comparevalues)
+ - [hasAtLeastOneDictionaryValue](https://api.ezlo.com/hub/scenes/when_blocks/index.html#hasatleastonedictionaryvalue)
+ - [isFirmwareUpdateState](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isfirmwareupdatestate)
+ - [isDictionaryChanged](https://api.ezlo.com/hub/scenes/when_blocks/index.html#isdictionarychanged)
+ - [and](https://api.ezlo.com/hub/scenes/when_blocks/index.html#and)
+ - [not](https://api.ezlo.com/hub/scenes/when_blocks/index.html#not)
+ - [or](https://api.ezlo.com/hub/scenes/when_blocks/index.html#or)
+ - [xor](https://api.ezlo.com/hub/scenes/when_blocks/index.html#xor)
+
+11. [Scenes : Action blocks](https://api.ezlo.com/hub/scenes/action_blocks/index.html#action-blocks)
+ - [setItemValue](https://api.ezlo.com/hub/scenes/action_blocks/index.html#setitemvalue)
+ - [sendHttpRequest](https://api.ezlo.com/hub/scenes/action_blocks/index.html#sendhttprequest)
+ - [runCustomScript](https://api.ezlo.com/hub/scenes/action_blocks/index.html#runcustomscript)
+ - [rebootHub](https://api.ezlo.com/hub/scenes/action_blocks/index.html#reboothub)
+ - [resetHub](https://api.ezlo.com/hub/scenes/action_blocks/index.html#resethub)
+
+
+## Supported Sensors
+
+
+1. MPU6050 Accelerometer and Gyroscope
+2. ADXL345 3-Axis Accelerometer
+3. GY-271 Magnetometer
+4. LTR303ALS Luminosity sensor
+5. RMT SK6812
+6. BMP680 I2C Sensor
+7. BMP280 I2C Sensor
+8. DHT11 Temperature Humidity Sensor
+9. DHT22 Temperature Humidity Sensor
+10. Potentiometer
+11. Internal Hall Effect Sensor
+12. PIR Sensor
+13. Parallax 2-Axis Joystick
+14. MB1013 Sonar
+15. PWM Generic Load
+16. Touch Switch TTP223B (Toggle)
+17. Ultrasonic Sensor HC SR04
+18. LDR Digital and analog Sensor
+19. Water Leak Sensor
+20. GY61 3-Axis Accelerometer
+21. GXHTC3 - RH and T Sensor
+22. DS18B20 Temperature Sensor
+23. JSN SR04T Water Level Sensor
+24. Soil Moisture Sensor
+25. Turbidity Sensor
+26. Proximity Sensor
+27. Touch switch TPP 223B (Momentary)
+28. Servo Motor MG996R
+29. SK6812 RGB LEDs
+30. TCS230 Sensor
+31. FC28 Soil Moisture Sensor
+32. Shunt voltmeter
+33. UV Intensity Sensor
+34. TSL2561 Luminosity Sensor
+35. CS712TELC 05B Current Sensor
+36. HX711 Load Cell
+37. MQ4 Methane Gas Sensor
+38. MQ2 LPG Gas Sensor
+39. MQ3 Alcohol Sensor
+40. MQ8 H2 Gas Sensor
+41. MQ135 NH3 Gas Sensor
+42. GPS GYGPS6MV2
+43. YFS201 flowmeter
+44. Flex Resistor
+45. Force Sensitive Resistor
+46. KY026 Flame Sensor
+47. MQ6 LPG Detector
+48. Vibration Sensor
+49. Reed Switch
+50. MQ7 CO Detector
+51. MQ9 LPG Detector
+52. Float Switch
+53. R307 Fingerprint Module
+54. HLK-LD2410B Presence Sensor
+55. ENS160 gas sensor
+56. ZE08 ch02 gas sensor
+
+## Supported Controllable Devices
+1. PWM Dimmable
+2. RGB Dimmable
+3. Smart Plug / Relay
+4. Servo Mot0r
+5. Addressable LEDs
+
+## Firmware Features
+### BLE WiFi Onboarding
+BLE (Bluetooth Low Energy) WiFi on-boarding for EzloPi Devices simplifies the process of connecting EzloPi devices to a WiFi network. Using BLE technology, the device can initiate a secure and user-friendly on-boarding process without the need for direct user input on the device.
+### BLE Provisioning
+BLE provisioning for EzloPi devices enhances user convenience by providing a wireless and user-friendly method for initial setup, eliminating the need for complex manual configurations directly on the device.
+### BLE Pin Configurations
+BLE Configuration simplifies the process of configuring the GPIOs of a hardware microcontroller employed by EzloPi, enhancing user convenience.
+### OTA
+This feature allows for convenient and remote firmware upgrades, ensuring that EzloPi devices can receive the latest software improvements and enhancements without the need for manual intervention or physical access.
+
+## Local Meshbot (Scene)
+Scenes provide the possibility to make the relations between devices and make some actions with them. A scene consists of "conditions" and "actions" represented by (when blocks and action blocks respectively. All of them, except action groups, have Json Array representation.
+
+In the perfect case when and exceptions ("conditions") block must form Abstract Syntax Tree (AST) from the Json and be executable. Currently, it's represented as a list of possible single-argument function.
+then and else (action) blocks contain the list of actions. Each functional element actually is the item. As far as you can see there are read only items such as : temperature, pressure, humidity, etc. and there are read-write items : switch, dimmer, light(switch), doorlock, etc...
\ No newline at end of file
diff --git a/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.c b/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.c
index 55afdf8b9..f839a316c 100644
--- a/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.c
+++ b/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.c
@@ -216,6 +216,7 @@ const char *scene_status_finished_str = "finished";
const char *scene_status_partially_finished_str = "partially_finished";
const char *scene_status_failed_str = "failed";
const char *scene_status_stopped_str = "stopped";
+
const char *ezlopi_valueformatted_str = "valueFormatted";
const char *ezlopi_value_default_str = "valueDefault";
const char *ezlopi_text_str = "text";
@@ -258,6 +259,7 @@ const char *ezlopi_service_str = "service";
const char *ezlopi_alarmed_str = "alarmed";
const char *ezlopi_timeIsLeft_str = "timeIsLeft";
const char *ezlopi_sources_str = "sources";
+const char *ezlopi_source_str = "source";
const char *ezlopi_timestamp_str = "timestamp";
const char *ezlopi_Home_str = "Home";
const char *ezlopi_Away_str = "Away";
@@ -265,4 +267,6 @@ const char *ezlopi_Night_str = "Night";
const char *ezlopi_Vacation_str = "Vacation";
const char *ezlopi_houseMode_str = "houseMode";
+const char *ezlopi_client_id_str = "client_id";
+
#endif // __EZLOPI_CLOUD_KEYWORDS_H__
diff --git a/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.h b/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.h
index b1820ca74..e5a040ccc 100644
--- a/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.h
+++ b/ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.h
@@ -107,6 +107,7 @@ extern const char* ezlopi_unreachable_reasons_str;
extern const char* ezlopi_unreachable_actions_str;
extern const char* ezlopi_manual_device_adding_str;
extern const char* ezlopi_enum_str;
+
extern const char* ezlopi_has_getter_str;
extern const char* ezlopi_has_setter_str;
extern const char* ezlopi_scale_str;
@@ -211,6 +212,7 @@ extern const char* ezlopi_baud_str;
extern const char* ezlopi_baud_rate_str;
extern const char* ezlopi_sceneId_str;
extern const char* ezlopi_changed_by_str;
+
extern const char* scene_status_started_str;
extern const char* scene_status_finished_str;
extern const char* scene_status_partially_finished_str;
@@ -218,9 +220,7 @@ extern const char* scene_status_failed_str;
extern const char* scene_status_stopped_str;
extern const char* ezlopi_armed_str;
extern const char* ezlopi_subtype_str;
-extern const char* ezlopi_scale_str;
-extern const char* ezlopi_enum_str;
-extern const char* ezlopi_valueformatted_str;
+
extern const char* ezlopi_value_default_str;
extern const char* ezlopi_text_str;
extern const char* ezlopi_label_str;
@@ -268,4 +268,7 @@ extern const char* ezlopi_Night_str;
extern const char* ezlopi_Vacation_str;
extern const char* ezlopi_houseMode_str;
+extern const char* ezlopi_client_id_str;
+extern const char* ezlopi_source_str;
+
#endif // __EZLOPI_CLOUD_KEYWORDS_H__
diff --git a/ezlopi-cloud/ezlopi-cloud-items/ezlopi_cloud_items.c b/ezlopi-cloud/ezlopi-cloud-items/ezlopi_cloud_items.c
index 417d5e2bf..17558bcaa 100644
--- a/ezlopi-cloud/ezlopi-cloud-items/ezlopi_cloud_items.c
+++ b/ezlopi-cloud/ezlopi-cloud-items/ezlopi_cloud_items.c
@@ -16,9 +16,9 @@
#include "ezlopi_service_webprov.h"
-static cJSON *ezlopi_device_create_item_table_from_prop(l_ezlopi_item_t *item_properties)
+static cJSON* ezlopi_device_create_item_table_from_prop(l_ezlopi_item_t* item_properties)
{
- cJSON *cj_item_properties = cJSON_CreateObject();
+ cJSON* cj_item_properties = cJSON_CreateObject();
if (cj_item_properties)
{
char tmp_string[64];
@@ -49,23 +49,23 @@ static cJSON *ezlopi_device_create_item_table_from_prop(l_ezlopi_item_t *item_pr
return cj_item_properties;
}
-void items_list_v3(cJSON *cj_request, cJSON *cj_response)
+void items_list_v3(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
- cJSON *cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
- cJSON *cj_items_array = cJSON_AddArrayToObject(cj_result, ezlopi_items_str);
+ cJSON* cj_items_array = cJSON_AddArrayToObject(cj_result, ezlopi_items_str);
if (cj_items_array)
{
- cJSON *params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
+ cJSON* params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (params != NULL)
{
- cJSON *device_ids_array = cJSON_GetObjectItem(params, ezlopi_device_ids_str);
+ cJSON* device_ids_array = cJSON_GetObjectItem(params, ezlopi_device_ids_str);
if (device_ids_array != NULL)
{
@@ -73,23 +73,23 @@ void items_list_v3(cJSON *cj_request, cJSON *cj_response)
{
if (cJSON_GetArraySize(device_ids_array) > 0)
{
- cJSON *device_id;
+ cJSON* device_id;
cJSON_ArrayForEach(device_id, device_ids_array)
{
if (cJSON_IsString(device_id))
{
- char *device_id_str = device_id->valuestring;
+ char* device_id_str = device_id->valuestring;
uint32_t device_id = strtol(device_id_str, NULL, 16);
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
while (curr_device)
{
if (curr_device->cloud_properties.device_id == device_id)
{
- l_ezlopi_item_t *curr_item = curr_device->items;
+ l_ezlopi_item_t* curr_item = curr_device->items;
while (curr_item)
{
- cJSON *cj_item_properties = ezlopi_device_create_item_table_from_prop(curr_item);
+ cJSON* cj_item_properties = ezlopi_device_create_item_table_from_prop(curr_item);
if (cj_item_properties)
{
if (!cJSON_AddItemToArray(cj_items_array, cj_item_properties))
@@ -111,13 +111,13 @@ void items_list_v3(cJSON *cj_request, cJSON *cj_response)
}
else
{
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
while (curr_device)
{
- l_ezlopi_item_t *curr_item = curr_device->items;
+ l_ezlopi_item_t* curr_item = curr_device->items;
while (curr_item)
{
- cJSON *cj_item_properties = ezlopi_device_create_item_table_from_prop(curr_item);
+ cJSON* cj_item_properties = ezlopi_device_create_item_table_from_prop(curr_item);
if (cj_item_properties)
{
@@ -138,25 +138,25 @@ void items_list_v3(cJSON *cj_request, cJSON *cj_response)
}
}
-void items_set_value_v3(cJSON *cj_request, cJSON *cj_response)
+void items_set_value_v3(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
- cJSON *cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
+ cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cj_params)
{
- char *item_id_str = 0;
+ char* item_id_str = 0;
CJSON_GET_VALUE_STRING(cj_params, ezlopi__id_str, item_id_str);
int item_id = strtol(item_id_str, NULL, 16);
TRACE_S("item_id: %X", item_id);
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
uint32_t found_item = 0;
while (curr_device)
{
- l_ezlopi_item_t *curr_item = curr_device->items;
+ l_ezlopi_item_t* curr_item = curr_device->items;
while (curr_item)
{
if (item_id == curr_item->cloud_properties.item_id)
@@ -176,26 +176,26 @@ void items_set_value_v3(cJSON *cj_request, cJSON *cj_response)
}
}
-void items_update_v3(cJSON *cj_request, cJSON *cj_response)
+void items_update_v3(cJSON* cj_request, cJSON* cj_response)
{
- cJSON *cjson_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
+ cJSON* cjson_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cjson_params)
{
- char *item_id_str = NULL;
+ char* item_id_str = NULL;
CJSON_GET_VALUE_STRING(cjson_params, ezlopi__id_str, item_id_str);
int item_id = strtol(item_id_str, NULL, 16);
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
while (curr_device)
{
- l_ezlopi_item_t *curr_item = curr_device->items;
+ l_ezlopi_item_t* curr_item = curr_device->items;
while (curr_item)
{
if (item_id == curr_item->cloud_properties.item_id)
{
cJSON_AddStringToObject(cj_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
cJSON_AddStringToObject(cj_response, ezlopi_msg_subclass_str, method_hub_item_updated);
- cJSON *cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
char tmp_string[64];
@@ -229,18 +229,18 @@ void items_update_v3(cJSON *cj_request, cJSON *cj_response)
}
}
-cJSON *ezlopi_cloud_items_updated_from_devices_v3(l_ezlopi_device_t *device, l_ezlopi_item_t *item)
+cJSON* ezlopi_cloud_items_updated_from_devices_v3(l_ezlopi_device_t* device, l_ezlopi_item_t* item)
{
- cJSON *cjson_response = cJSON_CreateObject();
+ cJSON* cjson_response = cJSON_CreateObject();
if (cjson_response)
{
if (NULL != item)
{
cJSON_AddStringToObject(cjson_response, ezlopi_msg_subclass_str, method_hub_item_updated);
- cJSON_AddNumberToObject(cjson_response, ezlopi_msg_id_str, web_provisioning_get_message_count());
+ cJSON_AddNumberToObject(cjson_response, ezlopi_msg_id_str, ezlopi_service_web_provisioning_get_message_count());
cJSON_AddStringToObject(cjson_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
- cJSON *cj_result = cJSON_AddObjectToObject(cjson_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cjson_response, ezlopi_result_str);
if (cj_result)
{
char tmp_string[64];
diff --git a/ezlopi-cloud/ezlopi-cloud-registration/ezlopi_cloud_registration.c b/ezlopi-cloud/ezlopi-cloud-registration/ezlopi_cloud_registration.c
index 63c33ff6f..30be7e399 100644
--- a/ezlopi-cloud/ezlopi-cloud-registration/ezlopi_cloud_registration.c
+++ b/ezlopi-cloud/ezlopi-cloud-registration/ezlopi_cloud_registration.c
@@ -12,19 +12,19 @@
#include "ezlopi_core_websocket_client.h"
#include "ezlopi_core_event_group.h"
-static void registration_process(void *pv);
+static void registration_process(void* pv);
void registration_init(void)
{
xTaskCreate(registration_process, "registration_process", 2 * 2048, NULL, 2, NULL);
}
-void register_repeat(cJSON *cj_request, cJSON *cj_response)
+void register_repeat(cJSON* cj_request, cJSON* cj_response)
{
registration_init();
}
-void registered(cJSON *cj_request, cJSON *cj_response)
+void registered(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
@@ -32,9 +32,9 @@ void registered(cJSON *cj_request, cJSON *cj_response)
ezlopi_event_group_set_event(EZLOPI_EVENT_NMA_REG);
}
-static void registration_process(void *pv)
+static void registration_process(void* pv)
{
- cJSON *cj_register = cJSON_CreateObject();
+ cJSON* cj_register = cJSON_CreateObject();
if (cj_register)
{
char mac_str[18];
@@ -42,11 +42,13 @@ static void registration_process(void *pv)
esp_read_mac(mac_addr, ESP_MAC_WIFI_STA);
snprintf(mac_str, sizeof(mac_str), "%02X:%02X:%02X:%02X:%02X:%02X",
- mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
+ mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
cJSON_AddStringToObject(cj_register, "id", "__ID__");
cJSON_AddStringToObject(cj_register, ezlopi_method_str, "register");
- cJSON *cj_params = cJSON_AddObjectToObject(cj_register, ezlopi_params_str);
+
+ cJSON* cj_params = cJSON_AddObjectToObject(cj_register, ezlopi_params_str);
+
if (cj_params)
{
cJSON_AddStringToObject(cj_params, ezlopi_firmware_str, VERSION_STR);
@@ -62,9 +64,9 @@ static void registration_process(void *pv)
vTaskDelay(200 / portTICK_RATE_MS);
}
- while (0 >= ezlopi_event_group_wait_for_event(EZLOPI_EVENT_NMA_REG, 2000, false))
+ while (ezlopi_event_group_wait_for_event(EZLOPI_EVENT_NMA_REG, 2000, false) <= 0)
{
- web_provisioning_send_to_nma_websocket(cj_register, TRACE_TYPE_B);
+ ezlopi_service_web_provisioning_send_to_nma_websocket(cj_register, TRACE_TYPE_B);
}
cJSON_Delete(cj_register);
diff --git a/ezlopi-cloud/ezlopi-cloud-scenes/CMakeLists.txt b/ezlopi-cloud/ezlopi-cloud-scenes/CMakeLists.txt
index 8074f68b1..6aab9f05d 100644
--- a/ezlopi-cloud/ezlopi-cloud-scenes/CMakeLists.txt
+++ b/ezlopi-cloud/ezlopi-cloud-scenes/CMakeLists.txt
@@ -1,5 +1,5 @@
file(GLOB_RECURSE src_files "*.c*")
-idf_component_register(SRCS "ezlopi_cloud_scenes_block_data_list.c" "${src_files}"
+idf_component_register(SRCS "ezlopi_cloud_scenes_block_list.c" "ezlopi_cloud_scenes_block_data_list.c" "${src_files}"
INCLUDE_DIRS "."
REQUIRES ezlopi-core-factory-info ezlopi-util-trace json ezlopi-cloud-constants ezlopi-core-scenes)
diff --git a/ezlopi-cloud/ezlopi-cloud-scenes/ezlopi_cloud_scenes_block_list.c b/ezlopi-cloud/ezlopi-cloud-scenes/ezlopi_cloud_scenes_block_list.c
index 8bb4c3f26..41ec5ebf1 100644
--- a/ezlopi-cloud/ezlopi-cloud-scenes/ezlopi_cloud_scenes_block_list.c
+++ b/ezlopi-cloud/ezlopi-cloud-scenes/ezlopi_cloud_scenes_block_list.c
@@ -13,36 +13,36 @@
#include "ezlopi_cloud_constants.h"
#include "ezlopi_core_scenes_operators.h"
-static cJSON *__create_when_block_cjson(l_when_block_v2_t *when_block);
+static cJSON* __create_when_block_cjson(l_when_block_v2_t* when_block);
-static bool __found_item_in_field(l_fields_v2_t *field_node, uint32_t item_id);
-static cJSON *__add_scenes_blocks_by_device_ids(e_scenes_block_type_v2_t block_type, cJSON *cj_devices_array);
-static cJSON *__add_scenes_blocks_by_item_ids(e_scenes_block_type_v2_t block_type, l_ezlopi_item_t *item_list);
-static e_scenes_block_type_v2_t __get_block_type_and_create_block_array(cJSON *cj_result, char const **block_type_name, cJSON *cj_block_type);
+static bool __found_item_in_field(l_fields_v2_t* field_node, uint32_t item_id);
+static cJSON* __add_scenes_blocks_by_device_ids(e_scenes_block_type_v2_t block_type, cJSON* cj_devices_array);
+static cJSON* __add_scenes_blocks_by_item_ids(e_scenes_block_type_v2_t block_type, l_ezlopi_item_t* item_list);
+static e_scenes_block_type_v2_t __get_block_type_and_create_block_array(cJSON* cj_result, char const** block_type_name, cJSON* cj_block_type);
-void scenes_blocks_list(cJSON *cj_request, cJSON *cj_response)
+void scenes_blocks_list(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddItemReferenceToObject(cj_response, ezlopi__id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
- cJSON *cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
- cJSON *cj_paramas = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
+ cJSON* cj_paramas = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cj_paramas)
{
- cJSON *cj_block_type = cJSON_GetObjectItem(cj_paramas, ezlopi_blockType_str);
+ cJSON* cj_block_type = cJSON_GetObjectItem(cj_paramas, ezlopi_blockType_str);
if (cj_block_type && cj_block_type->valuestring)
{
- char *block_type_name = NULL;
- e_scenes_block_type_v2_t block_type = __get_block_type_and_create_block_array(cj_result, (const char **)&block_type_name, cj_block_type);
+ char* block_type_name = NULL;
+ e_scenes_block_type_v2_t block_type = __get_block_type_and_create_block_array(cj_result, (const char**)&block_type_name, cj_block_type);
if (block_type)
{
- cJSON *cj_devices_array = cJSON_GetObjectItem(cj_paramas, "devices");
+ cJSON* cj_devices_array = cJSON_GetObjectItem(cj_paramas, "devices");
if (cj_devices_array && (cJSON_Array == cj_devices_array->type))
{
- cJSON *cj_block_array = __add_scenes_blocks_by_device_ids(block_type, cj_devices_array);
+ cJSON* cj_block_array = __add_scenes_blocks_by_device_ids(block_type, cj_devices_array);
if (cj_block_array)
{
if (!cJSON_AddItemToObject(cj_result, block_type_name, cj_block_array))
@@ -57,24 +57,24 @@ void scenes_blocks_list(cJSON *cj_request, cJSON *cj_response)
}
}
-static void __add_block_options_and_fields_cjson(cJSON *cj_block, s_block_options_v2_t *block_options, l_fields_v2_t *fields_node)
+static void __add_block_options_and_fields_cjson(cJSON* cj_block, s_block_options_v2_t* block_options, l_fields_v2_t* fields_node)
{
- cJSON *cj_block_opt = cJSON_AddObjectToObject(cj_block, ezlopi_blockOptions_str);
- cJSON *cj_fields = cJSON_AddArrayToObject(cj_block, ezlopi_fields_str);
+ cJSON* cj_block_opt = cJSON_AddObjectToObject(cj_block, ezlopi_blockOptions_str);
+ cJSON* cj_fields = cJSON_AddArrayToObject(cj_block, ezlopi_fields_str);
if (cj_block_opt && cj_fields)
{
- cJSON *cj_method = cJSON_AddObjectToObject(cj_block_opt, ezlopi_method_str);
+ cJSON* cj_method = cJSON_AddObjectToObject(cj_block_opt, ezlopi_method_str);
if (cj_method)
{
cJSON_AddStringToObject(cj_method, ezlopi_name_str, block_options->method.name);
- cJSON *cj_args = cJSON_AddObjectToObject(cj_method, ezlopi_args_str);
+ cJSON* cj_args = cJSON_AddObjectToObject(cj_method, ezlopi_args_str);
if (cj_args)
{
while (fields_node)
{
cJSON_AddStringToObject(cj_args, fields_node->name, fields_node->name);
- cJSON *cj_field_obj = ezlopi_scene_cjson_get_field(fields_node);
+ cJSON* cj_field_obj = ezlopi_scene_cjson_get_field(fields_node);
if (!cJSON_AddItemToArray(cj_fields, cj_field_obj))
{
cJSON_Delete(cj_field_obj);
@@ -87,9 +87,9 @@ static void __add_block_options_and_fields_cjson(cJSON *cj_block, s_block_option
}
}
-static cJSON *__create_when_block_cjson(l_when_block_v2_t *when_block)
+static cJSON* __create_when_block_cjson(l_when_block_v2_t* when_block)
{
- cJSON *cj_when_block = NULL;
+ cJSON* cj_when_block = NULL;
if (when_block)
{
@@ -104,9 +104,9 @@ static cJSON *__create_when_block_cjson(l_when_block_v2_t *when_block)
return cj_when_block;
}
-static cJSON *__create_then_block_cjson(l_action_block_v2_t *then_block)
+static cJSON* __create_then_block_cjson(l_action_block_v2_t* then_block)
{
- cJSON *cj_then_block = NULL;
+ cJSON* cj_then_block = NULL;
if (then_block)
{
@@ -121,9 +121,9 @@ static cJSON *__create_then_block_cjson(l_action_block_v2_t *then_block)
return cj_then_block;
}
-static cJSON *__create_else_block_cjson(l_action_block_v2_t *else_block)
+static cJSON* __create_else_block_cjson(l_action_block_v2_t* else_block)
{
- cJSON *cj_else_block = NULL;
+ cJSON* cj_else_block = NULL;
if (else_block)
{
@@ -138,15 +138,19 @@ static cJSON *__create_else_block_cjson(l_action_block_v2_t *else_block)
return cj_else_block;
}
-static bool __found_item_in_field(l_fields_v2_t *field_node, uint32_t item_id)
+static bool __found_item_in_field(l_fields_v2_t* field_node, uint32_t item_id)
{
bool ret = false;
while (field_node)
{
if (EZLOPI_VALUE_TYPE_ITEM == field_node->value_type)
{
- uint32_t item_id_check = strtoul(field_node->value.value_string, NULL, 16);
- TRACE_D("item-id: %s | %08x", field_node->value.value_string, item_id);
+ uint32_t item_id_check = strtoul(field_node->field_value.u_value.value_string, NULL, 16);
+ TRACE_D("item-id: %s | %08x", field_node->field_value.u_value.value_string, item_id);
+
+ // uint32_t item_id_check = strtoul(field_node->value.value_string, NULL, 16);
+ // TRACE_D("item-id: %s | %08x", field_node->value.value_string, item_id);
+
if (item_id_check == item_id)
{
ret = 1;
@@ -160,12 +164,12 @@ static bool __found_item_in_field(l_fields_v2_t *field_node, uint32_t item_id)
return ret;
}
-static cJSON *__add_scenes_blocks_by_item_ids(e_scenes_block_type_v2_t block_type, l_ezlopi_item_t *item_list)
+static cJSON* __add_scenes_blocks_by_item_ids(e_scenes_block_type_v2_t block_type, l_ezlopi_item_t* item_list)
{
- cJSON *cj_block = NULL;
+ cJSON* cj_block = NULL;
while (item_list)
{
- l_scenes_list_v2_t *scene_node = ezlopi_scenes_get_scenes_head_v2();
+ l_scenes_list_v2_t* scene_node = ezlopi_scenes_get_scenes_head_v2();
while (scene_node)
{
TRACE_D("Here");
@@ -227,11 +231,11 @@ static cJSON *__add_scenes_blocks_by_item_ids(e_scenes_block_type_v2_t block_typ
return cj_block;
}
-static cJSON *__add_scenes_blocks_by_device_ids(e_scenes_block_type_v2_t block_type, cJSON *cj_devices_array)
+static cJSON* __add_scenes_blocks_by_device_ids(e_scenes_block_type_v2_t block_type, cJSON* cj_devices_array)
{
int device_id_idx = 0;
- cJSON *cj_device_id = NULL;
- cJSON *cj_block_array = NULL;
+ cJSON* cj_device_id = NULL;
+ cJSON* cj_block_array = NULL;
CJSON_TRACE("device array", cj_devices_array);
@@ -241,11 +245,11 @@ static cJSON *__add_scenes_blocks_by_device_ids(e_scenes_block_type_v2_t block_t
if (cj_device_id->valuestring)
{
uint32_t device_id = strtoul(cj_device_id->valuestring, NULL, 16);
- l_ezlopi_device_t *device_node = ezlopi_device_get_by_id(device_id);
+ l_ezlopi_device_t* device_node = ezlopi_device_get_by_id(device_id);
if (device_node)
{
TRACE_D("Here");
- cJSON *cj_block = __add_scenes_blocks_by_item_ids(block_type, device_node->items);
+ cJSON* cj_block = __add_scenes_blocks_by_item_ids(block_type, device_node->items);
if (cj_block)
{
if (NULL == cj_block_array)
@@ -272,7 +276,7 @@ static cJSON *__add_scenes_blocks_by_device_ids(e_scenes_block_type_v2_t block_t
return cj_block_array;
}
-static e_scenes_block_type_v2_t __get_block_type_and_create_block_array(cJSON *cj_result, char const **block_type_name, cJSON *cj_block_type)
+static e_scenes_block_type_v2_t __get_block_type_and_create_block_array(cJSON* cj_result, char const** block_type_name, cJSON* cj_block_type)
{
e_scenes_block_type_v2_t block_type = SCENE_BLOCK_TYPE_NONE;
diff --git a/ezlopi-cloud/ezlopi-cloud-settings/ezlopi_cloud_settings.c b/ezlopi-cloud/ezlopi-cloud-settings/ezlopi_cloud_settings.c
index 5e825f680..d07bdd6a8 100644
--- a/ezlopi-cloud/ezlopi-cloud-settings/ezlopi_cloud_settings.c
+++ b/ezlopi-cloud/ezlopi-cloud-settings/ezlopi_cloud_settings.c
@@ -11,24 +11,24 @@
#include "ezlopi_service_webprov.h"
-void ezlopi_device_settings_list_v3(cJSON *cj_request, cJSON *cj_response)
+void ezlopi_device_settings_list_v3(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
- cJSON *cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
- cJSON *cj_settings_array = cJSON_AddArrayToObject(cj_result, ezlopi_settings_str);
+ cJSON* cj_settings_array = cJSON_AddArrayToObject(cj_result, ezlopi_settings_str);
if (cj_settings_array)
{
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
while (curr_device)
{
- l_ezlopi_device_settings_v3_t *curr_setting = curr_device->settings;
+ l_ezlopi_device_settings_v3_t* curr_setting = curr_device->settings;
while (curr_setting)
{
- cJSON *cj_properties = cJSON_CreateObject();
+ cJSON* cj_properties = cJSON_CreateObject();
if (cj_properties)
{
char tmp_string[64];
@@ -50,24 +50,24 @@ void ezlopi_device_settings_list_v3(cJSON *cj_request, cJSON *cj_response)
}
}
}
-void ezlopi_device_settings_value_set_v3(cJSON *cj_request, cJSON *cj_response)
+void ezlopi_device_settings_value_set_v3(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
- cJSON *cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
+ cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cj_params)
{
- char *setting_id_str = 0;
+ char* setting_id_str = 0;
CJSON_GET_VALUE_STRING(cj_params, ezlopi__id_str, setting_id_str);
uint32_t setting_id = strtoul(setting_id_str, NULL, 16);
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
uint32_t found_setting = 0;
while (curr_device)
{
- l_ezlopi_device_settings_v3_t *curr_setting = curr_device->settings;
+ l_ezlopi_device_settings_v3_t* curr_setting = curr_device->settings;
while (curr_setting)
{
if (setting_id == curr_setting->cloud_properties.setting_id)
@@ -86,28 +86,28 @@ void ezlopi_device_settings_value_set_v3(cJSON *cj_request, cJSON *cj_response)
}
}
}
-void ezlopi_device_settings_reset_v3(cJSON *cj_request, cJSON *cj_response)
+void ezlopi_device_settings_reset_v3(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
- cJSON *cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
+ cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cj_params)
{
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
while (curr_device)
{
if (cJSON_HasObjectItem(cj_params, ezlopi_deviceId_str))
{
- char *device_id_str = 0;
+ char* device_id_str = 0;
CJSON_GET_VALUE_STRING(cj_params, ezlopi_deviceId_str, device_id_str);
int device_id = strtol(device_id_str, NULL, 16);
TRACE_E("device_id: %X", device_id);
if (device_id == curr_device->cloud_properties.device_id)
{
- l_ezlopi_device_settings_v3_t *curr_setting = curr_device->settings;
+ l_ezlopi_device_settings_v3_t* curr_setting = curr_device->settings;
while (curr_setting)
{
curr_setting->func(EZLOPI_SETTINGS_ACTION_RESET_SETTING, curr_setting, cj_params, curr_setting->user_arg);
@@ -118,11 +118,11 @@ void ezlopi_device_settings_reset_v3(cJSON *cj_request, cJSON *cj_response)
else if (cJSON_HasObjectItem(cj_params, ezlopi__id_str))
{
- char *setting_id_str = 0;
+ char* setting_id_str = 0;
CJSON_GET_VALUE_STRING(cj_params, ezlopi__id_str, setting_id_str);
uint32_t setting_id = strtol(setting_id_str, NULL, 16);
TRACE_E("setting_id: %X", setting_id);
- l_ezlopi_device_settings_v3_t *curr_setting = curr_device->settings;
+ l_ezlopi_device_settings_v3_t* curr_setting = curr_device->settings;
while (curr_setting)
{
if (setting_id == curr_setting->cloud_properties.setting_id)
@@ -141,18 +141,18 @@ void ezlopi_device_settings_reset_v3(cJSON *cj_request, cJSON *cj_response)
}
}
-cJSON *ezlopi_cloud_settings_updated_from_devices_v3(l_ezlopi_device_t *device, l_ezlopi_device_settings_v3_t *setting)
+cJSON* ezlopi_cloud_settings_updated_from_devices_v3(l_ezlopi_device_t* device, l_ezlopi_device_settings_v3_t* setting)
{
- cJSON *cjson_response = cJSON_CreateObject();
+ cJSON* cjson_response = cJSON_CreateObject();
if (cjson_response)
{
if (NULL != setting)
{
cJSON_AddStringToObject(cjson_response, ezlopi_msg_subclass_str, method_hub_device_setting_updated);
- cJSON_AddNumberToObject(cjson_response, ezlopi_msg_id_str, web_provisioning_get_message_count());
+ cJSON_AddNumberToObject(cjson_response, ezlopi_msg_id_str, ezlopi_service_web_provisioning_get_message_count());
cJSON_AddStringToObject(cjson_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
- cJSON *cj_result = cJSON_AddObjectToObject(cjson_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cjson_response, ezlopi_result_str);
if (cj_result)
{
char tmp_string[64];
diff --git a/ezlopi-components/lua/lua/lua.h b/ezlopi-components/lua/lua/lua.h
index 55c05dbfd..aba159a1b 100644
--- a/ezlopi-components/lua/lua/lua.h
+++ b/ezlopi-components/lua/lua/lua.h
@@ -212,7 +212,6 @@ LUA_API const char *(lua_pushvfstring)(lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring)(lua_State *L, const char *fmt, ...);
LUA_API void(lua_pushcclosure)(lua_State *L, lua_CFunction fn, int n);
-#warning "Compile and check the warning details, Krishna needs to resolve it. note: expected 'int' but argument is of type 'const char *'"
LUA_API void(lua_pushboolean)(lua_State *L, int b);
LUA_API void(lua_pushlightuserdata)(lua_State *L, void *p);
LUA_API int(lua_pushthread)(lua_State *L);
diff --git a/ezlopi-core/ezlopi-core-devices/ezlopi_core_device_value_updated.c b/ezlopi-core/ezlopi-core-devices/ezlopi_core_device_value_updated.c
index d0720cb38..2087c23cc 100644
--- a/ezlopi-core/ezlopi-core-devices/ezlopi_core_device_value_updated.c
+++ b/ezlopi-core/ezlopi-core-devices/ezlopi_core_device_value_updated.c
@@ -1,4 +1,5 @@
#include "ezlopi_core_devices_list.h"
+#include "ezlopi_core_ezlopi_broadcast.h"
#include "ezlopi_cloud_items.h"
#include "ezlopi_cloud_settings.h"
@@ -16,27 +17,34 @@ int ezlopi_device_value_updated_from_device_v3(l_ezlopi_item_t* item)
while (curr_device)
{
l_ezlopi_item_t* curr_item = curr_device->items;
+
while (curr_item)
{
if (item == curr_item)
{
cJSON* cj_response = ezlopi_cloud_items_updated_from_devices_v3(curr_device, item);
+
if (cj_response)
{
char* data_to_send = cJSON_Print(cj_response);
cJSON_Delete(cj_response);
+
if (data_to_send)
{
cJSON_Minify(data_to_send);
- ret = web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
- // ret = web_provisioning_send_to_nma_websocket(cj_response, TRACE_TYPE_D);
- free(data_to_send);
+ ret = ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data_to_send)) {
+ free(data_to_send);
+ }
}
}
+
break;
}
+
curr_item = curr_item->next;
}
+
curr_device = curr_device->next;
}
}
@@ -48,35 +56,40 @@ int ezlopi_device_value_updated_from_device_item_id_v3(uint32_t item_id)
{
int ret = 0;
- // if (item)
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
+ while (curr_device)
{
- l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
- while (curr_device)
+ l_ezlopi_item_t* curr_item = curr_device->items;
+
+ while (curr_item)
{
- l_ezlopi_item_t* curr_item = curr_device->items;
- while (curr_item)
+ if (item_id == curr_item->cloud_properties.item_id)
{
- if (item_id == curr_item->cloud_properties.item_id)
+ cJSON* cj_response = ezlopi_cloud_items_updated_from_devices_v3(curr_device, curr_item);
+
+ if (cj_response)
{
- cJSON* cj_response = ezlopi_cloud_items_updated_from_devices_v3(curr_device, curr_item);
- if (cj_response)
+ char* data_to_send = cJSON_Print(cj_response);
+ cJSON_Delete(cj_response);
+
+ if (data_to_send)
{
- char* data_to_send = cJSON_Print(cj_response);
- cJSON_Delete(cj_response);
- if (data_to_send)
+ cJSON_Minify(data_to_send);
+ ret = ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data_to_send))
{
- cJSON_Minify(data_to_send);
- ret = web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
- // ret = web_provisioning_send_to_nma_websocket(cj_response, TRACE_TYPE_D);
free(data_to_send);
}
}
- break;
}
- curr_item = curr_item->next;
+
+ break;
}
- curr_device = curr_device->next;
+
+ curr_item = curr_item->next;
}
+
+ curr_device = curr_device->next;
}
return ret;
@@ -101,12 +114,15 @@ int ezlopi_setting_value_updated_from_device_v3(l_ezlopi_device_settings_v3_t* s
{
char* data_to_send = cJSON_Print(cj_response);
cJSON_Delete(cj_response);
+
if (data_to_send)
{
cJSON_Minify(data_to_send);
- ret = web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
- free(data_to_send);
- // ret = web_provisioning_send_to_nma_websocket(cj_response, TRACE_TYPE_B);
+ ret = ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data_to_send))
+ {
+ free(data_to_send);
+ }
}
}
break;
@@ -139,12 +155,14 @@ int ezlopi_setting_value_updated_from_device_settings_id_v3(uint32_t setting_id)
{
char* data_to_send = cJSON_Print(cj_response);
cJSON_Delete(cj_response);
+
if (data_to_send)
{
cJSON_Minify(data_to_send);
- ret = web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
- free(data_to_send);
- // ret = web_provisioning_send_to_nma_websocket(cj_response, TRACE_TYPE_B);
+ ret = ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data_to_send)) {
+ free(data_to_send);
+ }
}
}
break;
@@ -168,7 +186,7 @@ int ezlopi_network_update_wifi_scan_process(cJSON* network_array)
{
cJSON_AddStringToObject(cjson_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
cJSON_AddStringToObject(cjson_response, ezlopi_msg_subclass_str, method_hub_network_wifi_scan_progress);
- cJSON_AddNumberToObject(cjson_response, ezlopi_msg_id_str, web_provisioning_get_message_count());
+ cJSON_AddNumberToObject(cjson_response, ezlopi_msg_id_str, ezlopi_service_web_provisioning_get_message_count());
cJSON* result = cJSON_AddObjectToObject(cjson_response, "result");
if (result)
{
@@ -179,7 +197,7 @@ int ezlopi_network_update_wifi_scan_process(cJSON* network_array)
if (data_to_send)
{
cJSON_Minify(data_to_send);
- ret = web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
+ ret = ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
}
else
{
diff --git a/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.c b/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.c
index 6ef3bcab0..6c493f40b 100644
--- a/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.c
+++ b/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.c
@@ -6,19 +6,19 @@
#include "ezlopi_cloud_items.h"
#include "ezlopi_cloud_constants.h"
-static l_ezlopi_device_t *l_device_head = NULL;
+static l_ezlopi_device_t* l_device_head = NULL;
static volatile uint32_t g_store_dev_config_with_id = 0;
static s_ezlopi_cloud_controller_t s_controller_information;
-static void ezlopi_device_parse_json_v3(cJSON *cj_config);
-static void ezlopi_device_free_single(l_ezlopi_device_t *device);
+static void ezlopi_device_parse_json_v3(cJSON* cj_config);
+static void ezlopi_device_free_single(l_ezlopi_device_t* device);
static void ezlopi_device_print_controller_cloud_information_v3(void);
-void ezlopi_device_name_set_by_device_id(uint32_t a_device_id, cJSON *cj_new_name)
+void ezlopi_device_name_set_by_device_id(uint32_t a_device_id, cJSON* cj_new_name)
{
if (a_device_id && cj_new_name && cj_new_name->valuestring)
{
- l_ezlopi_device_t *l_device_node = l_device_head;
+ l_ezlopi_device_t* l_device_node = l_device_head;
while (l_device_node)
{
if (a_device_id == l_device_node->cloud_properties.device_id)
@@ -30,22 +30,22 @@ void ezlopi_device_name_set_by_device_id(uint32_t a_device_id, cJSON *cj_new_nam
l_device_node = l_device_node->next;
}
- char *device_config_str = ezlopi_factory_info_v3_get_ezlopi_config();
+ char* device_config_str = ezlopi_factory_info_v3_get_ezlopi_config();
if (device_config_str)
{
- cJSON *cj_device_config = cJSON_Parse(device_config_str);
+ cJSON* cj_device_config = cJSON_Parse(device_config_str);
ezlopi_factory_info_v3_free(device_config_str);
if (cj_device_config)
{
- cJSON *cj_devices = cJSON_GetObjectItem(cj_device_config, ezlopi_dev_detail_str);
+ cJSON* cj_devices = cJSON_GetObjectItem(cj_device_config, ezlopi_dev_detail_str);
if (cj_devices)
{
uint32_t idx = 0;
- cJSON *cj_device = NULL;
+ cJSON* cj_device = NULL;
while (NULL != (cj_device = cJSON_GetArrayItem(cj_devices, idx)))
{
- cJSON *cj_device_id = cJSON_GetObjectItem(cj_device, ezlopi_device_id_str);
+ cJSON* cj_device_id = cJSON_GetObjectItem(cj_device, ezlopi_device_id_str);
if (cj_device_id && cj_device_id->valuestring)
{
uint32_t device_id = strtoul(cj_device_id->valuestring, NULL, 16);
@@ -61,7 +61,7 @@ void ezlopi_device_name_set_by_device_id(uint32_t a_device_id, cJSON *cj_new_nam
}
}
- char *update_device_config = cJSON_Print(cj_device_config);
+ char* update_device_config = cJSON_Print(cj_device_config);
cJSON_Delete(cj_device_config);
if (update_device_config)
{
@@ -74,19 +74,19 @@ void ezlopi_device_name_set_by_device_id(uint32_t a_device_id, cJSON *cj_new_nam
}
}
-s_ezlopi_cloud_controller_t *ezlopi_device_get_controller_information(void)
+s_ezlopi_cloud_controller_t* ezlopi_device_get_controller_information(void)
{
return &s_controller_information;
}
-l_ezlopi_device_t *ezlopi_device_get_head(void)
+l_ezlopi_device_t* ezlopi_device_get_head(void)
{
return l_device_head;
}
-l_ezlopi_device_t *ezlopi_device_get_by_id(uint32_t device_id)
+l_ezlopi_device_t* ezlopi_device_get_by_id(uint32_t device_id)
{
- l_ezlopi_device_t *device_node = l_device_head;
+ l_ezlopi_device_t* device_node = l_device_head;
while (device_node)
{
@@ -100,14 +100,14 @@ l_ezlopi_device_t *ezlopi_device_get_by_id(uint32_t device_id)
return device_node;
}
-l_ezlopi_device_t *ezlopi_device_add_device(cJSON *cj_device)
+l_ezlopi_device_t* ezlopi_device_add_device(cJSON* cj_device)
{
- l_ezlopi_device_t *new_device = malloc(sizeof(l_ezlopi_device_t));
+ l_ezlopi_device_t* new_device = malloc(sizeof(l_ezlopi_device_t));
if (new_device)
{
memset(new_device, 0, sizeof(l_ezlopi_device_t));
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
ASSIGN_DEVICE_NAME_V2(new_device, device_name);
@@ -118,7 +118,7 @@ l_ezlopi_device_t *ezlopi_device_add_device(cJSON *cj_device)
if (new_device->cloud_properties.device_id)
{
- l_ezlopi_device_t *curr_dev_node = l_device_head;
+ l_ezlopi_device_t* curr_dev_node = l_device_head;
while (curr_dev_node)
{
if (curr_dev_node->cloud_properties.device_id == new_device->cloud_properties.device_id)
@@ -148,7 +148,7 @@ l_ezlopi_device_t *ezlopi_device_add_device(cJSON *cj_device)
}
else
{
- l_ezlopi_device_t *curr_device = l_device_head;
+ l_ezlopi_device_t* curr_device = l_device_head;
while (curr_device->next)
{
curr_device = curr_device->next;
@@ -161,7 +161,7 @@ l_ezlopi_device_t *ezlopi_device_add_device(cJSON *cj_device)
return new_device;
}
-void ezlopi_device_free_device(l_ezlopi_device_t *device)
+void ezlopi_device_free_device(l_ezlopi_device_t* device)
{
if (device && l_device_head)
{
@@ -175,7 +175,7 @@ void ezlopi_device_free_device(l_ezlopi_device_t *device)
}
else
{
- l_ezlopi_device_t *curr_device = l_device_head;
+ l_ezlopi_device_t* curr_device = l_device_head;
while (curr_device->next)
{
TRACE_D("Device-ID: %08x", curr_device->next->cloud_properties.device_id);
@@ -183,7 +183,7 @@ void ezlopi_device_free_device(l_ezlopi_device_t *device)
{
TRACE_E("To free Device-ID: %08x", curr_device->next->cloud_properties.device_id);
- l_ezlopi_device_t *free_device = curr_device->next;
+ l_ezlopi_device_t* free_device = curr_device->next;
curr_device->next = curr_device->next->next;
free_device->next = NULL;
ezlopi_device_free_single(free_device);
@@ -196,14 +196,14 @@ void ezlopi_device_free_device(l_ezlopi_device_t *device)
}
}
-void ezlopi_device_free_device_by_item(l_ezlopi_item_t *item)
+void ezlopi_device_free_device_by_item(l_ezlopi_item_t* item)
{
if (item)
{
- l_ezlopi_device_t *device_node = l_device_head;
+ l_ezlopi_device_t* device_node = l_device_head;
while (device_node)
{
- l_ezlopi_item_t *item_node = device_node->items;
+ l_ezlopi_item_t* item_node = device_node->items;
while (item_node)
{
if (item_node == item)
@@ -220,14 +220,14 @@ void ezlopi_device_free_device_by_item(l_ezlopi_item_t *item)
}
}
-l_ezlopi_item_t *ezlopi_device_get_item_by_id(uint32_t item_id)
+l_ezlopi_item_t* ezlopi_device_get_item_by_id(uint32_t item_id)
{
- l_ezlopi_item_t *item_to_return = NULL;
- l_ezlopi_device_t *device_node = l_device_head;
+ l_ezlopi_item_t* item_to_return = NULL;
+ l_ezlopi_device_t* device_node = l_device_head;
while (device_node)
{
- l_ezlopi_item_t *item_node = device_node->items;
+ l_ezlopi_item_t* item_node = device_node->items;
while (item_node)
{
if (item_id == item_node->cloud_properties.item_id)
@@ -249,9 +249,9 @@ l_ezlopi_item_t *ezlopi_device_get_item_by_id(uint32_t item_id)
return item_to_return;
}
-l_ezlopi_item_t *ezlopi_device_add_item_to_device(l_ezlopi_device_t *device, int (*item_func)(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg))
+l_ezlopi_item_t* ezlopi_device_add_item_to_device(l_ezlopi_device_t* device, int (*item_func)(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg))
{
- l_ezlopi_item_t *new_item = NULL;
+ l_ezlopi_item_t* new_item = NULL;
if (device)
{
new_item = malloc(sizeof(l_ezlopi_item_t));
@@ -267,7 +267,7 @@ l_ezlopi_item_t *ezlopi_device_add_item_to_device(l_ezlopi_device_t *device, int
}
else
{
- l_ezlopi_item_t *curr_item = device->items;
+ l_ezlopi_item_t* curr_item = device->items;
while (curr_item->next)
{
curr_item = curr_item->next;
@@ -296,17 +296,17 @@ void ezlopi_device_prepare(void)
s_controller_information.status = "idle";
#if (EZLOPI_DEVICE_TYPE_GENERIC == EZLOPI_DEVICE_TYPE)
- char *config_string = ezlopi_factory_info_v3_get_ezlopi_config();
+ char* config_string = ezlopi_factory_info_v3_get_ezlopi_config();
#elif (EZLOPI_DEVICE_TYPE_TEST_DEVICE == EZLOPI_DEVICE_TYPE)
- char *config_string = ezlopi_config_test;
+ char* config_string = ezlopi_config_test;
#else
- char *config_string = ezlopi_factory_info_v3_get_ezlopi_config();
+ char* config_string = ezlopi_factory_info_v3_get_ezlopi_config();
#endif
if (config_string)
{
TRACE_D("Initial config:\r\n%s", config_string);
- cJSON *cj_config = cJSON_Parse(config_string);
+ cJSON* cj_config = cJSON_Parse(config_string);
// ezlopi_factory_info_v3_free(config_string);
if (cj_config)
{
@@ -314,7 +314,7 @@ void ezlopi_device_prepare(void)
if (g_store_dev_config_with_id)
{
- char *updated_config = cJSON_Print(cj_config);
+ char* updated_config = cJSON_Print(cj_config);
if (updated_config)
{
TRACE_D("Updated config:\r\n%s", config_string);
@@ -346,7 +346,7 @@ static void ezlopi_device_print_controller_cloud_information_v3(void)
TRACE_I("Status: %s", s_controller_information.status ? s_controller_information.status : ezlopi_null_str);
}
-static void ezlopi_device_print_interface_digital_io(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_digital_io(l_ezlopi_item_t* item)
{
TRACE_D(" |~~~|- item->interface.gpio.gpio_in.enable: %s", item->interface.gpio.gpio_in.enable ? ezlopi_true_str : ezlopi_false_str);
TRACE_D(" |~~~|- item->interface.gpio.gpio_in.gpio_num: %d", item->interface.gpio.gpio_in.gpio_num);
@@ -363,15 +363,15 @@ static void ezlopi_device_print_interface_digital_io(l_ezlopi_item_t *item)
TRACE_D(" |~~~|- item->interface.gpio.gpio_in.interrupt: %d", item->interface.gpio.gpio_in.interrupt);
}
-static void ezlopi_device_print_interface_analogue_input(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_analogue_input(l_ezlopi_item_t* item)
{
TRACE_D(" |~~~|- item->interface.adc.gpio_num: %d", item->interface.adc.gpio_num);
TRACE_D(" |~~~|- item->interface.adc.resln_bit: %d", item->interface.adc.resln_bit);
}
-static void ezlopi_device_print_interface_analogue_output(l_ezlopi_item_t *item) {}
+static void ezlopi_device_print_interface_analogue_output(l_ezlopi_item_t* item) {}
-static void ezlopi_device_print_interface_pwm(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_pwm(l_ezlopi_item_t* item)
{
TRACE_D(" |~~~|- item->interface.pwm.gpio_num: %d", item->interface.pwm.gpio_num);
TRACE_D(" |~~~|- item->interface.pwm.channel: %d", item->interface.pwm.channel);
@@ -381,7 +381,7 @@ static void ezlopi_device_print_interface_pwm(l_ezlopi_item_t *item)
TRACE_D(" |~~~|- item->interface.pwm.duty_cycle: %d", item->interface.pwm.duty_cycle);
}
-static void ezlopi_device_print_interface_uart(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_uart(l_ezlopi_item_t* item)
{
TRACE_D(" |~~~|- item->interface.uart.channel: %d", item->interface.uart.channel);
TRACE_D(" |~~~|- item->interface.uart.baudrate: %d", item->interface.uart.baudrate);
@@ -390,7 +390,7 @@ static void ezlopi_device_print_interface_uart(l_ezlopi_item_t *item)
TRACE_D(" |~~~|- item->interface.uart.enable: %d", item->interface.uart.enable);
}
-static void ezlopi_device_print_interface_i2c_master(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_i2c_master(l_ezlopi_item_t* item)
{
TRACE_D("|~~~|- item->interface.i2c_master.enable: %s", item->interface.i2c_master.enable ? ezlopi_true_str : ezlopi_false_str);
TRACE_D("|~~~|- item->interface.i2c_master.channel: %d", item->interface.i2c_master.channel);
@@ -399,7 +399,7 @@ static void ezlopi_device_print_interface_i2c_master(l_ezlopi_item_t *item)
TRACE_D("|~~~|- item->interface.i2c_master.sda: %d", item->interface.i2c_master.sda);
}
-static void ezlopi_device_print_interface_spi_master(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_spi_master(l_ezlopi_item_t* item)
{
TRACE_D(" |~~~|- item->interface.spi_master.enable: %d", item->interface.spi_master.enable);
TRACE_D(" |~~~|- item->interface.spi_master.channel: %d", item->interface.spi_master.channel);
@@ -416,13 +416,13 @@ static void ezlopi_device_print_interface_spi_master(l_ezlopi_item_t *item)
TRACE_D(" |~~~|- item->interface.spi_master.flags: %d", item->interface.spi_master.flags);
}
-static void ezlopi_device_print_interface_onewire_master(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_onewire_master(l_ezlopi_item_t* item)
{
TRACE_D(" |~~~|- item->interface.onewire_master.enable: %d", item->interface.onewire_master.enable);
TRACE_D(" |~~~|- item->interface.onewire_master.onewire_pin: %d", item->interface.onewire_master.onewire_pin);
}
-static void ezlopi_device_print_interface_type(l_ezlopi_item_t *item)
+static void ezlopi_device_print_interface_type(l_ezlopi_item_t* item)
{
switch (item->interface_type)
{
@@ -476,14 +476,14 @@ static void ezlopi_device_print_interface_type(l_ezlopi_item_t *item)
//////////////////// Print functions end here /////////////////////////
///////////////////////////////////////////////////////////////////////
-static void ezlopi_device_parse_json_v3(cJSON *cjson_config)
+static void ezlopi_device_parse_json_v3(cJSON* cjson_config)
{
- cJSON *cjson_device_list = cJSON_GetObjectItem(cjson_config, ezlopi_dev_detail_str);
+ cJSON* cjson_device_list = cJSON_GetObjectItem(cjson_config, ezlopi_dev_detail_str);
if (cjson_device_list)
{
int config_dev_idx = 0;
- cJSON *cjson_device = NULL;
+ cJSON* cjson_device = NULL;
TRACE_I("---------------------------------------------");
while (NULL != (cjson_device = cJSON_GetArrayItem(cjson_device_list, config_dev_idx)))
@@ -496,15 +496,15 @@ static void ezlopi_device_parse_json_v3(cJSON *cjson_config)
if (0 != id_item)
{
- s_ezlopi_device_v3_t *v3_sensor_list = ezlopi_devices_list_get_list_v3();
+ s_ezlopi_device_v3_t* v3_sensor_list = ezlopi_devices_list_get_list_v3();
int dev_idx = 0;
while (NULL != v3_sensor_list[dev_idx].func)
{
if (id_item == v3_sensor_list[dev_idx].id)
{
- s_ezlopi_prep_arg_t device_prep_arg = {.device = &v3_sensor_list[dev_idx], .cjson_device = cjson_device};
- v3_sensor_list[dev_idx].func(EZLOPI_ACTION_PREPARE, NULL, (void *)&device_prep_arg, NULL);
+ s_ezlopi_prep_arg_t device_prep_arg = { .device = &v3_sensor_list[dev_idx], .cjson_device = cjson_device };
+ v3_sensor_list[dev_idx].func(EZLOPI_ACTION_PREPARE, NULL, (void*)&device_prep_arg, NULL);
}
dev_idx++;
@@ -520,7 +520,7 @@ static void ezlopi_device_parse_json_v3(cJSON *cjson_config)
ezlopi_device_print_controller_cloud_information_v3();
int device_count = 0;
- l_ezlopi_device_t *tm_device_l_list = l_device_head;
+ l_ezlopi_device_t* tm_device_l_list = l_device_head;
while (tm_device_l_list)
{
TRACE_D("|~~~~~~~~~~~~~~~~ Device - %d ~~~~~~~~~~~~~~~~|", device_count + 1);
@@ -533,7 +533,7 @@ static void ezlopi_device_parse_json_v3(cJSON *cjson_config)
TRACE_D("|- Device-type: %s", tm_device_l_list->cloud_properties.device_type ? tm_device_l_list->cloud_properties.device_type : ezlopi_null_str);
int item_count = 0;
- l_ezlopi_item_t *tm_itme_l_list = tm_device_l_list->items;
+ l_ezlopi_item_t* tm_itme_l_list = tm_device_l_list->items;
while (tm_itme_l_list)
{
TRACE_D("|~~~|--------------- Item - %d ---------------|", item_count + 1);
@@ -557,7 +557,7 @@ static void ezlopi_device_parse_json_v3(cJSON *cjson_config)
#endif
#if 0
- l_ezlopi_configured_devices_t *current_head = ezlopi_devices_list_get_configured_items();
+ l_ezlopi_configured_devices_t* current_head = ezlopi_devices_list_get_configured_items();
while (NULL != current_head)
{
ezlopi_device_print_properties(current_head->properties);
@@ -567,7 +567,7 @@ static void ezlopi_device_parse_json_v3(cJSON *cjson_config)
#endif
}
-static void ezlopi_device_free_item(l_ezlopi_item_t *items)
+static void ezlopi_device_free_item(l_ezlopi_item_t* items)
{
if (items->next)
{
@@ -581,13 +581,13 @@ static void ezlopi_device_free_item(l_ezlopi_item_t *items)
// {
// if (settings->next)
// {
-// ezlopi_device_free_item(settings->next);
+// ezlopi_device_free_setting(settings->next);//recursive
// }
//
// free(settings);
// }
-static void ezlopi_device_free_single(l_ezlopi_device_t *device)
+static void ezlopi_device_free_single(l_ezlopi_device_t* device)
{
if (device->items)
{
@@ -598,9 +598,9 @@ static void ezlopi_device_free_single(l_ezlopi_device_t *device)
free(device);
}
-l_ezlopi_device_settings_v3_t *ezlopi_device_add_settings_to_device_v3(l_ezlopi_device_t *device, int (*setting_func)(e_ezlopi_settings_action_t action, struct l_ezlopi_device_settings_v3 *setting, void *arg, void *user_arg))
+l_ezlopi_device_settings_v3_t* ezlopi_device_add_settings_to_device_v3(l_ezlopi_device_t* device, int (*setting_func)(e_ezlopi_settings_action_t action, struct l_ezlopi_device_settings_v3* setting, void* arg, void* user_arg))
{
- l_ezlopi_device_settings_v3_t *new_setting = NULL;
+ l_ezlopi_device_settings_v3_t* new_setting = NULL;
if (device)
{
new_setting = malloc(sizeof(l_ezlopi_device_settings_v3_t));
@@ -615,7 +615,7 @@ l_ezlopi_device_settings_v3_t *ezlopi_device_add_settings_to_device_v3(l_ezlopi_
}
else
{
- l_ezlopi_device_settings_v3_t *curr_setting = device->settings;
+ l_ezlopi_device_settings_v3_t* curr_setting = device->settings;
while (curr_setting->next)
{
curr_setting = curr_setting->next;
@@ -629,9 +629,9 @@ l_ezlopi_device_settings_v3_t *ezlopi_device_add_settings_to_device_v3(l_ezlopi_
return new_setting;
}
-cJSON *ezlopi_device_create_device_table_from_prop(l_ezlopi_device_t *device_prop)
+cJSON* ezlopi_device_create_device_table_from_prop(l_ezlopi_device_t* device_prop)
{
- cJSON *cj_device = NULL;
+ cJSON* cj_device = NULL;
if (device_prop)
{
diff --git a/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.h b/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.h
index 69305331a..7e66e1806 100644
--- a/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.h
+++ b/ezlopi-core/ezlopi-core-devices/ezlopi_core_devices.h
@@ -44,6 +44,21 @@
TRACE_E("%s not found!", item_name); \
} \
}
+
+#define CJSON_GET_VALUE_GPIO(root, item_name, item_val) \
+ { \
+ cJSON *o_item = cJSON_GetObjectItem(root, item_name); \
+ if (o_item && o_item->type == cJSON_Number) \
+ { \
+ item_val = o_item->valueint; \
+ } \
+ else \
+ { \
+ item_val = -1; \
+ TRACE_E("%s not found!", item_name); \
+ } \
+ }
+
// TRACE_I("%s: %d", item_name, item_val);
#define CJSON_GET_VALUE_STRING(root, item_name, item_val) \
diff --git a/ezlopi-core/ezlopi-core-event-group/CMakeLists.txt b/ezlopi-core/ezlopi-core-event-group/CMakeLists.txt
index 16ad428dc..5ec2dd20f 100644
--- a/ezlopi-core/ezlopi-core-event-group/CMakeLists.txt
+++ b/ezlopi-core/ezlopi-core-event-group/CMakeLists.txt
@@ -2,7 +2,9 @@
file(GLOB_RECURSE config_src "*.c")
-idf_component_register(SRCS "${config_src}"
- INCLUDE_DIRS ".")
+idf_component_register(SRCS "ezlopi_core_event_group.c" "${config_src}"
+ INCLUDE_DIRS "."
+ REQUIRES ezlopi-util-trace
+)
diff --git a/ezlopi-core/ezlopi-core-event-group/ezlopi_core_event_group.c b/ezlopi-core/ezlopi-core-event-group/ezlopi_core_event_group.c
index edbee2e11..1eb29302d 100644
--- a/ezlopi-core/ezlopi-core-event-group/ezlopi_core_event_group.c
+++ b/ezlopi-core/ezlopi-core-event-group/ezlopi_core_event_group.c
@@ -4,6 +4,8 @@
#include "freertos/task.h"
#include "freertos/event_groups.h"
+#include "ezlopi_util_trace.h"
+
#include "ezlopi_core_event_group.h"
static EventGroupHandle_t ezlopi_event_group_handle = NULL;
@@ -42,6 +44,8 @@ int ezlopi_event_group_wait_for_event(e_ezlopi_event_t event, uint32_t wait_time
{
ret = 1;
}
+
+ // TRACE_D("event-bits: %08x, event: %08x", event_bits, event);
}
else
{
diff --git a/ezlopi-core/ezlopi-core-ezlopi/CMakeLists.txt b/ezlopi-core/ezlopi-core-ezlopi/CMakeLists.txt
index fea7848ac..8ea933daf 100644
--- a/ezlopi-core/ezlopi-core-ezlopi/CMakeLists.txt
+++ b/ezlopi-core/ezlopi-core-ezlopi/CMakeLists.txt
@@ -2,43 +2,38 @@
file(GLOB_RECURSE config_src "*.c")
-set(EZLOPI_UTIL_COMPONENTS
- ezlopi-util-trace
-)
-
set(EZLOPI_CORE_COMPONENTS
ezlopi-core-wifi
+ ezlopi-core-modes
ezlopi-core-sntp
ezlopi-core-ble
ezlopi-core-scenes
+ ezlopi-util-trace
ezlopi-core-mdns
)
-set(EZLOPI_CLOUD_COMPONENTS
-
-)
-
-set(EZLOPI_SERVICE_COMPONENTS
- ezlopi-service-webprov
- ezlopi-service-timer
- ezlopi-service-gpioisr
- ezlopi-service-ble
- ezlopi-service-ota
- ezlopi-service-uart
- ezlopi-service-meshbot
- ezlopi-service-modes
-
+set(EZLOPI_CLOUD_COMPONENTS
+ ezlopi-cloud-data
+ ezlopi-cloud-devices
+ ezlopi-cloud-scenes
+ ezlopi-cloud-registration
+ ezlopi-cloud-favorite
+ ezlopi-cloud-gateways
+ ezlopi-cloud-info
+ ezlopi-cloud-modes
+ ezlopi-cloud-items
+ ezlopi-cloud-room
+ ezlopi-cloud-settings
+ ezlopi-cloud-network
+ ezlopi-cloud-ota
+ ezlopi-cloud-location
+ ezlopi-cloud-coordinates
)
-
-
-idf_component_register(SRCS "ezlopi_core_ezlopi.c" "${config_src}"
+idf_component_register(SRCS "ezlopi_core_ezlopi.c" "ezlopi_core_ezlopi_broadcast.c" "${config_src}"
INCLUDE_DIRS "."
- REQUIRES
- ezlopi-user-config
- ${EZLOPI_UTIL_COMPONENTS}
- ${EZLOPI_CORE_COMPONENTS}
+ REQUIRES ${EZLOPI_CORE_COMPONENTS}
${EZLOPI_CLOUD_COMPONENTS}
- ${EZLOPI_SERVICE_COMPONENTS}
- )
+)
+
diff --git a/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi.c b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi.c
index 09c5bd75b..2739c7f40 100644
--- a/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi.c
+++ b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi.c
@@ -21,15 +21,6 @@
#include "ezlopi_core_ethernet.h"
#endif // CONFIG_EZPI_CORE_ENABLE_ETH
-#include "ezlopi_service_uart.h"
-#include "ezlopi_service_ota.h"
-#include "ezlopi_service_timer.h"
-#include "ezlopi_service_webprov.h"
-#include "ezlopi_service_gpioisr.h"
-#include "ezlopi_service_ble.h"
-#include "ezlopi_service_meshbot.h"
-#include "ezlopi_service_modes.h"
-
#include "ezlopi_hal_system_info.h"
static void ezlopi_initialize_devices_v3(void);
@@ -37,10 +28,6 @@ static void ezlopi_initialize_devices_v3(void);
void ezlopi_init(void)
{
- gpio_install_isr_service(0);
-
- EZPI_SERVICE_uart_init();
- gpio_isr_service_init();
// Init memories
ezlopi_nvs_init();
@@ -64,10 +51,8 @@ void ezlopi_init(void)
ezlopi_core_modes_init();
ezlopi_room_init();
- ezlopi_ble_service_init();
#ifdef CONFIG_EZPI_SERV_ENABLE_MESHBOTS
- ezlopi_scenes_meshbot_init();
ezlopi_scenes_scripts_init();
ezlopi_scenes_expressions_init();
ezlopi_scenes_init_v2();
@@ -87,17 +72,6 @@ void ezlopi_init(void)
ezlopi_event_queue_init();
ezlopi_ping_init();
ezlopi_timer_start_1000ms();
- ezlopi_ping_init();
-
- EZPI_CORE_sntp_init();
-
- timer_service_init();
-
- web_provisioning_init();
-
- ota_service_init();
-
- ezlopi_service_modes_init();
}
static void ezlopi_initialize_devices_v3(void)
diff --git a/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.c b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.c
new file mode 100644
index 000000000..fe8454fd1
--- /dev/null
+++ b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.c
@@ -0,0 +1,148 @@
+#include "ezlopi_util_trace.h"
+#include "ezlopi_core_ezlopi_broadcast.h"
+
+static l_broadcast_method_t* __method_head = NULL;
+static int (*__broadcast_queue_func)(char*) = NULL;
+
+static l_broadcast_method_t* __method_create(f_broadcast_method_t method, uint32_t retries);
+
+void ezlopi_core_ezlopi_broadcast_methods_set_queue(int(*func)(char*))
+{
+ __broadcast_queue_func = func;
+}
+
+int ezlopi_core_ezlopi_broadcast_methods_send_to_queue(char* data)
+{
+ int ret = 0;
+ if (__broadcast_queue_func)
+ {
+ ret = __broadcast_queue_func(data);
+ }
+ return ret;
+}
+
+l_broadcast_method_t* ezlopi_core_ezlopi_broadcast_methods_get_head(void)
+{
+ return __method_head;
+}
+
+void ezlopi_core_ezlopi_broadcast_execute(char* data)
+{
+ if (data)
+ {
+ l_broadcast_method_t* curr_node = __method_head;
+
+ while (curr_node)
+ {
+ if (curr_node->func)
+ {
+ uint32_t retries = curr_node->fail_retry;
+
+ do
+ {
+ if (curr_node->func(data) > 0)
+ {
+ break;
+ }
+
+ } while (--retries);
+ }
+
+ curr_node = curr_node->next;
+ }
+ }
+}
+
+l_broadcast_method_t* ezlopi_core_ezlopi_broadcast_method_add(f_broadcast_method_t broadcast_method, uint32_t retries)
+{
+ l_broadcast_method_t* ret = __method_create(broadcast_method, retries);
+
+ if (ret)
+ {
+ TRACE_D("registering broadcast method ...");
+
+ if (__method_head)
+ {
+ l_broadcast_method_t* curr_node = __method_head;
+
+ while (curr_node->next)
+ {
+ curr_node = curr_node->next;
+ }
+
+ TRACE_D("registered ...");
+ curr_node->next = ret;
+ }
+ else
+ {
+ TRACE_D("registered ...");
+ __method_head = ret;
+ }
+ }
+ else
+ {
+ TRACE_E("registering broadcast method failed ...");
+ }
+
+ return ret;
+}
+
+void ezlopi_core_ezlopi_broadcast_remove_method(f_broadcast_method_t broadcast_method)
+{
+ if (__method_head)
+ {
+ if (broadcast_method == __method_head->func)
+ {
+ l_broadcast_method_t* remove_node = __method_head;
+ __method_head = __method_head->next;
+ free(remove_node);
+ }
+ else
+ {
+ l_broadcast_method_t* curr_node = __method_head;
+ while (curr_node->next)
+ {
+ if (curr_node->next->func == broadcast_method)
+ {
+ l_broadcast_method_t* remove_node = curr_node->next;
+ curr_node->next = curr_node->next->next;
+ free(remove_node);
+
+ break;
+ }
+
+ curr_node = curr_node->next;
+ }
+ }
+ }
+}
+
+static l_broadcast_method_t* __method_create(f_broadcast_method_t method, uint32_t retries)
+{
+ l_broadcast_method_t* method_node = NULL;
+
+ if (method)
+ {
+ method_node = malloc(sizeof(l_broadcast_method_t));
+
+ if (method_node)
+ {
+ memset(method_node, 0, sizeof(l_broadcast_method_t));
+
+ method_node->next = NULL;
+ method_node->func = method;
+ method_node->fail_retry = retries;
+ method_node->method_name = "";
+ }
+ else
+ {
+ TRACE_E("malloc failed");
+ }
+ }
+ else
+ {
+ TRACE_E("method is NULL");
+ }
+
+ return method_node;
+}
\ No newline at end of file
diff --git a/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.h b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.h
new file mode 100644
index 000000000..0f472a799
--- /dev/null
+++ b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.h
@@ -0,0 +1,27 @@
+#ifndef __EZLOPI_CORE_EZLOPI_BROADCAST_H__
+#define __EZLOPI_CORE_EZLOPI_BROADCAST_H__
+
+#include
+#include
+#include
+#include
+
+typedef int (*f_broadcast_method_t)(char* data);
+
+typedef struct l_broadcast_method
+{
+ char* method_name;
+ uint32_t fail_retry;
+ f_broadcast_method_t func;
+ struct l_broadcast_method* next;
+
+} l_broadcast_method_t;
+
+void ezlopi_core_ezlopi_broadcast_execute(char* data);
+int ezlopi_core_ezlopi_broadcast_methods_send_to_queue(char* data);
+void ezlopi_core_ezlopi_broadcast_methods_set_queue(int(*func)(char*));
+l_broadcast_method_t* ezlopi_core_ezlopi_broadcast_methods_get_head(void);
+void ezlopi_core_ezlopi_broadcast_remove_method(f_broadcast_method_t broadcast_method);
+l_broadcast_method_t* ezlopi_core_ezlopi_broadcast_method_add(f_broadcast_method_t broadcast_method, uint32_t retries);
+
+#endif // __EZLOPI_CORE_EZLOPI_BROADCAST_H__
diff --git a/ezlopi-services/ezlopi-service-webprov/ezlopi_api_url_macros.h b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_cloud_api_macros.h
similarity index 97%
rename from ezlopi-services/ezlopi-service-webprov/ezlopi_api_url_macros.h
rename to ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_cloud_api_macros.h
index 4f17313e8..98e93b872 100644
--- a/ezlopi-services/ezlopi-service-webprov/ezlopi_api_url_macros.h
+++ b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_cloud_api_macros.h
@@ -1,6 +1,6 @@
// ("name", func, updater_func)
CLOUD_METHOD("hub.items.list", items_list_v3, NULL)
-CLOUD_METHOD("hub.item.value.set", items_set_value_v3, items_update_v3)
+CLOUD_METHOD("hub.item.value.set", items_set_value_v3, NULL)
CLOUD_METHOD("hub.devices.list", devices_list_v3, NULL)
CLOUD_METHOD("hub.device.name.set", device_name_set, device_updated)
@@ -85,7 +85,7 @@ CLOUD_METHOD("hub.scenes.expressions.delete", scenes_expressions_delete, NULL)
CLOUD_METHOD("hub.nma.register.repeat", register_repeat, NULL)
-CLOUD_METHOD("hub.reboot", __hub_reboot, NULL)
+CLOUD_METHOD("hub.reboot", ezlopi_core_ezlopi_methods_reboot, NULL)
CLOUD_METHOD("registered", registered, NULL)
CLOUD_METHOD("hub.coordinates.set", hub_coordinates_set, NULL)
diff --git a/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_methods.c b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_methods.c
new file mode 100644
index 000000000..06e50e9cc
--- /dev/null
+++ b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_methods.c
@@ -0,0 +1,108 @@
+
+#include "ezlopi_cloud_ota.h"
+#include "ezlopi_cloud_data.h"
+#include "ezlopi_cloud_info.h"
+#include "ezlopi_cloud_room.h"
+#include "ezlopi_cloud_items.h"
+#include "ezlopi_cloud_modes.h"
+#include "ezlopi_cloud_scenes.h"
+#include "ezlopi_cloud_devices.h"
+#include "ezlopi_cloud_network.h"
+#include "ezlopi_cloud_location.h"
+#include "ezlopi_cloud_favorite.h"
+#include "ezlopi_cloud_gateways.h"
+#include "ezlopi_cloud_settings.h"
+#include "ezlopi_cloud_constants.h"
+#include "ezlopi_cloud_coordinates.h"
+#include "ezlopi_cloud_registration.h"
+#include "ezlopi_cloud_modes_updaters.h"
+#include "ezlopi_cloud_scenes_scripts.h"
+#include "ezlopi_cloud_scenes_expressions.h"
+
+#include "ezlopi_core_reset.h"
+#include "ezlopi_core_ezlopi_methods.h"
+#include "ezlopi_util_trace.h"
+
+static const s_method_list_v2_t method_list_v2[] = {
+#define CLOUD_METHOD(name, _method, _updater) {.method_name = name, .method = _method, .updater = _updater},
+#include "ezlopi_core_ezlopi_cloud_api_macros.h"
+#undef CLOUD_METHOD
+ {.method_name = NULL, .method = NULL, .updater = NULL},
+};
+
+f_method_func_t ezlopi_core_ezlopi_methods_get_by_id(uint32_t method_id)
+{
+ return method_list_v2[method_id].method;
+}
+
+f_method_func_t ezlopi_core_ezlopi_methods_get_updater_by_id(uint32_t method_id)
+{
+ return method_list_v2[method_id].updater;
+}
+
+char* ezlopi_core_ezlopi_methods_get_name_by_id(uint32_t method_id)
+{
+ return method_list_v2[method_id].method_name;
+}
+
+uint32_t ezlopi_core_ezlopi_methods_search_in_list(cJSON* cj_method)
+{
+ uint32_t found_method = 0;
+ uint32_t idx = 0;
+
+ if (cj_method && cj_method->valuestring)
+ {
+ while (method_list_v2[idx].method_name)
+ {
+ uint32_t request_method_name_len = strlen(cj_method->valuestring);
+ uint32_t list_method_name_len = strlen(method_list_v2[idx].method_name);
+ uint32_t comp_len = list_method_name_len > request_method_name_len ? list_method_name_len : request_method_name_len;
+ if (0 == strncmp(cj_method->valuestring, method_list_v2[idx].method_name, comp_len))
+ {
+ found_method = 1;
+ break;
+ }
+
+ idx++;
+ }
+ }
+
+ return (found_method ? idx : UINT32_MAX);
+}
+
+void ezlopi_core_ezlopi_methods_rpc_method_notfound(cJSON* cj_request, cJSON* cj_response)
+{
+ cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
+ cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
+ cJSON* cjson_error = cJSON_AddObjectToObject(cj_response, ezlopi_error_str);
+ if (cjson_error)
+ {
+ cJSON_AddNumberToObject(cjson_error, ezlopi_code_str, -32602);
+ cJSON_AddStringToObject(cjson_error, ezlopi_data_str, ezlopi_rpc_method_notfound_str);
+ cJSON_AddStringToObject(cjson_error, ezlopi_message_str, ezlopi_Unknown_method_str);
+ }
+
+ cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
+}
+
+void ezlopi_core_ezlopi_methods_registration_init(void)
+{
+ registration_init();
+}
+
+bool ezlopi_core_elzlopi_methods_check_method_register(f_method_func_t method)
+{
+ bool ret = false;
+
+ if (registered == method)
+ {
+ ret = true;
+ }
+
+ return ret;
+}
+
+void ezlopi_core_ezlopi_methods_reboot(cJSON* cj_request, cJSON* cj_response)
+{
+ EZPI_CORE_reboot();
+}
diff --git a/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_methods.h b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_methods.h
new file mode 100644
index 000000000..2eab424b9
--- /dev/null
+++ b/ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_methods.h
@@ -0,0 +1,30 @@
+#ifndef __EZLOPI_CORE_EZLOPI_METHODS_H__
+#define __EZLOPI_CORE_EZLOPI_METHODS_H__
+
+#include
+#include
+#include
+#include
+#include
+
+typedef void (*f_method_func_t)(cJSON *cj_request, cJSON *cj_response);
+typedef struct s_method_list_v2
+{
+ char *method_name;
+ f_method_func_t method;
+ f_method_func_t updater;
+} s_method_list_v2_t;
+
+void ezlopi_core_ezlopi_methods_registration_init(void);
+bool ezlopi_core_elzlopi_methods_check_method_register(f_method_func_t method);
+
+uint32_t ezlopi_core_ezlopi_methods_search_in_list(cJSON *cj_method);
+
+char *ezlopi_core_ezlopi_methods_get_name_by_id(uint32_t method_id);
+f_method_func_t ezlopi_core_ezlopi_methods_get_by_id(uint32_t method_id);
+f_method_func_t ezlopi_core_ezlopi_methods_get_updater_by_id(uint32_t method_id);
+
+void ezlopi_core_ezlopi_methods_reboot(cJSON *cj_request, cJSON *cj_response);
+void ezlopi_core_ezlopi_methods_rpc_method_notfound(cJSON *cj_request, cJSON *cj_response);
+
+#endif // __EZLOPI_CORE_EZLOPI_METHODS_H__
\ No newline at end of file
diff --git a/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.c b/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.c
index 52dac3c03..7f9bd2820 100644
--- a/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.c
+++ b/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.c
@@ -119,7 +119,7 @@ const esp_partition_t* ezlopi_factory_info_v3_init(void)
partition_ctx_v3 = esp_partition_find_first(EZLOPI_FACTORY_INFO_V3_PARTITION_TYPE, EZLOPI_FACTORY_INFO_V3_SUBTYPE, EZLOPI_FACTORY_INFO_V3_PARTITION_NAME);
unsigned long long id = ezlopi_factory_info_v3_get_id();
- TRACE_D("SERIAL-ID [off: 0x%04X, size: 0x%04X]: %llu", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_DEVICE_ID, E_EZLOPI_FACTORY_INFO_HUB_DATA), EZLOPI_FINFO_LEN_DEVICE_ID, id);
+ // TRACE_D("SERIAL-ID [off: 0x%04X, size: 0x%04X]: %llu", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_DEVICE_ID, E_EZLOPI_FACTORY_INFO_HUB_DATA), EZLOPI_FINFO_LEN_DEVICE_ID, id);
}
return partition_ctx_v3;
}
@@ -169,7 +169,6 @@ void print_factory_info_v3(void)
TRACE_W("WIFI-SSID [off: 0x%04X, size: 0x%04X]: %s", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_WIFI_SSID, E_EZLOPI_FACTORY_INFO_HUB_DATA), EZLOPI_FINFO_LEN_WIFI_SSID, wifi_ssid ? wifi_ssid : "null");
TRACE_W("WIFI-PASSWORD [off: 0x%04X, size: 0x%04X]: %s", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_WIFI_PASS, E_EZLOPI_FACTORY_INFO_HUB_DATA), EZLOPI_FINFO_LEN_WIFI_PASS, wifi_password ? wifi_password : "null");
TRACE_W("CLOUD_SERVER [off: 0x%04X, size: 0x%04X]: %s", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_CLOUD_SERVER_URL, E_EZLOPI_FACTORY_INFO_CONN_DATA), EZLOPI_FINFO_LEN_CLOUD_SERVER_URL, cloud_server ? cloud_server : "null");
- TRACE_W("PROVISIONING_SERVER [off: 0x%04X, size: 0x%04X]: %s", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_PROVISIONING_SERVER_URL, E_EZLOPI_FACTORY_INFO_CONN_DATA), EZLOPI_FINFO_LEN_PROVISIONING_SERVER_URL, provision_server ? provision_server : "null");
TRACE_W("DEVICE_TYPE [off: 0x%04X, size: 0x%04X]: %s", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_EZLOPI_DEVICE_TYPE, E_EZLOPI_FACTORY_INFO_HUB_DATA), EZLOPI_FINFO_LEN_EZLOPI_DEVICE_TYPE, device_type ? device_type : "null");
TRACE_W("CA_CERTIFICATE [off: 0x%04X, size: 0x%04X]: %s", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_CA_CERTIFICATE, E_EZLOPI_FACTORY_INFO_CONN_DATA), EZLOPI_FINFO_LEN_CA_CERTIFICATE, ca_certificate ? ca_certificate : "null");
TRACE_W("SSL_PRIVATE_KEY [off: 0x%04X, size: 0x%04X]: %s", ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_SSL_PRIVATE_KEY, E_EZLOPI_FACTORY_INFO_CONN_DATA), EZLOPI_FINFO_LEN_SSL_PRIVATE_KEY, ssl_private_key ? ssl_private_key : "null");
@@ -448,7 +447,16 @@ char* ezlopi_factory_info_v3_get_ssl_shared_key(void)
char* ezlopi_factory_info_v3_get_ezlopi_config(void)
{
- return ezlopi_factory_info_v3_read_string(ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_EZLOPI_CONFIG_JSON, E_EZLOPI_FACTORY_INFO_CONN_DATA), EZLOPI_FINFO_LEN_EZLOPI_CONFIG_JSON);
+ char* ret = ezlopi_factory_info_v3_read_string(ezlopi_factory_info_v3_get_abs_address(EZLOPI_FINFO_REL_OFFSET_EZLOPI_CONFIG_JSON, E_EZLOPI_FACTORY_INFO_CONN_DATA), EZLOPI_FINFO_LEN_EZLOPI_CONFIG_JSON);
+ if (false == isprint(ret[0]))
+ {
+ if (ret)
+ {
+ free(ret);
+ ret = NULL;
+ }
+ }
+ return ret;
}
@@ -614,6 +622,7 @@ int ezlopi_factory_info_v3_set_wifi(char* ssid, char* password)
{
snprintf(tmp_buffer + EZLOPI_FINFO_REL_OFFSET_WIFI_SSID, EZLOPI_FINFO_LEN_WIFI_SSID, "%s", ssid);
snprintf(tmp_buffer + EZLOPI_FINFO_REL_OFFSET_WIFI_PASS, EZLOPI_FINFO_LEN_WIFI_PASS, "%s", password);
+
if (ESP_OK == esp_partition_erase_range(partition_ctx_v3, EZLOPI_FINFO_OFFSET_HUB_DATA, EZLOPI_FINFO_READ_LEN_4KB))
{
if (ESP_OK == esp_partition_write(partition_ctx_v3, EZLOPI_FINFO_OFFSET_HUB_DATA, tmp_buffer, EZLOPI_FINFO_READ_LEN_4KB))
@@ -621,6 +630,9 @@ int ezlopi_factory_info_v3_set_wifi(char* ssid, char* password)
ret = 1;
}
}
+ else {
+ TRACE_E("failed to save wifi");
+ }
}
else
{
diff --git a/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h b/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h
index bba08fbbf..0a11fb826 100644
--- a/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h
+++ b/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h
@@ -160,12 +160,19 @@ extern "C"
\"dev_detail\":\
[\
{\
- \"dev_type\":8,\
- \"dev_name\":\"ENS160\",\
+ \"dev_type\": 1,\
+ \"dev_name\": \"Dining Room Main Lamp\",\
\"id_room\":\"\",\
- \"id_item\":68,\
- \"gpio_scl\":17,\
- \"gpio_sda\":18\
+ \"id_item\": 2,\
+ \"val_ip\": false,\
+ \"val_op\": false,\
+ \"gpio_in\": 21,\
+ \"gpio_out\": 13,\
+ \"is_ip\": false,\
+ \"ip_inv\": true,\
+ \"pullup_ip\": true,\
+ \"pullup_op\": true,\
+ \"op_inv\": false\
}\
],\
\"dev_total\": 1}";
diff --git a/ezlopi-core/ezlopi-core-reset/ezlopi_core_reset.c b/ezlopi-core/ezlopi-core-reset/ezlopi_core_reset.c
index be1f4e8b1..bcd8773e4 100644
--- a/ezlopi-core/ezlopi-core-reset/ezlopi_core_reset.c
+++ b/ezlopi-core/ezlopi-core-reset/ezlopi_core_reset.c
@@ -10,7 +10,7 @@
void EZPI_CORE_reboot(void)
{
- web_provisioning_deinit();
+ ezlopi_service_web_provisioning_deinit();
esp_restart();
}
diff --git a/ezlopi-core/ezlopi-core-room/ezlopi_core_room.c b/ezlopi-core/ezlopi-core-room/ezlopi_core_room.c
index f854aaf02..677513e4e 100644
--- a/ezlopi-core/ezlopi-core-room/ezlopi_core_room.c
+++ b/ezlopi-core/ezlopi-core-room/ezlopi_core_room.c
@@ -4,14 +4,15 @@
#include "ezlopi_core_room.h"
#include "ezlopi_core_cloud.h"
#include "ezlopi_core_cjson_macros.h"
+#include "ezlopi_core_ezlopi_broadcast.h"
#include "ezlopi_cloud_constants.h"
#include "ezlopi_service_webprov.h"
-static s_ezlopi_room_t *l_room_head = NULL;
+static s_ezlopi_room_t* l_room_head = NULL;
-static const char *sc_room_subtype_name[] = {
+static const char* sc_room_subtype_name[] = {
#ifndef ROOM_SUBTYPE
#define ROOM_SUBTYPE(name, e_num) name,
#undef ROOM_SUBTYPE
@@ -19,45 +20,45 @@ static const char *sc_room_subtype_name[] = {
};
static void __sort_by_pos(void);
-static void __free_nodes(s_ezlopi_room_t *room);
+static void __free_nodes(s_ezlopi_room_t* room);
static int __free_room_from_list_by_id(uint32_t room_id);
static void __update_cloud_room_deleted(uint32_t room_id);
static int __remove_room_from_nvs_by_id(uint32_t a_room_id);
-static e_room_subtype_t __get_subtype_enum(char *subtype_str);
+static e_room_subtype_t __get_subtype_enum(char* subtype_str);
// static const char *__get_subtype_name(e_room_subtype_t subtype);
-s_ezlopi_room_t *ezlopi_room_get_room_head(void)
+s_ezlopi_room_t* ezlopi_room_get_room_head(void)
{
return l_room_head;
}
-int ezlopi_room_name_set(cJSON *cj_room)
+int ezlopi_room_name_set(cJSON* cj_room)
{
int ret = 0;
if (cj_room)
{
- cJSON *cj_room_id = cJSON_GetObjectItem(cj_room, ezlopi__id_str);
- cJSON *cj_room_name = cJSON_GetObjectItem(cj_room, ezlopi_name_str);
+ cJSON* cj_room_id = cJSON_GetObjectItem(cj_room, ezlopi__id_str);
+ cJSON* cj_room_name = cJSON_GetObjectItem(cj_room, ezlopi_name_str);
if (cj_room_id && cj_room_id->valuestring && cj_room_name && cj_room_name->valuestring)
{
uint32_t room_id = strtoul(cj_room_id->valuestring, NULL, 16);
if (room_id)
{
- char *rooms_str = ezlopi_nvs_read_rooms();
+ char* rooms_str = ezlopi_nvs_read_rooms();
if (rooms_str)
{
- cJSON *cj_rooms = cJSON_Parse(rooms_str);
+ cJSON* cj_rooms = cJSON_Parse(rooms_str);
free(rooms_str);
if (cj_rooms)
{
int idx = 0;
- cJSON *cj_room_tmp = NULL;
+ cJSON* cj_room_tmp = NULL;
while (NULL != (cj_room_tmp = cJSON_GetArrayItem(cj_rooms, idx++)))
{
- cJSON *cj_room_tmp_id = cJSON_GetObjectItem(cj_room_tmp, ezlopi__id_str);
+ cJSON* cj_room_tmp_id = cJSON_GetObjectItem(cj_room_tmp, ezlopi__id_str);
if (cj_room_tmp_id && cj_room_tmp_id->valuestring)
{
uint32_t tmp_room_id = strtoul(cj_room_tmp_id->valuestring, NULL, 16);
@@ -66,7 +67,7 @@ int ezlopi_room_name_set(cJSON *cj_room)
cJSON_DeleteItemFromObject(cj_room_tmp, ezlopi_name_str);
ret = cJSON_AddItemReferenceToObject(cj_room_tmp, ezlopi_name_str, cj_room_name);
- s_ezlopi_room_t *room_node = l_room_head;
+ s_ezlopi_room_t* room_node = l_room_head;
while (room_node)
{
if (room_node->_id == room_id)
@@ -83,7 +84,7 @@ int ezlopi_room_name_set(cJSON *cj_room)
if (ret)
{
- char *updated_rooms = cJSON_Print(cj_rooms);
+ char* updated_rooms = cJSON_Print(cj_rooms);
if (updated_rooms)
{
cJSON_Minify(updated_rooms);
@@ -102,13 +103,13 @@ int ezlopi_room_name_set(cJSON *cj_room)
return ret;
}
-int ezlopi_room_delete(cJSON *cj_room)
+int ezlopi_room_delete(cJSON* cj_room)
{
int ret = 0;
if (cj_room)
{
CJSON_TRACE("cj_room", cj_room);
- cJSON *cj_room_id = cJSON_GetObjectItem(cj_room, ezlopi__id_str);
+ cJSON* cj_room_id = cJSON_GetObjectItem(cj_room, ezlopi__id_str);
if (cj_room_id && cj_room_id->valuestring)
{
@@ -142,7 +143,7 @@ int ezlopi_room_delete_all(void)
return ret;
}
-int ezlopi_room_add_to_nvs(cJSON *cj_room)
+int ezlopi_room_add_to_nvs(cJSON* cj_room)
{
CJSON_TRACE("cj_room", cj_room);
@@ -150,7 +151,7 @@ int ezlopi_room_add_to_nvs(cJSON *cj_room)
if (cj_room)
{
int room_free = 1;
- char *rooms_str = ezlopi_nvs_read_rooms();
+ char* rooms_str = ezlopi_nvs_read_rooms();
if (NULL == rooms_str)
{
@@ -158,7 +159,7 @@ int ezlopi_room_add_to_nvs(cJSON *cj_room)
room_free = 0;
}
- cJSON *cj_rooms = cJSON_Parse(rooms_str);
+ cJSON* cj_rooms = cJSON_Parse(rooms_str);
if (room_free)
{
free(rooms_str);
@@ -172,7 +173,7 @@ int ezlopi_room_add_to_nvs(cJSON *cj_room)
{
CJSON_TRACE("cj_rooms", cj_rooms);
- char *updated_rooms_str = cJSON_Print(cj_rooms);
+ char* updated_rooms_str = cJSON_Print(cj_rooms);
if (updated_rooms_str)
{
cJSON_Minify(updated_rooms_str);
@@ -194,7 +195,7 @@ int ezlopi_room_add_to_nvs(cJSON *cj_room)
return ret;
}
-int ezlopi_room_reorder(cJSON *cj_rooms_ids)
+int ezlopi_room_reorder(cJSON* cj_rooms_ids)
{
int ret = 0;
@@ -206,25 +207,25 @@ int ezlopi_room_reorder(cJSON *cj_rooms_ids)
if (rooms_id_arr_size)
{
int idx = 0;
- cJSON *cj_reordered_rooms = cJSON_CreateArray();
+ cJSON* cj_reordered_rooms = cJSON_CreateArray();
if (cj_reordered_rooms)
{
- cJSON *cj_room_id = NULL;
+ cJSON* cj_room_id = NULL;
while (NULL != (cj_room_id = cJSON_GetArrayItem(cj_rooms_ids, idx)))
{
uint32_t room_id = strtoul(cj_room_id->valuestring, NULL, 16);
if (room_id)
{
- s_ezlopi_room_t *room_node = l_room_head;
+ s_ezlopi_room_t* room_node = l_room_head;
while (room_node)
{
if (room_id == room_node->_id)
{
room_node->_pos = idx;
- cJSON *cj_room = cJSON_CreateObject();
+ cJSON* cj_room = cJSON_CreateObject();
if (cj_room)
{
cJSON_AddStringToObject(cj_room, ezlopi__id_str, cj_room_id->valuestring);
@@ -248,7 +249,7 @@ int ezlopi_room_reorder(cJSON *cj_rooms_ids)
if (cJSON_GetArraySize(cj_reordered_rooms))
{
- char *reordered_rooms_str = cJSON_Print(cj_reordered_rooms);
+ char* reordered_rooms_str = cJSON_Print(cj_reordered_rooms);
if (reordered_rooms_str)
{
cJSON_Minify(reordered_rooms_str);
@@ -262,7 +263,7 @@ int ezlopi_room_reorder(cJSON *cj_rooms_ids)
#if 0
int idx = 0;
- cJSON *cj_room_id = NULL;
+ cJSON* cj_room_id = NULL;
uint32_t rooms_id_arr[rooms_id_arr_size];
while (NULL != (cj_room_id = cJSON_GetArrayItem(cj_rooms_ids, idx)))
@@ -270,17 +271,17 @@ int ezlopi_room_reorder(cJSON *cj_rooms_ids)
rooms_id_arr[idx] = strtoul(cj_room_id->valuestring, NULL, 16);
idx++;
}
- char *room_list_str = ezlopi_nvs_read_rooms();
+ char* room_list_str = ezlopi_nvs_read_rooms();
if (room_list_str)
{
TRACE_D("old-order list: %s", room_list_str);
- cJSON *cj_stored_room_list = cJSON_Parse(room_list_str);
+ cJSON* cj_stored_room_list = cJSON_Parse(room_list_str);
free(room_list_str);
if (cj_stored_room_list)
{
- cJSON *cj_reordered_rooms = cJSON_CreateArray();
+ cJSON* cj_reordered_rooms = cJSON_CreateArray();
if (cj_reordered_rooms)
{
@@ -288,10 +289,10 @@ int ezlopi_room_reorder(cJSON *cj_rooms_ids)
while (idx1 < rooms_id_arr_size)
{
int idx2 = 0;
- cJSON *cj_stored_room = NULL;
+ cJSON* cj_stored_room = NULL;
while (NULL != (cj_stored_room = cJSON_GetArrayItem(cj_stored_room_list, idx2)))
{
- cJSON *cj_stored_room_id = cJSON_GetObjectItem(cj_stored_room, ezlopi__id_str);
+ cJSON* cj_stored_room_id = cJSON_GetObjectItem(cj_stored_room, ezlopi__id_str);
if (cj_stored_room_id && cj_stored_room_id->valuestring)
{
uint32_t stored_room_id = strtoul(cj_stored_room_id->valuestring, NULL, 16);
@@ -308,7 +309,7 @@ int ezlopi_room_reorder(cJSON *cj_rooms_ids)
idx1++;
}
- char *reordered_rooms_str = cJSON_Print(cj_reordered_rooms);
+ char* reordered_rooms_str = cJSON_Print(cj_reordered_rooms);
cJSON_Delete(cj_reordered_rooms);
if (reordered_rooms_str)
@@ -330,9 +331,9 @@ int ezlopi_room_reorder(cJSON *cj_rooms_ids)
return ret;
}
-s_ezlopi_room_t *ezlopi_room_add_to_list(cJSON *cj_room)
+s_ezlopi_room_t* ezlopi_room_add_to_list(cJSON* cj_room)
{
- s_ezlopi_room_t *new_room = malloc(sizeof(s_ezlopi_room_t));
+ s_ezlopi_room_t* new_room = malloc(sizeof(s_ezlopi_room_t));
if (new_room)
{
memset(new_room, 0, sizeof(s_ezlopi_room_t));
@@ -341,7 +342,7 @@ s_ezlopi_room_t *ezlopi_room_add_to_list(cJSON *cj_room)
{
CJSON_TRACE("room", cj_room);
- cJSON *cj_room_id = cJSON_GetObjectItem(cj_room, ezlopi__id_str);
+ cJSON* cj_room_id = cJSON_GetObjectItem(cj_room, ezlopi__id_str);
if (cj_room_id && cj_room_id->valuestring)
{
new_room->_id = strtoul(cj_room_id->valuestring, NULL, 16);
@@ -355,7 +356,7 @@ s_ezlopi_room_t *ezlopi_room_add_to_list(cJSON *cj_room)
cJSON_AddStringToObject(cj_room, ezlopi__id_str, tmp_str);
}
- cJSON *cj_room_subtype = cJSON_GetObjectItem(cj_room, ezlopi_subtype_str);
+ cJSON* cj_room_subtype = cJSON_GetObjectItem(cj_room, ezlopi_subtype_str);
if (cj_room_subtype && cj_room_subtype->valuestring)
{
new_room->subtype = __get_subtype_enum(cj_room_subtype->valuestring);
@@ -365,7 +366,7 @@ s_ezlopi_room_t *ezlopi_room_add_to_list(cJSON *cj_room)
new_room->subtype = ROOM_SUBTYPE_NONE;
}
- cJSON *cj_room_name = cJSON_GetObjectItem(cj_room, ezlopi_name_str);
+ cJSON* cj_room_name = cJSON_GetObjectItem(cj_room, ezlopi_name_str);
if (cj_room_name && cj_room_name->valuestring)
{
snprintf(new_room->name, sizeof(new_room->name), "%s", cj_room_name->valuestring);
@@ -378,21 +379,21 @@ s_ezlopi_room_t *ezlopi_room_add_to_list(cJSON *cj_room)
void ezlopi_room_init(void)
{
- char *rooms_str = ezlopi_nvs_read_rooms();
+ char* rooms_str = ezlopi_nvs_read_rooms();
if (rooms_str)
{
- cJSON *cj_rooms = cJSON_Parse(rooms_str);
+ cJSON* cj_rooms = cJSON_Parse(rooms_str);
free(rooms_str);
if (cj_rooms)
{
int idx = 0;
- cJSON *cj_room = NULL;
- s_ezlopi_room_t *curr_room_node = NULL;
+ cJSON* cj_room = NULL;
+ s_ezlopi_room_t* curr_room_node = NULL;
while (NULL != (cj_room = cJSON_GetArrayItem(cj_rooms, idx)))
{
- s_ezlopi_room_t *new_room = ezlopi_room_add_to_list(cj_rooms);
+ s_ezlopi_room_t* new_room = ezlopi_room_add_to_list(cj_rooms);
if (new_room)
{
new_room->_pos = idx;
@@ -416,13 +417,13 @@ void ezlopi_room_init(void)
static void __update_cloud_room_deleted(uint32_t room_id)
{
- cJSON *cj_response = cJSON_CreateObject();
+ cJSON* cj_response = cJSON_CreateObject();
{
cJSON_AddStringToObject(cj_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
cJSON_AddStringToObject(cj_response, ezlopi_msg_subclass_str, ezlopi_hub_room_deleted_str);
cJSON_AddStringToObject(cj_response, ezlopi_method_str, "hub.room.all.delete");
- cJSON *cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
char tmp_str[32];
@@ -430,19 +431,21 @@ static void __update_cloud_room_deleted(uint32_t room_id)
cJSON_AddStringToObject(cj_result, ezlopi__id_str, tmp_str);
}
- char *data_str = cJSON_Print(cj_response);
+ char* data_str = cJSON_Print(cj_response);
cJSON_Delete(cj_response);
if (data_str)
{
cJSON_Minify(data_str);
- web_provisioning_send_str_data_to_nma_websocket(data_str, TRACE_TYPE_B);
- free(data_str);
+ ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_str, TRACE_TYPE_B);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data_str)) {
+ free(data_str);
+ }
}
}
}
-static void __free_nodes(s_ezlopi_room_t *room)
+static void __free_nodes(s_ezlopi_room_t* room)
{
if (room)
{
@@ -455,8 +458,8 @@ static void __free_nodes(s_ezlopi_room_t *room)
static void __sort_by_pos(void)
{
uint32_t size = 0;
- s_ezlopi_room_t *room_ptr_arr[32];
- s_ezlopi_room_t *curr_room = l_room_head;
+ s_ezlopi_room_t* room_ptr_arr[32];
+ s_ezlopi_room_t* curr_room = l_room_head;
curr_room = l_room_head;
memset(room_ptr_arr, 0, sizeof(room_ptr_arr));
@@ -493,7 +496,7 @@ static void __sort_by_pos(void)
// return ret;
// }
-static e_room_subtype_t __get_subtype_enum(char *subtype_str)
+static e_room_subtype_t __get_subtype_enum(char* subtype_str)
{
e_room_subtype_t ret = ROOM_SUBTYPE_NONE;
@@ -523,17 +526,17 @@ static int __free_room_from_list_by_id(uint32_t room_id)
if (l_room_head->_id == room_id)
{
ret = 1;
- s_ezlopi_room_t *free_node = l_room_head;
+ s_ezlopi_room_t* free_node = l_room_head;
l_room_head = l_room_head->next;
free(free_node);
}
else
{
- s_ezlopi_room_t *room_node = l_room_head;
+ s_ezlopi_room_t* room_node = l_room_head;
while (room_node->next)
{
- s_ezlopi_room_t *free_node = room_node->next;
+ s_ezlopi_room_t* free_node = room_node->next;
TRACE_I("free_node->_id == room_id -> %8x == %8x", free_node->_id, room_id);
if (free_node->_id == room_id)
@@ -555,12 +558,12 @@ static int __free_room_from_list_by_id(uint32_t room_id)
static int __remove_room_from_nvs_by_id(uint32_t a_room_id)
{
int ret = 0;
- char *rooms_str = ezlopi_nvs_read_rooms();
+ char* rooms_str = ezlopi_nvs_read_rooms();
if (rooms_str)
{
TRACE_I("rooms_str: %s", rooms_str);
- cJSON *cj_rooms = cJSON_Parse(rooms_str);
+ cJSON* cj_rooms = cJSON_Parse(rooms_str);
free(rooms_str);
if (cj_rooms)
@@ -568,13 +571,13 @@ static int __remove_room_from_nvs_by_id(uint32_t a_room_id)
CJSON_TRACE("cj_rooms", cj_rooms);
int idx = 0;
- cJSON *cj_room_tmp = NULL;
+ cJSON* cj_room_tmp = NULL;
while (NULL != (cj_room_tmp = cJSON_GetArrayItem(cj_rooms, idx)))
{
CJSON_TRACE("cj_room_tmp", cj_room_tmp);
- cJSON *cj_room_tmp_id = cJSON_GetObjectItem(cj_room_tmp, ezlopi__id_str);
+ cJSON* cj_room_tmp_id = cJSON_GetObjectItem(cj_room_tmp, ezlopi__id_str);
if (cj_room_tmp_id && cj_room_tmp_id->valuestring)
{
CJSON_TRACE("cj_room_tmp_id", cj_room_tmp_id);
@@ -595,7 +598,7 @@ static int __remove_room_from_nvs_by_id(uint32_t a_room_id)
if (ret)
{
CJSON_TRACE("cj_rooms", cj_rooms);
- char *updated_rooms = cJSON_Print(cj_rooms);
+ char* updated_rooms = cJSON_Print(cj_rooms);
if (updated_rooms)
{
diff --git a/ezlopi-core/ezlopi-core-scenes/CMakeLists.txt b/ezlopi-core/ezlopi-core-scenes/CMakeLists.txt
index 3934077e8..b20700e40 100644
--- a/ezlopi-core/ezlopi-core-scenes/CMakeLists.txt
+++ b/ezlopi-core/ezlopi-core-scenes/CMakeLists.txt
@@ -2,7 +2,7 @@
file(GLOB_RECURSE config_src "*.c")
-idf_component_register(SRCS "ezlopi_core_scenes_when_methods.c" "ezlopi_core_scenes_cjson.c" "ezlopi_core_scenes_print.c" "ezlopi_core_scenes_value.c" "${config_src}"
+idf_component_register(SRCS "ezlopi_core_scenes_scripts.c" "${config_src}"
INCLUDE_DIRS "."
REQUIRES core
- )
\ No newline at end of file
+ )
\ No newline at end of file
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_cjson.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_cjson.c
index a0680467f..1e7ff4361 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_cjson.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_cjson.c
@@ -8,19 +8,19 @@
#include "ezlopi_cloud_constants.h"
-static void __cjson_add_fields(cJSON *cj_block, l_fields_v2_t *fields);
-static void __cjson_add_string(cJSON *root, const char *key, const char *value);
-static void __cjson_add_action_delay(cJSON *cj_then_block, s_action_delay_v2_t *action_delay);
-static void __cjson_add_action_block_options(cJSON *cj_block_array, l_action_block_v2_t *then_block);
+static void __cjson_add_fields(cJSON* cj_block, l_fields_v2_t* fields);
+static void __cjson_add_string(cJSON* root, const char* key, const char* value);
+static void __cjson_add_action_delay(cJSON* cj_then_block, s_action_delay_v2_t* action_delay);
+static void __cjson_add_action_block_options(cJSON* cj_block_array, l_action_block_v2_t* then_block);
-cJSON *ezlopi_scene_cjson_get_field(l_fields_v2_t *field_node)
+cJSON* ezlopi_scene_cjson_get_field(l_fields_v2_t* field_node)
{
- cJSON *cj_field = NULL;
+ cJSON* cj_field = NULL;
if (field_node)
{
cj_field = cJSON_CreateObject();
{
- const char *value_type_str = ezlopi_scene_get_scene_value_type_name(field_node->value_type);
+ const char* value_type_str = ezlopi_scene_get_scene_value_type_name(field_node->value_type);
if (value_type_str)
{
cJSON_AddStringToObject(cj_field, ezlopi_type_str, value_type_str);
@@ -37,12 +37,14 @@ cJSON *ezlopi_scene_cjson_get_field(l_fields_v2_t *field_node)
case EZLOPI_VALUE_TYPE_INT:
case EZLOPI_VALUE_TYPE_FLOAT:
{
- cJSON_AddNumberToObject(cj_field, ezlopi_value_str, field_node->value.value_double);
+ cJSON_AddNumberToObject(cj_field, ezlopi_value_str, field_node->field_value.u_value.value_double);
+ // cJSON_AddNumberToObject(cj_field, ezlopi_value_str, field_node->value.value_double);
break;
}
case EZLOPI_VALUE_TYPE_BOOL:
{
- if (0 == field_node->value.value_double)
+ if (0 == field_node->field_value.u_value.value_double)
+ // if (0 == field_node->value.value_double)
{
cJSON_AddFalseToObject(cj_field, ezlopi_value_str);
}
@@ -56,18 +58,20 @@ cJSON *ezlopi_scene_cjson_get_field(l_fields_v2_t *field_node)
case EZLOPI_VALUE_TYPE_STRING:
case EZLOPI_VALUE_TYPE_INTERVAL:
{
- __cjson_add_string(cj_field, ezlopi_value_str, field_node->value.value_string);
+ __cjson_add_string(cj_field, ezlopi_value_str, field_node->field_value.u_value.value_string);
+ // __cjson_add_string(cj_field, ezlopi_value_str, field_node->value.value_string);
break;
}
case EZLOPI_VALUE_TYPE_BLOCKS:
{
- cJSON *vlaue_block_array = cJSON_AddArrayToObject(cj_field, ezlopi_value_str);
+ cJSON* vlaue_block_array = cJSON_AddArrayToObject(cj_field, ezlopi_value_str);
if (vlaue_block_array)
{
- l_when_block_v2_t *curr_when_block = field_node->value.when_block;
+ l_when_block_v2_t* curr_when_block = field_node->field_value.u_value.when_block;
+ // l_when_block_v2_t* curr_when_block = field_node->value.when_block;
while (curr_when_block)
{
- cJSON *cj_when_block = ezlopi_scenes_cjson_create_when_block(curr_when_block);
+ cJSON* cj_when_block = ezlopi_scenes_cjson_create_when_block(curr_when_block);
if (cj_when_block)
{
if (!cJSON_AddItemToArray(vlaue_block_array, cj_when_block))
@@ -150,7 +154,7 @@ cJSON *ezlopi_scene_cjson_get_field(l_fields_v2_t *field_node)
}
default:
{
- const char *value_type_name = ezlopi_scene_get_scene_value_type_name(field_node->value_type);
+ const char* value_type_name = ezlopi_scene_get_scene_value_type_name(field_node->value_type);
TRACE_E("Value type not matched!, curr-type[%d]: %s ", field_node->value_type, value_type_name ? value_type_name : ezlopi_null_str);
break;
}
@@ -161,16 +165,16 @@ cJSON *ezlopi_scene_cjson_get_field(l_fields_v2_t *field_node)
return cj_field;
}
-static void ezlopi_scenes_cjson_add_user_notifications(cJSON *root, l_user_notification_v2_t *user_notifications)
+static void ezlopi_scenes_cjson_add_user_notifications(cJSON* root, l_user_notification_v2_t* user_notifications)
{
if (root)
{
- cJSON *cj_user_notifications_array = cJSON_AddArrayToObject(root, ezlopi_user_notifications_str);
+ cJSON* cj_user_notifications_array = cJSON_AddArrayToObject(root, ezlopi_user_notifications_str);
if (cj_user_notifications_array)
{
while (user_notifications)
{
- cJSON *array_item = cJSON_CreateString(user_notifications->user_id);
+ cJSON* array_item = cJSON_CreateString(user_notifications->user_id);
if (array_item)
{
if (!cJSON_AddItemToArray(cj_user_notifications_array, array_item))
@@ -184,16 +188,16 @@ static void ezlopi_scenes_cjson_add_user_notifications(cJSON *root, l_user_notif
}
}
-static void ezlopi_scenes_cjson_add_house_modes(cJSON *root, l_house_modes_v2_t *house_modes)
+static void ezlopi_scenes_cjson_add_house_modes(cJSON* root, l_house_modes_v2_t* house_modes)
{
if (root)
{
- cJSON *cj_user_notifications_array = cJSON_AddArrayToObject(root, ezlopi_house_modes_str);
+ cJSON* cj_user_notifications_array = cJSON_AddArrayToObject(root, ezlopi_house_modes_str);
if (cj_user_notifications_array)
{
while (house_modes)
{
- cJSON *array_item = cJSON_CreateString(house_modes->house_mode);
+ cJSON* array_item = cJSON_CreateString(house_modes->house_mode);
if (array_item)
{
if (!cJSON_AddItemToArray(cj_user_notifications_array, array_item))
@@ -207,20 +211,20 @@ static void ezlopi_scenes_cjson_add_house_modes(cJSON *root, l_house_modes_v2_t
}
}
-static void ezlopi_scenes_cjson_add_when_block_options(cJSON *cj_block_array, l_when_block_v2_t *when_block)
+static void ezlopi_scenes_cjson_add_when_block_options(cJSON* cj_block_array, l_when_block_v2_t* when_block)
{
if (cj_block_array && when_block)
{
- cJSON *cj_block_options = cJSON_AddObjectToObject(cj_block_array, ezlopi_blockOptions_str);
+ cJSON* cj_block_options = cJSON_AddObjectToObject(cj_block_array, ezlopi_blockOptions_str);
if (cj_block_options)
{
- cJSON *cj_method = cJSON_AddObjectToObject(cj_block_options, ezlopi_method_str);
+ cJSON* cj_method = cJSON_AddObjectToObject(cj_block_options, ezlopi_method_str);
if (cj_method)
{
if ((when_block->block_options.method.type > EZLOPI_SCENE_METHOD_TYPE_NONE) &&
(when_block->block_options.method.type < EZLOPI_SCENE_METHOD_TYPE_MAX))
{
- const char *method_type_name = ezlopi_scene_get_scene_method_name(when_block->block_options.method.type);
+ const char* method_type_name = ezlopi_scene_get_scene_method_name(when_block->block_options.method.type);
__cjson_add_string(cj_method, ezlopi_name_str, method_type_name ? method_type_name : ezlopi__str);
}
else
@@ -228,10 +232,10 @@ static void ezlopi_scenes_cjson_add_when_block_options(cJSON *cj_block_array, l_
TRACE_E("Method type error");
}
- cJSON *cj_args = cJSON_AddObjectToObject(cj_method, ezlopi_args_str);
+ cJSON* cj_args = cJSON_AddObjectToObject(cj_method, ezlopi_args_str);
if (cj_args)
{
- l_fields_v2_t *curr_field = when_block->fields;
+ l_fields_v2_t* curr_field = when_block->fields;
while (curr_field)
{
cJSON_AddStringToObject(cj_args, curr_field->name, curr_field->name);
@@ -243,22 +247,22 @@ static void ezlopi_scenes_cjson_add_when_block_options(cJSON *cj_block_array, l_
}
}
-static void __cjson_add_action_block_options(cJSON *cj_block_array, l_action_block_v2_t *action_block)
+static void __cjson_add_action_block_options(cJSON* cj_block_array, l_action_block_v2_t* action_block)
{
if (cj_block_array && action_block)
{
- cJSON *cj_block_options = cJSON_AddObjectToObject(cj_block_array, ezlopi_blockOptions_str);
+ cJSON* cj_block_options = cJSON_AddObjectToObject(cj_block_array, ezlopi_blockOptions_str);
if (cj_block_options)
{
- cJSON *cj_method = cJSON_AddObjectToObject(cj_block_options, ezlopi_method_str);
+ cJSON* cj_method = cJSON_AddObjectToObject(cj_block_options, ezlopi_method_str);
if (cj_method)
{
if ((action_block->block_options.method.type > EZLOPI_SCENE_METHOD_TYPE_NONE) &&
(action_block->block_options.method.type < EZLOPI_SCENE_METHOD_TYPE_MAX))
{
- const char *method_type_name = ezlopi_scene_get_scene_method_name(action_block->block_options.method.type);
+ const char* method_type_name = ezlopi_scene_get_scene_method_name(action_block->block_options.method.type);
__cjson_add_string(cj_method, ezlopi_name_str, method_type_name ? method_type_name : ezlopi__str);
}
else
@@ -266,10 +270,10 @@ static void __cjson_add_action_block_options(cJSON *cj_block_array, l_action_blo
TRACE_E("Method type error");
}
- cJSON *cj_args = cJSON_AddObjectToObject(cj_method, ezlopi_args_str);
+ cJSON* cj_args = cJSON_AddObjectToObject(cj_method, ezlopi_args_str);
if (cj_args)
{
- l_fields_v2_t *curr_field = action_block->fields;
+ l_fields_v2_t* curr_field = action_block->fields;
while (curr_field)
{
cJSON_AddStringToObject(cj_args, curr_field->name, curr_field->name);
@@ -281,13 +285,13 @@ static void __cjson_add_action_block_options(cJSON *cj_block_array, l_action_blo
}
}
-static void __cjson_add_action_delay(cJSON *cj_action_block, s_action_delay_v2_t *action_delay)
+static void __cjson_add_action_delay(cJSON* cj_action_block, s_action_delay_v2_t* action_delay)
{
if (cj_action_block && action_delay)
{
if (action_delay->days || action_delay->hours || action_delay->minutes || action_delay->seconds)
{
- cJSON *cj_action_delay = cJSON_AddObjectToObject(cj_action_block, ezlopi_delay_str);
+ cJSON* cj_action_delay = cJSON_AddObjectToObject(cj_action_block, ezlopi_delay_str);
if (cj_action_delay)
{
cJSON_AddNumberToObject(cj_action_delay, "days", action_delay->days);
@@ -299,21 +303,21 @@ static void __cjson_add_action_delay(cJSON *cj_action_block, s_action_delay_v2_t
}
}
-static void __cjson_add_fields(cJSON *cj_block, l_fields_v2_t *fields)
+static void __cjson_add_fields(cJSON* cj_block, l_fields_v2_t* fields)
{
if (cj_block)
{
- cJSON *cj_fields_array = cJSON_AddArrayToObject(cj_block, ezlopi_fields_str);
+ cJSON* cj_fields_array = cJSON_AddArrayToObject(cj_block, ezlopi_fields_str);
if (cj_fields_array)
{
- l_fields_v2_t *curr_field = fields;
+ l_fields_v2_t* curr_field = fields;
while (curr_field)
{
- cJSON *cj_field = cJSON_CreateObject();
+ cJSON* cj_field = cJSON_CreateObject();
if (cj_field)
{
__cjson_add_string(cj_field, ezlopi_name_str, curr_field->name);
- const char *value_type_name = ezlopi_scene_get_scene_value_type_name(curr_field->value_type);
+ const char* value_type_name = ezlopi_scene_get_scene_value_type_name(curr_field->value_type);
__cjson_add_string(cj_field, ezlopi_type_str, value_type_name ? value_type_name : ezlopi__str);
switch (curr_field->value_type)
@@ -324,12 +328,13 @@ static void __cjson_add_fields(cJSON *cj_block, l_fields_v2_t *fields)
}
case EZLOPI_VALUE_TYPE_INT:
{
- cJSON_AddNumberToObject(cj_field, ezlopi_value_str, curr_field->value.value_double);
+ cJSON_AddNumberToObject(cj_field, ezlopi_value_str, curr_field->field_value.u_value.value_double);
+ // cJSON_AddNumberToObject(cj_field, ezlopi_value_str, curr_field->field_value.u_value.value_double);
break;
}
case EZLOPI_VALUE_TYPE_BOOL:
{
- if (0 == curr_field->value.value_double)
+ if (0 == curr_field->field_value.u_value.value_double)
{
cJSON_AddFalseToObject(cj_field, ezlopi_value_str);
}
@@ -341,33 +346,33 @@ static void __cjson_add_fields(cJSON *cj_block, l_fields_v2_t *fields)
}
case EZLOPI_VALUE_TYPE_FLOAT:
{
- cJSON_AddNumberToObject(cj_field, ezlopi_value_str, curr_field->value.value_double);
+ cJSON_AddNumberToObject(cj_field, ezlopi_value_str, curr_field->field_value.u_value.value_double);
break;
}
case EZLOPI_VALUE_TYPE_STRING:
{
- __cjson_add_string(cj_field, ezlopi_value_str, curr_field->value.value_string);
+ __cjson_add_string(cj_field, ezlopi_value_str, curr_field->field_value.u_value.value_string);
break;
}
case EZLOPI_VALUE_TYPE_ITEM:
{
- __cjson_add_string(cj_field, ezlopi_value_str, curr_field->value.value_string);
+ __cjson_add_string(cj_field, ezlopi_value_str, curr_field->field_value.u_value.value_string);
break;
}
case EZLOPI_VALUE_TYPE_INTERVAL:
{
- __cjson_add_string(cj_field, ezlopi_value_str, curr_field->value.value_string);
+ __cjson_add_string(cj_field, ezlopi_value_str, curr_field->field_value.u_value.value_string);
break;
}
case EZLOPI_VALUE_TYPE_BLOCKS:
{
- cJSON *vlaue_block_array = cJSON_AddArrayToObject(cj_field, ezlopi_value_str);
+ cJSON* vlaue_block_array = cJSON_AddArrayToObject(cj_field, ezlopi_value_str);
if (vlaue_block_array)
{
- l_when_block_v2_t *curr_when_block = curr_field->value.when_block;
+ l_when_block_v2_t* curr_when_block = curr_field->field_value.u_value.when_block;
while (curr_when_block)
{
- cJSON *cj_when_block = NULL;
+ cJSON* cj_when_block = NULL;
// ezlopi_scenes_cjson_create_when_block(curr_when_block);
if (cj_when_block)
{
@@ -386,12 +391,12 @@ static void __cjson_add_fields(cJSON *cj_block, l_fields_v2_t *fields)
case EZLOPI_VALUE_TYPE_HOUSE_MODE_ID:
{
char id_str[32];
- snprintf(id_str, sizeof(id_str), "%u", (uint32_t)curr_field->value.value_double);
+ snprintf(id_str, sizeof(id_str), "%u", (uint32_t)curr_field->field_value.u_value.value_double);
break;
}
case EZLOPI_VALUE_TYPE_HOUSE_MODE_ID_ARRAY:
{
- cJSON_AddItemReferenceToObject(cj_field, ezlopi_value_str, curr_field->value.cj_value);
+ cJSON_AddItemReferenceToObject(cj_field, ezlopi_value_str, curr_field->field_value.u_value.cj_value);
break;
}
case EZLOPI_VALUE_TYPE_DICTIONARY:
@@ -460,7 +465,7 @@ static void __cjson_add_fields(cJSON *cj_block, l_fields_v2_t *fields)
}
default:
{
- const char *value_type_name = ezlopi_scene_get_scene_value_type_name(curr_field->value_type);
+ const char* value_type_name = ezlopi_scene_get_scene_value_type_name(curr_field->value_type);
TRACE_E("Value type not matched!, curr-type[%d]: %s ", curr_field->value_type, value_type_name ? value_type_name : ezlopi_null_str);
break;
}
@@ -478,9 +483,9 @@ static void __cjson_add_fields(cJSON *cj_block, l_fields_v2_t *fields)
}
}
-cJSON *ezlopi_scenes_cjson_create_action_block(l_action_block_v2_t *action_block, char *block_type_str)
+cJSON* ezlopi_scenes_cjson_create_action_block(l_action_block_v2_t* action_block, char* block_type_str)
{
- cJSON *cj_action_block = NULL;
+ cJSON* cj_action_block = NULL;
if (action_block)
{
cj_action_block = cJSON_CreateObject();
@@ -496,17 +501,17 @@ cJSON *ezlopi_scenes_cjson_create_action_block(l_action_block_v2_t *action_block
return cj_action_block;
}
-void ezlopi_scenes_cjson_add_action_blocks(cJSON *root, l_action_block_v2_t *action_blocks, const char *block_type_str)
+void ezlopi_scenes_cjson_add_action_blocks(cJSON* root, l_action_block_v2_t* action_blocks, const char* block_type_str)
{
if (root && action_blocks)
{
- cJSON *cj_then_block_array = cJSON_AddArrayToObject(root, block_type_str);
+ cJSON* cj_then_block_array = cJSON_AddArrayToObject(root, block_type_str);
if (cj_then_block_array)
{
while (action_blocks)
{
- cJSON *cj_then_block = ezlopi_scenes_cjson_create_action_block(action_blocks, (char *)block_type_str);
+ cJSON* cj_then_block = ezlopi_scenes_cjson_create_action_block(action_blocks, (char*)block_type_str);
if (cj_then_block)
{
if (!cJSON_AddItemToArray(cj_then_block_array, cj_then_block))
@@ -521,9 +526,9 @@ void ezlopi_scenes_cjson_add_action_blocks(cJSON *root, l_action_block_v2_t *act
}
}
-cJSON *ezlopi_scenes_cjson_create_when_block(l_when_block_v2_t *when_block)
+cJSON* ezlopi_scenes_cjson_create_when_block(l_when_block_v2_t* when_block)
{
- cJSON *cj_when_block = NULL;
+ cJSON* cj_when_block = NULL;
if (when_block)
{
cj_when_block = cJSON_CreateObject();
@@ -538,16 +543,16 @@ cJSON *ezlopi_scenes_cjson_create_when_block(l_when_block_v2_t *when_block)
return cj_when_block;
}
-void ezlopi_scenes_cjson_add_when_blocks(cJSON *root, l_when_block_v2_t *when_block_node)
+void ezlopi_scenes_cjson_add_when_blocks(cJSON* root, l_when_block_v2_t* when_block_node)
{
if (root)
{
- cJSON *cj_when_block_array = cJSON_AddArrayToObject(root, ezlopi_when_str);
+ cJSON* cj_when_block_array = cJSON_AddArrayToObject(root, ezlopi_when_str);
if (cj_when_block_array)
{
while (when_block_node)
{
- cJSON *cj_when_block = ezlopi_scenes_cjson_create_when_block(when_block_node);
+ cJSON* cj_when_block = ezlopi_scenes_cjson_create_when_block(when_block_node);
if (cj_when_block)
{
if (!cJSON_AddItemToArray(cj_when_block_array, cj_when_block))
@@ -562,15 +567,15 @@ void ezlopi_scenes_cjson_add_when_blocks(cJSON *root, l_when_block_v2_t *when_bl
}
}
-cJSON *ezlopi_scenes_create_cjson_scene(l_scenes_list_v2_t *scene)
+cJSON* ezlopi_scenes_create_cjson_scene(l_scenes_list_v2_t* scene)
{
- cJSON *cj_scene = NULL;
+ cJSON* cj_scene = NULL;
if (scene)
{
cj_scene = cJSON_CreateObject();
if (cj_scene)
{
- char tmp_str[16] = {0};
+ char tmp_str[16] = { 0 };
snprintf(tmp_str, sizeof(tmp_str), "%08x", scene->_id);
cJSON_AddStringToObject(cj_scene, ezlopi__id_str, tmp_str);
cJSON_AddBoolToObject(cj_scene, ezlopi_enabled_str, scene->enabled);
@@ -591,14 +596,14 @@ cJSON *ezlopi_scenes_create_cjson_scene(l_scenes_list_v2_t *scene)
return cj_scene;
}
-cJSON *ezlopi_scenes_create_cjson_scene_list(l_scenes_list_v2_t *scenes_list)
+cJSON* ezlopi_scenes_create_cjson_scene_list(l_scenes_list_v2_t* scenes_list)
{
- cJSON *cj_scenes_array = cJSON_CreateArray();
+ cJSON* cj_scenes_array = cJSON_CreateArray();
if (cj_scenes_array)
{
while (scenes_list)
{
- cJSON *cj_scene = ezlopi_scenes_create_cjson_scene(scenes_list);
+ cJSON* cj_scene = ezlopi_scenes_create_cjson_scene(scenes_list);
if (cj_scene)
{
if (!cJSON_AddItemToArray(cj_scenes_array, cj_scene))
@@ -613,11 +618,11 @@ cJSON *ezlopi_scenes_create_cjson_scene_list(l_scenes_list_v2_t *scenes_list)
return cj_scenes_array;
}
-char *ezlopi_scenes_create_json_string(l_scenes_list_v2_t *scenes_list)
+char* ezlopi_scenes_create_json_string(l_scenes_list_v2_t* scenes_list)
{
- char *scenes_list_str = NULL;
+ char* scenes_list_str = NULL;
- cJSON *cj_scenes_array = ezlopi_scenes_create_cjson_scene_list(scenes_list);
+ cJSON* cj_scenes_array = ezlopi_scenes_create_cjson_scene_list(scenes_list);
if (cj_scenes_array)
{
scenes_list_str = cJSON_Print(cj_scenes_array);
@@ -631,7 +636,7 @@ char *ezlopi_scenes_create_json_string(l_scenes_list_v2_t *scenes_list)
return scenes_list_str;
}
-static void __cjson_add_string(cJSON *root, const char *key, const char *value)
+static void __cjson_add_string(cJSON* root, const char* key, const char* value)
{
if (root && key && value)
{
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_delete.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_delete.c
index 927763985..d3243a043 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_delete.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_delete.c
@@ -2,7 +2,7 @@
#include "ezlopi_core_scenes_v2.h"
-void ezlopi_scenes_delete_user_notifications(l_user_notification_v2_t *user_notifications)
+void ezlopi_scenes_delete_user_notifications(l_user_notification_v2_t* user_notifications)
{
if (user_notifications)
{
@@ -12,7 +12,7 @@ void ezlopi_scenes_delete_user_notifications(l_user_notification_v2_t *user_noti
}
}
-void ezlopi_scenes_delete_house_modes(l_house_modes_v2_t *house_modes)
+void ezlopi_scenes_delete_house_modes(l_house_modes_v2_t* house_modes)
{
if (house_modes)
{
@@ -22,7 +22,7 @@ void ezlopi_scenes_delete_house_modes(l_house_modes_v2_t *house_modes)
}
}
-void ezlopi_scenes_delete_fields(l_fields_v2_t *fields)
+void ezlopi_scenes_delete_fields(l_fields_v2_t* fields)
{
if (fields)
{
@@ -34,7 +34,7 @@ void ezlopi_scenes_delete_fields(l_fields_v2_t *fields)
}
}
-void ezlopi_scenes_delete_action_blocks(l_action_block_v2_t *action_blocks)
+void ezlopi_scenes_delete_action_blocks(l_action_block_v2_t* action_blocks)
{
if (action_blocks)
{
@@ -45,7 +45,7 @@ void ezlopi_scenes_delete_action_blocks(l_action_block_v2_t *action_blocks)
}
}
-void ezlopi_scenes_delete_when_blocks(l_when_block_v2_t *when_blocks)
+void ezlopi_scenes_delete_when_blocks(l_when_block_v2_t* when_blocks)
{
if (when_blocks)
{
@@ -56,7 +56,7 @@ void ezlopi_scenes_delete_when_blocks(l_when_block_v2_t *when_blocks)
}
}
-void ezlopi_scenes_delete(l_scenes_list_v2_t *scenes_list)
+void ezlopi_scenes_delete(l_scenes_list_v2_t* scenes_list)
{
if (scenes_list)
{
@@ -77,44 +77,59 @@ void ezlopi_scenes_delete(l_scenes_list_v2_t *scenes_list)
// ezlopi_scenes_delete(ezlopi_scenes_pop_by_id_v2(_id));
// }
-void ezlopi_scenes_delete_field_value(l_fields_v2_t *field)
+void ezlopi_scenes_delete_field_value(l_fields_v2_t* field)
{
- switch (field->value.type)
+ switch (field->field_value.e_type)
+ // switch (field->value.type)
{
case VALUE_TYPE_NUMBER:
{
- field->value.value_double = 0;
+ field->field_value.u_value.value_double = 0;
+ // field->value.value_double = 0;
break;
}
case VALUE_TYPE_STRING:
{
- if (field->value.value_string)
+ if (field->field_value.u_value.value_string)
+ // if (field->value.value_string)
{
- free(field->value.value_string);
- field->value.value_string = NULL;
+ free(field->field_value.u_value.value_string);
+ field->field_value.u_value.value_string = NULL;
+
+ // free(field->value.value_string);
+ // field->value.value_string = NULL;
}
break;
}
case VALUE_TYPE_BOOL:
{
- field->value.value_bool = false;
+ field->field_value.u_value.value_bool = false;
+ // field->value.value_bool = false;
break;
}
case VALUE_TYPE_CJSON:
{
- if (field->value.cj_value)
+ if (field->field_value.u_value.cj_value)
+ // if (field->value.cj_value)
{
- cJSON_Delete(field->value.cj_value);
- field->value.cj_value = NULL;
+ cJSON_Delete(field->field_value.u_value.cj_value);
+ field->field_value.u_value.cj_value = NULL;
+
+ // cJSON_Delete(field->value.cj_value);
+ // field->value.cj_value = NULL;
}
break;
}
case VALUE_TYPE_BLOCK:
{
- if (field->value.when_block)
+ if (field->field_value.u_value.when_block)
+ // if (field->value.when_block)
{
- ezlopi_scenes_delete_when_blocks(field->value.when_block);
- field->value.when_block = NULL;
+ ezlopi_scenes_delete_when_blocks(field->field_value.u_value.when_block);
+ field->field_value.u_value.when_block = NULL;
+
+ // ezlopi_scenes_delete_when_blocks(field->value.when_block);
+ // field->value.when_block = NULL;
}
break;
}
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_operators.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_operators.c
index 814ab7cbe..29923e684 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_operators.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_operators.c
@@ -10,25 +10,25 @@
#include "ezlopi_cloud_constants.h"
/************* Numeric ************/
-static const char *const ezlopi_scenes_num_cmp_operators_op[] = {
+static const char* const ezlopi_scenes_num_cmp_operators_op[] = {
#define SCENES_NUM_COMP_OPERATORS(OPERATOR, op, name, method) op,
#include "__operators_macros/__numeric_comparision_operators_macros.h"
#undef SCENES_NUM_COMP_OPERATORS
};
-static const char *const ezlopi_scenes_num_cmp_operators_name[] = {
+static const char* const ezlopi_scenes_num_cmp_operators_name[] = {
#define SCENES_NUM_COMP_OPERATORS(OPERATOR, op, name, method) name,
#include "__operators_macros/__numeric_comparision_operators_macros.h"
#undef SCENES_NUM_COMP_OPERATORS
};
-static const char *const ezlopi_scenes_num_cmp_operators_method[] = {
+static const char* const ezlopi_scenes_num_cmp_operators_method[] = {
#define SCENES_NUM_COMP_OPERATORS(OPERATOR, op, name, method) method,
#include "__operators_macros/__numeric_comparision_operators_macros.h"
#undef SCENES_NUM_COMP_OPERATORS
};
-e_scene_num_cmp_operators_t ezlopi_scenes_numeric_comparator_operators_get_enum(char *operator_str)
+e_scene_num_cmp_operators_t ezlopi_scenes_numeric_comparator_operators_get_enum(char* operator_str)
{
e_scene_num_cmp_operators_t ret = SCENES_NUM_COMP_OPERATORS_NONE + 1;
if (operator_str)
@@ -45,9 +45,9 @@ e_scene_num_cmp_operators_t ezlopi_scenes_numeric_comparator_operators_get_enum(
return ret;
}
-const char *ezlopi_scenes_numeric_comparator_operators_get_op(e_scene_num_cmp_operators_t operator)
+const char* ezlopi_scenes_numeric_comparator_operators_get_op(e_scene_num_cmp_operators_t operator)
{
- const char *ret = NULL;
+ const char* ret = NULL;
if ((operator> SCENES_NUM_COMP_OPERATORS_NONE) && (operator SCENES_NUM_COMP_OPERATORS_NONE) && (operator SCENES_NUM_COMP_OPERATORS_NONE) && (operatoritems;
+ l_ezlopi_item_t* item = device->items;
while (item)
{
if (item->cloud_properties.item_id == item_id)
{
if (cj_item_value)
{
- item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void *)cj_item_value, NULL);
- cJSON *cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
+ item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void*)cj_item_value, NULL);
+ cJSON* cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
if (cj_value)
{
item_value = cj_value->valuedouble;
@@ -109,36 +109,36 @@ int ezlopi_scenes_operators_value_number_operations(uint32_t item_id, l_fields_v
device = device->next;
}
- switch (ezlopi_scenes_numeric_comparator_operators_get_enum(comparator_field->value.value_string))
+ switch (ezlopi_scenes_numeric_comparator_operators_get_enum(comparator_field->field_value.u_value.value_string))
{
case SCENES_NUM_COMP_OPERATORS_LESS:
{
- ret = (item_value < value_field->value.value_double);
+ ret = (item_value < value_field->field_value.u_value.value_double);
break;
}
case SCENES_NUM_COMP_OPERATORS_LESS_EQUAL:
{
- ret = (item_value <= value_field->value.value_double);
+ ret = (item_value <= value_field->field_value.u_value.value_double);
break;
}
case SCENES_NUM_COMP_OPERATORS_GREATER:
{
- ret = (item_value > value_field->value.value_double);
+ ret = (item_value > value_field->field_value.u_value.value_double);
break;
}
case SCENES_NUM_COMP_OPERATORS_GREATER_EQUAL:
{
- ret = (item_value >= value_field->value.value_double);
+ ret = (item_value >= value_field->field_value.u_value.value_double);
break;
}
case SCENES_NUM_COMP_OPERATORS_EQUAL:
{
- ret = (item_value == value_field->value.value_double);
+ ret = (item_value == value_field->field_value.u_value.value_double);
break;
}
case SCENES_NUM_COMP_OPERATORS_NOT_EQUAL:
{
- ret = (item_value != value_field->value.value_double);
+ ret = (item_value != value_field->field_value.u_value.value_double);
break;
}
case SCENES_NUM_COMP_OPERATORS_BETWEEN:
@@ -179,25 +179,25 @@ int ezlopi_scenes_operators_value_number_operations(uint32_t item_id, l_fields_v
}
/************* Strings ************/
-static const char *const ezlopi_scenes_str_cmp_operators_op[] = {
+static const char* const ezlopi_scenes_str_cmp_operators_op[] = {
#define SCENES_STRINGS_OPERATORS(OPERATOR, op, name, method) op,
#include "__operators_macros/__strings_comparision_operators_macros.h"
#undef SCENES_STRINGS_OPERATORS
};
-static const char *const ezlopi_scenes_str_cmp_operators_name[] = {
+static const char* const ezlopi_scenes_str_cmp_operators_name[] = {
#define SCENES_STRINGS_OPERATORS(OPERATOR, op, name, method) name,
#include "__operators_macros/__strings_comparision_operators_macros.h"
#undef SCENES_STRINGS_OPERATORS
};
-static const char *const ezlopi_scenes_str_cmp_operators_method[] = {
+static const char* const ezlopi_scenes_str_cmp_operators_method[] = {
#define SCENES_STRINGS_OPERATORS(OPERATOR, op, name, method) method,
#include "__operators_macros/__strings_comparision_operators_macros.h"
#undef SCENES_STRINGS_OPERATORS
};
-e_scene_str_cmp_operators_t ezlopi_scenes_strings_comparator_operators_get_enum(char *operator_str)
+e_scene_str_cmp_operators_t ezlopi_scenes_strings_comparator_operators_get_enum(char* operator_str)
{
e_scene_str_cmp_operators_t ret = SCENES_STRINGS_OPERATORS_NONE + 1;
if (operator_str)
@@ -216,9 +216,9 @@ e_scene_str_cmp_operators_t ezlopi_scenes_strings_comparator_operators_get_enum(
return ret;
}
-const char *ezlopi_scenes_strings_comparator_operators_get_op(e_scene_str_cmp_operators_t operator)
+const char* ezlopi_scenes_strings_comparator_operators_get_op(e_scene_str_cmp_operators_t operator)
{
- const char *ret = NULL;
+ const char* ret = NULL;
if ((operator>= SCENES_STRINGS_OPERATORS_NONE) && (operator SCENES_STRINGS_OPERATORS_NONE) && (operator SCENES_STRINGS_OPERATORS_NONE) && (operatoritems;
+ l_ezlopi_item_t* item = device->items;
while (item)
{
if (item->cloud_properties.item_id == item_id)
{
if (cj_item_value)
{
- item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void *)cj_item_value, NULL);
- cJSON *cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
+ item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void*)cj_item_value, NULL);
+ cJSON* cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
if (cj_value)
{
-#warning "Krishna needs to complete this"
- item_value = cj_value->valuedouble;
+ #warning "Krishna needs to complete this"
+ item_value = cj_value->valuedouble;
}
}
@@ -279,7 +279,7 @@ int ezlopi_scenes_operators_value_strings_operations(uint32_t item_id, l_fields_
device = device->next;
}
- e_scene_str_cmp_operators_t string_operator = ezlopi_scenes_strings_comparator_operators_get_enum(comparator_field->value.value_string);
+ e_scene_str_cmp_operators_t string_operator = ezlopi_scenes_strings_comparator_operators_get_enum(comparator_field->field_value.u_value.value_string);
switch (string_operator)
{
@@ -370,25 +370,25 @@ int ezlopi_scenes_operators_value_strings_operations(uint32_t item_id, l_fields_
}
/************* Values with Less ************/
-static const char *const ezlopi_scenes_value_with_less_cmp_operators_op[] = {
+static const char* const ezlopi_scenes_value_with_less_cmp_operators_op[] = {
#define SCENES_VALUES_WITH_LESS_OPERATORS(OPERATOR, op, name, method) op,
#include "__operators_macros/__value_with_less_comparision_operators_macros.h"
#undef SCENES_VALUES_WITH_LESS_OPERATORS
};
-static const char *const ezlopi_scenes_value_with_less_cmp_operators_name[] = {
+static const char* const ezlopi_scenes_value_with_less_cmp_operators_name[] = {
#define SCENES_VALUES_WITH_LESS_OPERATORS(OPERATOR, op, name, method) name,
#include "__operators_macros/__value_with_less_comparision_operators_macros.h"
#undef SCENES_VALUES_WITH_LESS_OPERATORS
};
-static const char *const ezlopi_scenes_value_with_less_cmp_operators_method[] = {
+static const char* const ezlopi_scenes_value_with_less_cmp_operators_method[] = {
#define SCENES_VALUES_WITH_LESS_OPERATORS(OPERATOR, op, name, method) method,
#include "__operators_macros/__value_with_less_comparision_operators_macros.h"
#undef SCENES_VALUES_WITH_LESS_OPERATORS
};
-e_scene_value_with_less_cmp_operators_t ezlopi_scenes_value_with_less_comparator_operators_get_enum(char *operator_str)
+e_scene_value_with_less_cmp_operators_t ezlopi_scenes_value_with_less_comparator_operators_get_enum(char* operator_str)
{
e_scene_value_with_less_cmp_operators_t ret = SCENES_VALUES_WITH_LESS_OPERATORS_NONE + 1;
if (operator_str)
@@ -407,9 +407,9 @@ e_scene_value_with_less_cmp_operators_t ezlopi_scenes_value_with_less_comparator
return ret;
}
-const char *ezlopi_scenes_value_with_less_comparator_operators_get_op(e_scene_value_with_less_cmp_operators_t operator)
+const char* ezlopi_scenes_value_with_less_comparator_operators_get_op(e_scene_value_with_less_cmp_operators_t operator)
{
- const char *ret = NULL;
+ const char* ret = NULL;
if ((operator>= SCENES_VALUES_WITH_LESS_OPERATORS_NONE) && (operator SCENES_VALUES_WITH_LESS_OPERATORS_NONE) && (operator SCENES_VALUES_WITH_LESS_OPERATORS_NONE) && (operatoritems;
+ l_ezlopi_item_t* item = device->items;
while (item)
{
if (item->cloud_properties.item_id == item_id)
{
if (cj_item_value)
{
- item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void *)cj_item_value, NULL);
- cJSON *cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
+ item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void*)cj_item_value, NULL);
+ cJSON* cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
if (cj_value)
{
-#warning "Krishna needs to complete this"
- item_value = cj_value->valuedouble;
+ #warning "Krishna needs to complete this"
+ item_value = cj_value->valuedouble;
}
}
@@ -470,7 +470,7 @@ int ezlopi_scenes_operators_value_with_less_operations(uint32_t item_id, l_field
device = device->next;
}
- e_scene_value_with_less_cmp_operators_t value_with_less_operator = ezlopi_scenes_value_with_less_comparator_operators_get_enum(comparator_field->value.value_string);
+ e_scene_value_with_less_cmp_operators_t value_with_less_operator = ezlopi_scenes_value_with_less_comparator_operators_get_enum(comparator_field->field_value.u_value.value_string);
switch (value_with_less_operator)
{
@@ -521,25 +521,25 @@ int ezlopi_scenes_operators_value_with_less_operations(uint32_t item_id, l_field
}
/************* Values without less ************/
-static const char *const ezlopi_scenes_value_without_less_cmp_operators_op[] = {
+static const char* const ezlopi_scenes_value_without_less_cmp_operators_op[] = {
#define SCENES_VALUES_WITHOUT_LESS_OPERATORS(OPERATOR, op, name, method) op,
#include "__operators_macros/__value_without_less_comparision_operators_macros.h"
#undef SCENES_VALUES_WITHOUT_LESS_OPERATORS
};
-static const char *const ezlopi_scenes_value_without_less_cmp_operators_name[] = {
+static const char* const ezlopi_scenes_value_without_less_cmp_operators_name[] = {
#define SCENES_VALUES_WITHOUT_LESS_OPERATORS(OPERATOR, op, name, method) name,
#include "__operators_macros/__value_without_less_comparision_operators_macros.h"
#undef SCENES_VALUES_WITHOUT_LESS_OPERATORS
};
-static const char *const ezlopi_scenes_value_without_less_cmp_operators_method[] = {
+static const char* const ezlopi_scenes_value_without_less_cmp_operators_method[] = {
#define SCENES_VALUES_WITHOUT_LESS_OPERATORS(OPERATOR, op, name, method) method,
#include "__operators_macros/__value_without_less_comparision_operators_macros.h"
#undef SCENES_VALUES_WITHOUT_LESS_OPERATORS
};
-e_scene_value_without_less_cmp_operators_t ezlopi_scenes_value_without_less_comparator_operators_get_enum(char *operator_str)
+e_scene_value_without_less_cmp_operators_t ezlopi_scenes_value_without_less_comparator_operators_get_enum(char* operator_str)
{
e_scene_value_without_less_cmp_operators_t ret = SCENES_VALUES_WITHOUT_LESS_OPERATORS_NONE + 1; // 1st element of enum after *_NONE
if (operator_str)
@@ -558,9 +558,9 @@ e_scene_value_without_less_cmp_operators_t ezlopi_scenes_value_without_less_comp
return ret;
}
-const char *ezlopi_scenes_value_without_less_comparator_operators_get_op(e_scene_value_without_less_cmp_operators_t operator)
+const char* ezlopi_scenes_value_without_less_comparator_operators_get_op(e_scene_value_without_less_cmp_operators_t operator)
{
- const char *ret = NULL;
+ const char* ret = NULL;
if ((operator>= SCENES_VALUES_WITHOUT_LESS_OPERATORS_NONE) && (operator SCENES_VALUES_WITHOUT_LESS_OPERATORS_NONE) && (operator SCENES_VALUES_WITHOUT_LESS_OPERATORS_NONE) && (operatoritems;
+ l_ezlopi_item_t* item = device->items;
while (item)
{
if (item->cloud_properties.item_id == item_id)
{
if (cj_item_value)
{
- item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void *)cj_item_value, NULL);
- cJSON *cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
+ item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, item, (void*)cj_item_value, NULL);
+ cJSON* cj_value = cJSON_GetObjectItem(cj_item_value, ezlopi_value_str);
if (cj_value)
{
-#warning "Krishna needs to complete this"
- item_value = cj_value->valuedouble;
+ #warning "Krishna needs to complete this"
+ item_value = cj_value->valuedouble;
}
}
@@ -623,7 +623,7 @@ int ezlopi_scenes_operators_value_without_less_operations(uint32_t item_id, l_fi
device = device->next;
}
- e_scene_value_without_less_cmp_operators_t value_without_less_operator = ezlopi_scenes_value_without_less_comparator_operators_get_enum(comparator_field->value.value_string);
+ e_scene_value_without_less_cmp_operators_t value_without_less_operator = ezlopi_scenes_value_without_less_comparator_operators_get_enum(comparator_field->field_value.u_value.value_string);
switch (value_without_less_operator)
{
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_populate.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_populate.c
index 4bcf5c7a3..807faa13a 100644
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_populate.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_populate.c
@@ -352,20 +352,21 @@ void ezlopi_scenes_populate_fields_get_value(l_fields_v2_t* field, cJSON* cj_val
{
case cJSON_Number:
{
- field->value.type = VALUE_TYPE_NUMBER;
- field->value.value_double = cj_value->valuedouble;
- TRACE_I("value: %f", field->value.value_double);
+ field->field_value.e_type = VALUE_TYPE_NUMBER;
+ field->field_value.u_value.value_double = cj_value->valuedouble;
+
+ TRACE_I("value: %f", field->field_value.u_value.value_double);
break;
}
case cJSON_String:
{
- field->value.type = VALUE_TYPE_STRING;
+ field->field_value.e_type = VALUE_TYPE_STRING;
uint32_t value_len = strlen(cj_value->valuestring) + 1;
- field->value.value_string = malloc(value_len);
- if (field->value.value_string)
+ field->field_value.u_value.value_string = malloc(value_len);
+ if (field->field_value.u_value.value_string)
{
- snprintf(field->value.value_string, value_len, "%s", cj_value->valuestring);
- TRACE_I("value: %s", field->value.value_string);
+ snprintf(field->field_value.u_value.value_string, value_len, "%s", cj_value->valuestring);
+ TRACE_I("value: %s", field->field_value.u_value.value_string);
}
else
{
@@ -375,36 +376,36 @@ void ezlopi_scenes_populate_fields_get_value(l_fields_v2_t* field, cJSON* cj_val
}
case cJSON_True:
{
- field->value.type = VALUE_TYPE_BOOL;
- field->value.value_bool = true;
+ field->field_value.e_type = VALUE_TYPE_BOOL;
+ field->field_value.u_value.value_bool = true;
TRACE_I("value: true");
break;
}
case cJSON_False:
{
- field->value.type = VALUE_TYPE_BOOL;
- field->value.value_bool = false;
+ field->field_value.e_type = VALUE_TYPE_BOOL;
+ field->field_value.u_value.value_bool = false;
TRACE_I("value: false");
break;
}
case cJSON_Object:
{
- field->value.type = VALUE_TYPE_CJSON;
- field->value.cj_value = cJSON_Duplicate(cj_value, cJSON_True);
- CJSON_TRACE("value", field->value.cj_value);
+ field->field_value.e_type = VALUE_TYPE_CJSON;
+ field->field_value.u_value.cj_value = cJSON_Duplicate(cj_value, cJSON_True);
+ CJSON_TRACE("value", field->field_value.u_value.cj_value);
break;
}
case cJSON_Array:
{
int block_idx = 0;
cJSON* cj_block = NULL;
- field->value.type = VALUE_TYPE_BLOCK;
+ field->field_value.e_type = VALUE_TYPE_BLOCK;
CJSON_TRACE("value", cj_value);
l_when_block_v2_t* curr_when_block = NULL;
while (NULL != (cj_block = cJSON_GetArrayItem(cj_value, block_idx++)))
{
- if (field->value.when_block)
+ if (field->field_value.u_value.when_block)
{
curr_when_block->next = (l_when_block_v2_t*)malloc(sizeof(l_when_block_v2_t));
if (curr_when_block->next)
@@ -416,12 +417,12 @@ void ezlopi_scenes_populate_fields_get_value(l_fields_v2_t* field, cJSON* cj_val
}
else
{
- field->value.when_block = (l_when_block_v2_t*)malloc(sizeof(l_when_block_v2_t));
- if (field->value.when_block)
+ field->field_value.u_value.when_block = (l_when_block_v2_t*)malloc(sizeof(l_when_block_v2_t));
+ if (field->field_value.u_value.when_block)
{
- memset(field->value.when_block, 0, sizeof(l_when_block_v2_t));
- ezlopi_scenes_populate_assign_when_block(field->value.when_block, cj_block);
- curr_when_block = field->value.when_block;
+ memset(field->field_value.u_value.when_block, 0, sizeof(l_when_block_v2_t));
+ ezlopi_scenes_populate_assign_when_block(field->field_value.u_value.when_block, cj_block);
+ curr_when_block = field->field_value.u_value.when_block;
}
}
}
@@ -429,7 +430,7 @@ void ezlopi_scenes_populate_fields_get_value(l_fields_v2_t* field, cJSON* cj_val
}
default:
{
- field->value.type = VALUE_TYPE_UNDEFINED;
+ field->field_value.e_type = VALUE_TYPE_UNDEFINED;
TRACE_E("cj_value type: %d", cj_value->type);
break;
}
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_print.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_print.c
index da5f18d04..2c8cd40ed 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_print.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_print.c
@@ -6,9 +6,9 @@
#include "ezlopi_cloud_constants.h"
-void ezlopi_print_when_blocks(l_when_block_v2_t *when_blocks);
+void ezlopi_print_when_blocks(l_when_block_v2_t* when_blocks);
-void ezlopi_print_block_options(s_block_options_v2_t *block_options, l_fields_v2_t *fields)
+void ezlopi_print_block_options(s_block_options_v2_t* block_options, l_fields_v2_t* fields)
{
TRACE_D("\t\t|-- blockOptions:");
TRACE_D("\t\t\t|-- method");
@@ -22,7 +22,7 @@ void ezlopi_print_block_options(s_block_options_v2_t *block_options, l_fields_v2
}
}
-void ezlopi_print_fields(l_fields_v2_t *fields)
+void ezlopi_print_fields(l_fields_v2_t* fields)
{
TRACE_D("\t\t|-- fields: ");
int field_count = 0;
@@ -31,7 +31,7 @@ void ezlopi_print_fields(l_fields_v2_t *fields)
TRACE_D("\t\t\t|---------- field_count: %d ----------", ++field_count);
TRACE_D("\t\t\t|-- name: %s", fields->name);
- const char *value_type_name = ezlopi_scene_get_scene_value_type_name(fields->value_type);
+ const char* value_type_name = ezlopi_scene_get_scene_value_type_name(fields->value_type);
TRACE_D("\t\t\t|-- type: %s", value_type_name ? value_type_name : ezlopi__str);
switch (fields->value_type)
@@ -39,42 +39,44 @@ void ezlopi_print_fields(l_fields_v2_t *fields)
case EZLOPI_VALUE_TYPE_INT:
case EZLOPI_VALUE_TYPE_HOUSE_MODE_ID:
{
- TRACE_D("\t\t\t|-- value: %f", fields->value.value_double);
+ TRACE_D("\t\t\t|-- value: %f", fields->field_value.u_value.value_double);
+ // TRACE_D("\t\t\t|-- value: %f", fields->value.value_double);
break;
}
case EZLOPI_VALUE_TYPE_BOOL:
{
- TRACE_D("\t\t\t|-- value: [%d]%s", fields->value.value_bool, fields->value.value_bool ? ezlopi_true_str : ezlopi_false_str);
+ TRACE_D("\t\t\t|-- value: [%d]%s", fields->field_value.u_value.value_bool, fields->field_value.u_value.value_bool ? ezlopi_true_str : ezlopi_false_str);
+ // TRACE_D("\t\t\t|-- value: [%d]%s", fields->value.value_bool, fields->value.value_bool ? ezlopi_true_str : ezlopi_false_str);
break;
}
case EZLOPI_VALUE_TYPE_FLOAT:
{
- TRACE_D("\t\t\t|-- value: %f", fields->value.value_double);
+ TRACE_D("\t\t\t|-- value: %f", fields->field_value.u_value.value_double);
break;
}
case EZLOPI_VALUE_TYPE_STRING:
{
- TRACE_D("\t\t\t|-- value: %s", fields->value.value_string);
+ TRACE_D("\t\t\t|-- value: %s", fields->field_value.u_value.value_string);
break;
}
case EZLOPI_VALUE_TYPE_ITEM:
{
- TRACE_D("\t\t\t|-- value: %s", fields->value.value_string);
+ TRACE_D("\t\t\t|-- value: %s", fields->field_value.u_value.value_string);
break;
}
case EZLOPI_VALUE_TYPE_INTERVAL:
{
- TRACE_D("\t\t\t|-- value: %s", fields->value.value_string);
+ TRACE_D("\t\t\t|-- value: %s", fields->field_value.u_value.value_string);
break;
}
case EZLOPI_VALUE_TYPE_BLOCKS:
{
- ezlopi_print_when_blocks((l_when_block_v2_t *)fields->value.when_block);
+ ezlopi_print_when_blocks((l_when_block_v2_t*)fields->field_value.u_value.when_block);
break;
}
case EZLOPI_VALUE_TYPE_HOUSE_MODE_ID_ARRAY:
{
- CJSON_TRACE("\t\t\t|-- value", fields->value.cj_value);
+ CJSON_TRACE("\t\t\t|-- value", fields->field_value.u_value.cj_value);
break;
}
case EZLOPI_VALUE_TYPE_DICTIONARY:
@@ -154,7 +156,7 @@ void ezlopi_print_fields(l_fields_v2_t *fields)
TRACE_D("\t\t\t|------------------------------------");
}
-void ezlopi_print_house_modes(l_house_modes_v2_t *house_modes)
+void ezlopi_print_house_modes(l_house_modes_v2_t* house_modes)
{
TRACE_D("\t|-- house_modes: ");
while (house_modes)
@@ -164,7 +166,7 @@ void ezlopi_print_house_modes(l_house_modes_v2_t *house_modes)
}
}
-void ezlopi_print_user_notifications(l_user_notification_v2_t *user_notification)
+void ezlopi_print_user_notifications(l_user_notification_v2_t* user_notification)
{
TRACE_D("\t|-- user_notifications: ");
while (user_notification)
@@ -174,7 +176,7 @@ void ezlopi_print_user_notifications(l_user_notification_v2_t *user_notification
}
}
-void ezlopi_print_when_blocks(l_when_block_v2_t *when_blocks)
+void ezlopi_print_when_blocks(l_when_block_v2_t* when_blocks)
{
TRACE_D("\t|-- when: ");
while (when_blocks)
@@ -186,7 +188,7 @@ void ezlopi_print_when_blocks(l_when_block_v2_t *when_blocks)
}
}
-void ezlopi_print_action_blocks(l_action_block_v2_t *action_block)
+void ezlopi_print_action_blocks(l_action_block_v2_t* action_block)
{
while (action_block)
{
@@ -207,7 +209,7 @@ void ezlopi_print_action_blocks(l_action_block_v2_t *action_block)
}
}
-void ezlopi_scenes_print(l_scenes_list_v2_t *scene_link_list)
+void ezlopi_scenes_print(l_scenes_list_v2_t* scene_link_list)
{
int scene_count = 0;
while (scene_link_list)
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts.c
index 0766822a0..c4b5bb03a 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts.c
@@ -10,6 +10,7 @@
#include "lua/lualib.h"
#include "lua/lauxlib.h"
+#include "corelib.h"
#include "ezlopi_core_nvs.h"
#include "ezlopi_core_cloud.h"
#include "ezlopi_core_scenes_scripts.h"
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts_custom_libs.h b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts_custom_libs.h
index 8ce489902..08fe9135c 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts_custom_libs.h
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_scripts_custom_libs.h
@@ -1 +1 @@
-SCRIPTS_CUSTOM_LIB("core", luaopen_lcore) // luaopen_lcore)
+// SCRIPTS_CUSTOM_LIB("core", luaopen_lcore) // luaopen_lcore)
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_status_changed.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_status_changed.c
index c22097782..7ce7e10d3 100644
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_status_changed.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_status_changed.c
@@ -1,18 +1,21 @@
-#include "ezlopi_service_webprov.h"
#include "ezlopi_cloud_constants.h"
+
+#include "ezlopi_core_ezlopi_broadcast.h"
#include "ezlopi_core_scenes_status_changed.h"
-int ezlopi_scenes_status_change_broadcast(l_scenes_list_v2_t *scene_node, const char *status_str)
+#include "ezlopi_service_webprov.h"
+
+int ezlopi_scenes_status_change_broadcast(l_scenes_list_v2_t* scene_node, const char* status_str)
{
int ret = 0;
if (scene_node)
{
- cJSON *cj_response = cJSON_CreateObject();
+ cJSON* cj_response = cJSON_CreateObject();
if (cj_response)
{
cJSON_AddStringToObject(cj_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
cJSON_AddStringToObject(cj_response, ezlopi_msg_subclass_str, method_hub_scene_run_progress);
- cJSON *cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
+ cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
char tmp_str[32];
@@ -20,15 +23,15 @@ int ezlopi_scenes_status_change_broadcast(l_scenes_list_v2_t *scene_node, const
cJSON_AddStringToObject(cj_result, ezlopi_scene_id_str, tmp_str);
cJSON_AddStringToObject(cj_result, ezlopi_scene_name_str, scene_node->name);
cJSON_AddStringToObject(cj_result, ezlopi_status_str, status_str ? status_str : scene_status_failed_str);
- cJSON *cj_notifications = cJSON_AddArrayToObject(cj_result, ezlopi_notifications_str);
+ cJSON* cj_notifications = cJSON_AddArrayToObject(cj_result, ezlopi_notifications_str);
if (scene_node->user_notifications && cj_notifications)
{
cJSON_AddTrueToObject(cj_result, ezlopi_userNotification_str);
- l_user_notification_v2_t *user_notification_node = scene_node->user_notifications;
+ l_user_notification_v2_t* user_notification_node = scene_node->user_notifications;
while (user_notification_node)
{
- cJSON *cj_notf = cJSON_CreateString(user_notification_node->user_id);
+ cJSON* cj_notf = cJSON_CreateString(user_notification_node->user_id);
if (!cJSON_AddItemToArray(cj_notifications, cj_notf))
{
cJSON_Delete(cj_notf);
@@ -46,27 +49,26 @@ int ezlopi_scenes_status_change_broadcast(l_scenes_list_v2_t *scene_node, const
cJSON_AddStringToObject(cj_result, ezlopi_room_name_str, ezlopi__str);
}
- char *data_to_send = cJSON_Print(cj_response);
+ char* data_to_send = cJSON_Print(cj_response);
cJSON_Delete(cj_response);
-
+
if (data_to_send)
{
cJSON_Minify(data_to_send);
- ret = web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
- free(data_to_send);
+ ret = ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data_to_send)) {
+ free(data_to_send);
+ }
}
-
- // ret = web_provisioning_send_to_nma_websocket(cj_response, TRACE_TYPE_I);
- // cJSON_Delete(cj_response);
}
}
return ret;
}
-const char *ezlopi_scenes_status_to_string(e_scene_status_v2_t scene_status)
+const char* ezlopi_scenes_status_to_string(e_scene_status_v2_t scene_status)
{
- const char *ret = "NULL";
+ const char* ret = "NULL";
switch (scene_status)
{
case EZLOPI_SCENE_STATUS_RUN:
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_then_methods.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_then_methods.c
index 3a9b3c573..04fe36f0a 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_then_methods.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_then_methods.c
@@ -1,57 +1,63 @@
#include "ezlopi_util_trace.h"
#include "ezlopi_core_devices.h"
+#include "ezlopi_core_scenes_scripts.h"
#include "ezlopi_core_scenes_then_methods.h"
+#include "ezlopi_service_meshbot.h"
#include "ezlopi_cloud_constants.h"
-int ezlopi_scene_then_set_item_value(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_set_item_value(l_scenes_list_v2_t* curr_scene, void* arg)
{
int ret = 0;
uint32_t item_id = 0;
- cJSON *cj_params = cJSON_CreateObject();
+ cJSON* cj_params = cJSON_CreateObject();
if (cj_params)
{
- l_action_block_v2_t *curr_then = (l_action_block_v2_t *)arg;
+ l_action_block_v2_t* curr_then = (l_action_block_v2_t*)arg;
if (curr_then)
{
- l_fields_v2_t *curr_field = curr_then->fields;
+ l_fields_v2_t* curr_field = curr_then->fields;
while (curr_field)
{
if (0 == strncmp(curr_field->name, "item", 4))
{
- cJSON_AddStringToObject(cj_params, ezlopi__id_str, curr_field->value.value_string);
- item_id = strtoul(curr_field->value.value_string, NULL, 16);
- TRACE_D("item_id: %s", curr_field->value.value_string);
+ cJSON_AddStringToObject(cj_params, ezlopi__id_str, curr_field->field_value.u_value.value_string);
+ item_id = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
+ TRACE_D("item_id: %s", curr_field->field_value.u_value.value_string);
+
+ // cJSON_AddStringToObject(cj_params, ezlopi__id_str, curr_field->field_value.u_value.value_string);
+ // item_id = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
+ // TRACE_D("item_id: %s", curr_field->field_value.u_value.value_string);
}
else if (0 == strncmp(curr_field->name, ezlopi_value_str, 5))
{
if (EZLOPI_VALUE_TYPE_INT == curr_field->value_type)
{
- cJSON_AddNumberToObject(cj_params, ezlopi_value_str, curr_field->value.value_double);
- TRACE_D("value: %f", curr_field->value.value_double);
+ cJSON_AddNumberToObject(cj_params, ezlopi_value_str, curr_field->field_value.u_value.value_double);
+ TRACE_D("value: %f", curr_field->field_value.u_value.value_double);
}
else if (EZLOPI_VALUE_TYPE_BOOL == curr_field->value_type)
{
- cJSON_AddBoolToObject(cj_params, ezlopi_value_str, curr_field->value.value_bool);
- TRACE_D("value: %s", curr_field->value.value_bool ? ezlopi_true_str : ezlopi_false_str);
+ cJSON_AddBoolToObject(cj_params, ezlopi_value_str, curr_field->field_value.u_value.value_bool);
+ TRACE_D("value: %s", curr_field->field_value.u_value.value_bool ? ezlopi_true_str : ezlopi_false_str);
}
else if (EZLOPI_VALUE_TYPE_STRING == curr_field->value_type)
{
- cJSON_AddStringToObject(cj_params, ezlopi_value_str, curr_field->value.value_string);
- TRACE_D("value: %s", curr_field->value.value_string);
+ cJSON_AddStringToObject(cj_params, ezlopi_value_str, curr_field->field_value.u_value.value_string);
+ TRACE_D("value: %s", curr_field->field_value.u_value.value_string);
}
}
curr_field = curr_field->next;
}
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
uint32_t found_item = 0;
while (curr_device)
{
- l_ezlopi_item_t *curr_item = curr_device->items;
+ l_ezlopi_item_t* curr_item = curr_device->items;
while (curr_item)
{
if (item_id == curr_item->cloud_properties.item_id)
@@ -76,82 +82,167 @@ int ezlopi_scene_then_set_item_value(l_scenes_list_v2_t *curr_scene, void *arg)
return ret;
}
-int ezlopi_scene_then_set_device_armed(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_set_device_armed(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_send_cloud_abstract_command(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_send_cloud_abstract_command(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_switch_house_mode(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_switch_house_mode(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_send_http_request(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_send_http_request(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_run_custom_script(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_run_custom_script(l_scenes_list_v2_t* curr_scene, void* arg)
{
- TRACE_W("Warning: then-method not implemented!");
- return 0;
+ int ret = 0;
+
+ uint32_t script_id = 0;
+ l_action_block_v2_t* curr_then = (l_action_block_v2_t*)arg;
+ if (curr_then)
+ {
+ l_fields_v2_t* curr_field = curr_then->fields;
+ while (curr_field)
+ {
+ if (0 == strncmp(curr_field->name, "script", 7))
+ {
+ script_id = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
+ TRACE_S("script_id: %s", curr_field->field_value.u_value.value_string);
+ }
+ curr_field = curr_field->next;
+ }
+ }
+
+ if (script_id)
+ {
+ ret = 1;
+ ezlopi_scenes_scripts_run_by_id(script_id);
+ }
+
+ return ret;
}
-int ezlopi_scene_then_run_plugin_script(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_run_plugin_script(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_run_scene(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_run_scene(l_scenes_list_v2_t* curr_scene, void* arg)
{
- TRACE_W("Warning: then-method not implemented!");
- return 0;
+ int ret = 0;
+ uint32_t sceneID = 0;
+ bool execute_else_condition = false;
+ l_action_block_v2_t* curr_then = (l_action_block_v2_t*)arg;
+ if (curr_then)
+ {
+ l_fields_v2_t* curr_field = curr_then->fields;
+ while (curr_field)
+ {
+ if (0 == strncmp(curr_field->name, "sceneId", 7))
+ {
+ if (curr_field->field_value.e_type == VALUE_TYPE_STRING)
+ {
+ sceneID = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
+ }
+ else
+ {
+ ret = 1;
+ }
+ }
+ else if (0 == strncmp(curr_field->name, "block", 5))
+ {
+ if (curr_field->field_value.e_type == VALUE_TYPE_STRING)
+ {
+ if (0 == strncmp(curr_field->field_value.u_value.value_string, "else", 4))
+ {
+ execute_else_condition = true;
+ }
+ else if (0 == strncmp(curr_field->field_value.u_value.value_string, "thenGroups", 10))
+ {
+ TRACE_D("Running scene group, yet to be implemented.");
+ }
+ else
+ {
+ ret = 1;
+ }
+ }
+ else
+ {
+ ret = 1;
+ }
+ }
+ else if ((0 == strncmp(curr_field->name, "group", 5)) && (curr_field->value_type == EZLOPI_VALUE_TYPE_STRING))
+ {
+ TRACE_D("Running scene group, yet to be implemented.");
+ }
+ curr_field = curr_field->next;
+ }
+ if (execute_else_condition)
+ {
+ TRACE_D("Executing else condition");
+ ezlopi_meshbot_execute_scene_else_action_group(sceneID);
+ }
+ else
+ {
+ TRACE_D("Executing scene, id: %d", sceneID);
+ ezlopi_scenes_service_run_by_id(sceneID);
+ }
+ }
+ else
+ {
+ ret = 1;
+ }
+ return ret;
}
-int ezlopi_scene_then_set_scene_state(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_set_scene_state(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_reset_latch(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_reset_latch(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_reset_scene_latches(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_reset_scene_latches(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_reboot_hub(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_reboot_hub(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_reset_hub(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_reset_hub(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_cloud_api(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_cloud_api(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_set_expression(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_set_expression(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_set_variable(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_set_variable(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
}
-int ezlopi_scene_then_toggle_value(l_scenes_list_v2_t *curr_scene, void *arg)
+int ezlopi_scene_then_toggle_value(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W("Warning: then-method not implemented!");
return 0;
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.c
index 77a6caac2..95fcd8b14 100644
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.c
@@ -745,32 +745,33 @@ static void _______fields_get_value(l_fields_v2_t* field, cJSON* cj_value)
{
if (field && cj_value)
{
+ CJSON_TRACE("cj_value", cj_value);
TRACE_I("type: %s", ezlopi_scene_get_scene_value_type_name(field->value_type));
switch (cj_value->type)
{
case cJSON_Number:
{
- field->value.type = VALUE_TYPE_NUMBER;
- field->value.value_double = cj_value->valuedouble;
- TRACE_I("value: %f", field->value.value_double);
+ field->field_value.e_type = VALUE_TYPE_NUMBER;
+ field->field_value.u_value.value_double = cj_value->valuedouble;
+ TRACE_I("value: %f", field->field_value.u_value.value_double);
break;
}
case cJSON_String:
{
if (EZLOPI_VALUE_TYPE_HOUSE_MODE_ID == field->value_type)
{
- field->value.type = VALUE_TYPE_NUMBER;
- field->value.value_double = strtoul(cj_value->valuestring, NULL, 16);
+ field->field_value.e_type = VALUE_TYPE_NUMBER;
+ field->field_value.u_value.value_double = strtoul(cj_value->valuestring, NULL, 16);
}
else
{
- field->value.type = VALUE_TYPE_STRING;
+ field->field_value.e_type = VALUE_TYPE_STRING;
uint32_t value_len = strlen(cj_value->valuestring) + 1;
- field->value.value_string = malloc(value_len);
- if (field->value.value_string)
+ field->field_value.u_value.value_string = malloc(value_len);
+ if (field->field_value.u_value.value_string)
{
- snprintf(field->value.value_string, value_len, "%s", cj_value->valuestring);
- TRACE_I("value: %s", field->value.value_string);
+ snprintf(field->field_value.u_value.value_string, value_len, "%s", cj_value->valuestring);
+ TRACE_I("value: %s", field->field_value.u_value.value_string);
}
else
{
@@ -781,23 +782,23 @@ static void _______fields_get_value(l_fields_v2_t* field, cJSON* cj_value)
}
case cJSON_True:
{
- field->value.type = VALUE_TYPE_BOOL;
- field->value.value_bool = true;
+ field->field_value.e_type = VALUE_TYPE_BOOL;
+ field->field_value.u_value.value_bool = true;
TRACE_I("value: true");
break;
}
case cJSON_False:
{
- field->value.type = VALUE_TYPE_BOOL;
- field->value.value_bool = false;
+ field->field_value.e_type = VALUE_TYPE_BOOL;
+ field->field_value.u_value.value_bool = false;
TRACE_I("value: false");
break;
}
case cJSON_Object:
{
- field->value.type = VALUE_TYPE_CJSON;
- field->value.cj_value = cJSON_Duplicate(cj_value, cJSON_True);
- CJSON_TRACE("value", field->value.cj_value);
+ field->field_value.e_type = VALUE_TYPE_CJSON;
+ field->field_value.u_value.cj_value = cJSON_Duplicate(cj_value, cJSON_True);
+ CJSON_TRACE("value", field->field_value.u_value.cj_value);
break;
}
case cJSON_Array:
@@ -810,20 +811,20 @@ static void _______fields_get_value(l_fields_v2_t* field, cJSON* cj_value)
{
case EZLOPI_VALUE_TYPE_HOUSE_MODE_ID_ARRAY:
{
- field->value.type = VALUE_TYPE_CJSON;
- field->value.cj_value = cJSON_Duplicate(cj_value, cJSON_True);
+ field->field_value.e_type = VALUE_TYPE_CJSON;
+ field->field_value.u_value.cj_value = cJSON_Duplicate(cj_value, cJSON_True);
break;
}
case EZLOPI_VALUE_TYPE_BLOCKS:
{
- field->value.type = VALUE_TYPE_BLOCK;
+ field->field_value.e_type = VALUE_TYPE_BLOCK;
while (NULL != (cj_block = cJSON_GetArrayItem(cj_value, block_idx++)))
{
CJSON_TRACE("cj_block", cj_block);
- if (field->value.when_block)
+ if (field->field_value.u_value.when_block)
{
- l_when_block_v2_t* curr_when_block = field->value.when_block;
+ l_when_block_v2_t* curr_when_block = field->field_value.u_value.when_block;
while (curr_when_block->next)
{
curr_when_block = curr_when_block->next;
@@ -832,7 +833,7 @@ static void _______fields_get_value(l_fields_v2_t* field, cJSON* cj_value)
}
else
{
- field->value.when_block = ____new_when_block_populate(cj_block);
+ field->field_value.u_value.when_block = ____new_when_block_populate(cj_block);
}
}
break;
@@ -846,7 +847,7 @@ static void _______fields_get_value(l_fields_v2_t* field, cJSON* cj_value)
}
default:
{
- field->value.type = VALUE_TYPE_UNDEFINED;
+ field->field_value.e_type = VALUE_TYPE_UNDEFINED;
TRACE_E("cj_value type: %d", cj_value->type);
break;
}
@@ -863,8 +864,10 @@ static l_fields_v2_t* ______new_field_populate(cJSON* cj_field)
if (field)
{
memset(field, 0, sizeof(l_fields_v2_t));
- CJSON_GET_VALUE_STRING_BY_COPY(cj_field, ezlopi_name_str, field->name);
+ // field->field_value.u_value.when_block
+
+ CJSON_GET_VALUE_STRING_BY_COPY(cj_field, ezlopi_name_str, field->name);
field->value_type = ezlopi_core_scenes_value_get_type(cj_field, ezlopi_type_str);
_______fields_get_value(field, cJSON_GetObjectItem(cj_field, ezlopi_value_str));
}
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.h b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.h
index 8081aecc4..a4fa6de69 100644
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.h
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.h
@@ -1,10 +1,12 @@
#ifndef _EZLOPI_CORE_SCENES_V2_H_
#define _EZLOPI_CORE_SCENES_V2_H_
-#include "ctype.h"
-#include "cJSON.h"
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
+#include
+#include
+#include
+#include
+#include
+#include
#include "ezlopi_core_scenes_methods.h"
@@ -67,24 +69,28 @@ typedef enum e_value_type
typedef union u_field_value_v2
{
- e_value_type_t type;
- char *value_string;
+ char* value_string;
double value_double;
bool value_bool;
- cJSON *cj_value;
- struct l_when_block_v2 *when_block;
- struct l_house_modes_v2_t *house_modes;
+ cJSON* cj_value;
+ struct l_when_block_v2* when_block;
+ struct l_house_modes_v2_t* house_modes;
} u_field_value_v2_t;
+typedef struct s_field_value {
+ e_value_type_t e_type;
+ u_field_value_v2_t u_value;
+} s_field_value_t;
+
typedef struct l_fields_v2
{
char name[32];
-
e_scene_value_type_v2_t value_type; // 0: double, 1: string
- u_field_value_v2_t value;
- char *scale;
- void *user_arg; // user by when-methods
- struct l_fields_v2 *next;
+ s_field_value_t field_value;
+ char* scale;
+ void* user_arg; // user by when-methods
+ struct l_fields_v2* next;
+
} l_fields_v2_t;
typedef struct l_action_block_v2
@@ -93,16 +99,16 @@ typedef struct l_action_block_v2
e_scenes_block_type_v2_t block_type;
s_block_options_v2_t block_options;
s_action_delay_v2_t delay;
- l_fields_v2_t *fields;
- struct l_action_block_v2 *next;
+ l_fields_v2_t* fields;
+ struct l_action_block_v2* next;
} l_action_block_v2_t;
typedef struct l_when_block_v2
{
e_scenes_block_type_v2_t block_type;
s_block_options_v2_t block_options;
- l_fields_v2_t *fields;
- struct l_when_block_v2 *next;
+ l_fields_v2_t* fields;
+ struct l_when_block_v2* next;
} l_when_block_v2_t;
// typedef struct l_else_block_v2
@@ -118,13 +124,13 @@ typedef struct l_when_block_v2
typedef struct l_user_notification_v2
{
char user_id[32];
- struct l_user_notification_v2 *next;
+ struct l_user_notification_v2* next;
} l_user_notification_v2_t;
typedef struct l_house_modes_v2
{
char house_mode[8];
- struct l_house_modes_v2 *next;
+ struct l_house_modes_v2* next;
} l_house_modes_v2_t;
typedef struct l_scenes_list_v2
@@ -141,45 +147,45 @@ typedef struct l_scenes_list_v2
char name[32];
char parent_id[32];
- l_user_notification_v2_t *user_notifications;
- l_house_modes_v2_t *house_modes;
- l_action_block_v2_t *then_block;
- l_when_block_v2_t *when_block;
- l_action_block_v2_t *else_block;
+ l_user_notification_v2_t* user_notifications;
+ l_house_modes_v2_t* house_modes;
+ l_action_block_v2_t* then_block;
+ l_when_block_v2_t* when_block;
+ l_action_block_v2_t* else_block;
- struct l_scenes_list_v2 *next;
+ struct l_scenes_list_v2* next;
} l_scenes_list_v2_t;
-typedef int (*f_scene_method_v2_t)(l_scenes_list_v2_t *curr_scene, void *arg);
+typedef int (*f_scene_method_v2_t)(l_scenes_list_v2_t* curr_scene, void* arg);
void ezlopi_scenes_init_v2(void);
-uint32_t ezlopi_store_new_scene_v2(cJSON *cj_new_scene);
-uint32_t ezlopi_scenes_get_list_v2(cJSON *cj_scenes_array);
-int ezlopi_scene_edit_by_id(uint32_t scene_id, cJSON *cj_scene);
+uint32_t ezlopi_store_new_scene_v2(cJSON* cj_new_scene);
+uint32_t ezlopi_scenes_get_list_v2(cJSON* cj_scenes_array);
+int ezlopi_scene_edit_by_id(uint32_t scene_id, cJSON* cj_scene);
-l_scenes_list_v2_t *ezlopi_scenes_get_scenes_head_v2(void);
+l_scenes_list_v2_t* ezlopi_scenes_get_scenes_head_v2(void);
f_scene_method_v2_t ezlopi_scene_get_method_v2(e_scene_method_type_t scene_method_type);
-l_scenes_list_v2_t *ezlopi_scenes_get_by_id_v2(uint32_t _id);
-l_scenes_list_v2_t *ezlopi_scenes_new_scene_populate(cJSON *cj_new_scene, uint32_t scene_id);
+l_scenes_list_v2_t* ezlopi_scenes_get_by_id_v2(uint32_t _id);
+l_scenes_list_v2_t* ezlopi_scenes_new_scene_populate(cJSON* cj_new_scene, uint32_t scene_id);
// e_scene_value_type_v2_t ezlopi_scenes_get_value_type(cJSON *cj_field);
// e_scene_value_type_v2_t ezlopi_scenes_get_expressions_value_type(cJSON *cj_value_type);
-void ezlopi_scene_add_users_in_notifications(l_scenes_list_v2_t *scene_node, cJSON *cj_user);
+void ezlopi_scene_add_users_in_notifications(l_scenes_list_v2_t* scene_node, cJSON* cj_user);
-void ezlopi_scenes_delete(l_scenes_list_v2_t *scenes_list);
-void ezlopi_scenes_delete_field_value(l_fields_v2_t *field);
-void ezlopi_scenes_delete_when_blocks(l_when_block_v2_t *when_blocks);
-void ezlopi_scenes_delete_house_modes(l_house_modes_v2_t *house_modes);
-void ezlopi_scenes_delete_action_blocks(l_action_block_v2_t *action_blocks);
-void ezlopi_scenes_delete_user_notifications(l_user_notification_v2_t *user_notifications);
+void ezlopi_scenes_delete(l_scenes_list_v2_t* scenes_list);
+void ezlopi_scenes_delete_field_value(l_fields_v2_t* field);
+void ezlopi_scenes_delete_when_blocks(l_when_block_v2_t* when_blocks);
+void ezlopi_scenes_delete_house_modes(l_house_modes_v2_t* house_modes);
+void ezlopi_scenes_delete_action_blocks(l_action_block_v2_t* action_blocks);
+void ezlopi_scenes_delete_user_notifications(l_user_notification_v2_t* user_notifications);
void ezlopi_scenes_depopulate_by_id_v2(uint32_t _id);
void ezlopi_scenes_remove_id_from_list_v2(uint32_t _id);
-l_scenes_list_v2_t *ezlopi_scenes_pop_by_id_v2(uint32_t _id);
+l_scenes_list_v2_t* ezlopi_scenes_pop_by_id_v2(uint32_t _id);
-void ezlopi_scenes_print(l_scenes_list_v2_t *scene_link_list);
-void ezlopi_scenes_notifications_add(cJSON *cj_notifications);
+void ezlopi_scenes_print(l_scenes_list_v2_t* scene_link_list);
+void ezlopi_scenes_notifications_add(cJSON* cj_notifications);
#endif // _EZLOPI_CORE_SCENES_V2_H_
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_value_types.h b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_value_types.h
index fc121dc1a..a26bfbb20 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_value_types.h
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_value_types.h
@@ -69,5 +69,6 @@ EZLOPI_VALUE_TYPE(HMS_INTERVAL, "hms_interval")
EZLOPI_VALUE_TYPE(BLOCKS, "blocks")
EZLOPI_VALUE_TYPE(HOUSE_MODE_ID_ARRAY, "houseModeId_array")
EZLOPI_VALUE_TYPE(HOUSE_MODE_ID, "houseModeId")
+EZLOPI_VALUE_TYPE(SCENEID, "sceneID")
//
EZLOPI_VALUE_TYPE(MAX, NULL)
\ No newline at end of file
diff --git a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_when_methods.c b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_when_methods.c
index dd4c11418..0df8671a6 100755
--- a/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_when_methods.c
+++ b/ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_when_methods.c
@@ -22,7 +22,7 @@ int ezlopi_scene_when_is_item_state(l_scenes_list_v2_t* scene_node, void* arg)
{
if (0 == strncmp(curr_field->name, "item", 4))
{
- item_id = strtoul(curr_field->value.value_string, NULL, 16);
+ item_id = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
}
else if (0 == strncmp(curr_field->name, ezlopi_value_str, 4))
{
@@ -52,7 +52,7 @@ int ezlopi_scene_when_is_item_state(l_scenes_list_v2_t* scene_node, void* arg)
{
case cJSON_True:
{
- if (true == value_field->value.value_bool)
+ if (true == value_field->field_value.u_value.value_bool)
{
ret = 1;
}
@@ -60,7 +60,7 @@ int ezlopi_scene_when_is_item_state(l_scenes_list_v2_t* scene_node, void* arg)
}
case cJSON_False:
{
- if (false == value_field->value.value_bool)
+ if (false == value_field->field_value.u_value.value_bool)
{
ret = 1;
}
@@ -68,7 +68,7 @@ int ezlopi_scene_when_is_item_state(l_scenes_list_v2_t* scene_node, void* arg)
}
case cJSON_Number:
{
- if (cj_value->valuedouble == value_field->value.value_double)
+ if (cj_value->valuedouble == value_field->field_value.u_value.value_double)
{
ret = 1;
}
@@ -76,8 +76,8 @@ int ezlopi_scene_when_is_item_state(l_scenes_list_v2_t* scene_node, void* arg)
}
case cJSON_String:
{
- uint32_t cmp_size = (strlen(cj_value->valuestring) > strlen(value_field->value.value_string)) ? strlen(cj_value->valuestring) : strlen(value_field->value.value_string);
- if (0 == strncmp(cj_value->valuestring, value_field->value.value_string, cmp_size))
+ uint32_t cmp_size = (strlen(cj_value->valuestring) > strlen(value_field->field_value.u_value.value_string)) ? strlen(cj_value->valuestring) : strlen(value_field->field_value.u_value.value_string);
+ if (0 == strncmp(cj_value->valuestring, value_field->field_value.u_value.value_string, cmp_size))
{
ret = 1;
}
@@ -112,7 +112,7 @@ int ezlopi_scene_when_is_interval(l_scenes_list_v2_t* scene_node, void* arg)
if (scene_node)
{
char* end_prt = NULL;
- uint32_t interval = strtoul(scene_node->when_block->fields->value.value_string, &end_prt, 10);
+ uint32_t interval = strtoul(scene_node->when_block->fields->field_value.u_value.value_string, &end_prt, 10);
if (end_prt)
{
if (0 == strncmp(end_prt, "m", 1))
@@ -215,7 +215,7 @@ int ezlopi_scene_when_is_house_mode_changed_to(l_scenes_list_v2_t* scene_node, v
uint32_t idx = 0;
cJSON* cj_house_mdoe_id = NULL;
- while (NULL == (cj_house_mdoe_id = cJSON_GetArrayItem(house_mode_id_array->value.cj_value, idx++)))
+ while (NULL == (cj_house_mdoe_id = cJSON_GetArrayItem(house_mode_id_array->field_value.u_value.cj_value, idx++)))
{
if (cj_house_mdoe_id->valuestring)
{
@@ -298,7 +298,7 @@ int ezlopi_scene_when_compare_numbers(l_scenes_list_v2_t* scene_node, void* arg)
{
if (0 == strncmp(curr_field->name, "item", 4))
{
- item_id = strtoul(curr_field->value.value_string, NULL, 16);
+ item_id = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
}
else if (0 == strncmp(curr_field->name, ezlopi_value_str, 4))
{
@@ -380,7 +380,7 @@ int ezlopi_scene_when_and(l_scenes_list_v2_t* scene_node, void* arg)
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block)
{
- l_when_block_v2_t* value_when_block = when_block->fields->value.when_block;
+ l_when_block_v2_t* value_when_block = when_block->fields->field_value.u_value.when_block;
while (value_when_block)
{
f_scene_method_v2_t scene_method = ezlopi_scene_get_method_v2(value_when_block->block_options.method.type);
@@ -407,7 +407,7 @@ int ezlopi_scene_when_not(l_scenes_list_v2_t* scene_node, void* arg)
if (when_block)
{
ret = 1; // required for the first case
- l_when_block_v2_t* value_when_block = when_block->fields->value.when_block;
+ l_when_block_v2_t* value_when_block = when_block->fields->field_value.u_value.when_block;
while (value_when_block)
{
f_scene_method_v2_t scene_method = ezlopi_scene_get_method_v2(value_when_block->block_options.method.type);
@@ -429,7 +429,7 @@ int ezlopi_scene_when_or(l_scenes_list_v2_t* scene_node, void* arg)
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block)
{
- l_when_block_v2_t* value_when_block = when_block->fields->value.when_block;
+ l_when_block_v2_t* value_when_block = when_block->fields->field_value.u_value.when_block;
while (value_when_block)
{
f_scene_method_v2_t scene_method = ezlopi_scene_get_method_v2(value_when_block->block_options.method.type);
@@ -455,7 +455,7 @@ int ezlopi_scene_when_xor(l_scenes_list_v2_t* scene_node, void* arg)
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block)
{
- l_when_block_v2_t* value_when_block = when_block->fields->value.when_block;
+ l_when_block_v2_t* value_when_block = when_block->fields->field_value.u_value.when_block;
while (value_when_block)
{
f_scene_method_v2_t scene_method = ezlopi_scene_get_method_v2(value_when_block->block_options.method.type);
diff --git a/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c b/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c
index 78ea87e56..6cd5076e7 100644
--- a/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c
+++ b/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c
@@ -36,9 +36,9 @@
static esp_netif_t* wifi_sta_netif = NULL;
static esp_netif_ip_info_t my_ip;
-static uint32_t new_wifi = 0;
+// static uint32_t new_wifi = 0;
static int s_retry_num = 0;
-static char wifi_ssid_pass_global_buffer[64];
+// static char wifi_ssid_pass_global_buffer[EZLOPI_FINFO_LEN_WIFI_SSID + EZLOPI_FINFO_LEN_WIFI_PASS];
static int station_got_ip = 0;
static const char* const wifi_no_error_str = "NO_ERROR";
static const char* last_disconnect_reason = wifi_no_error_str;
@@ -81,21 +81,15 @@ esp_netif_ip_info_t* ezlopi_wifi_get_ip_infos(void)
return &my_ip;
}
-// static void alert_qt_wifi_fail(void)
-// {
-// char *qt_resp = "{\"cmd\":2,\"status_write\":0,\"status_connect\":0}";
-// qt_serial_tx_data(strlen(qt_resp), (uint8_t *)qt_resp);
-// }
-
int ezlopi_wifi_got_ip(void)
{
return station_got_ip;
}
-void ezlopi_wifi_set_new_wifi_flag(void)
-{
- new_wifi = 1;
-}
+// void ezlopi_wifi_set_new_wifi_flag(void)
+// {
+// new_wifi = 1;
+// }
ezlopi_wifi_status_t* ezlopi_wifi_status(void)
{
@@ -197,6 +191,8 @@ static void __event_handler(void* arg, esp_event_base_t event_base, int32_t even
}
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
{
+ ezlopi_event_group_clear_event(EZLOPI_EVENT_WIFI_CONNECTED);
+
// event_data; //
wifi_event_sta_disconnected_t* disconnected = (wifi_event_sta_disconnected_t*)event_data;
TRACE_E("Disconnect reason[%d]: %s", disconnected->reason, ezlopi_wifi_err_reason_str(disconnected->reason));
@@ -270,8 +266,10 @@ static void __event_handler(void* arg, esp_event_base_t event_base, int32_t even
memcpy(&my_ip, &event->ip_info, sizeof(esp_netif_ip_info_t));
ezlopi_event_group_set_event(EZLOPI_EVENT_WIFI_CONNECTED);
ezlopi_flag_wifi_status = true;
-
- // alert_qt_wifi_got_ip();
+ }
+ else
+ {
+ TRACE_E("unknown event:: event_base: %u, event_id: %d", (uint32_t)event_base, event_id);
}
ll_ezlopi_wifi_event_upcall_t* curr_upcall = __event_upcall_head;
@@ -279,7 +277,7 @@ static void __event_handler(void* arg, esp_event_base_t event_base, int32_t even
{
if (curr_upcall->upcall)
{
- curr_upcall->upcall(event_base, curr_upcall->arg);
+ curr_upcall->upcall(event_base, event_id, curr_upcall->arg);
}
curr_upcall = curr_upcall->next;
}
@@ -308,42 +306,13 @@ void ezlopi_wifi_connect_from_id_bin(void)
{
char* wifi_ssid = ezlopi_factory_info_v3_get_ssid();
char* wifi_password = ezlopi_factory_info_v3_get_password();
- ezlopi_wifi_set_new_wifi_flag();
if ((NULL != wifi_ssid) && ('\0' != wifi_ssid[0]) &&
(NULL != wifi_password) && ('\0' != wifi_password[0]))
{
- memset(wifi_ssid_pass_global_buffer, 0, sizeof(wifi_ssid_pass_global_buffer));
- snprintf(&wifi_ssid_pass_global_buffer[00], 31, "%s", wifi_ssid);
- snprintf(&wifi_ssid_pass_global_buffer[32], 31, "%s", wifi_password);
+ esp_err_t wifi_error = ezlopi_wifi_connect(wifi_ssid, wifi_password);
+ TRACE_W("wifi_error: %u", wifi_error);
}
- else
- {
- strcpy(&wifi_ssid_pass_global_buffer[00], "ezlopitest");
- strcpy(&wifi_ssid_pass_global_buffer[32], "ezlopitest");
- }
-
- ezlopi_factory_info_v3_free(wifi_ssid);
- ezlopi_factory_info_v3_free(wifi_password);
-
- esp_err_t wifi_error = ezlopi_wifi_connect(&wifi_ssid_pass_global_buffer[0], &wifi_ssid_pass_global_buffer[32]);
- TRACE_W("wifi_error: %u", wifi_error);
-}
-
-void ezlopi_wifi_connect_from_nvs(void)
-{
- memset(wifi_ssid_pass_global_buffer, 0, sizeof(wifi_ssid_pass_global_buffer));
- ezlopi_nvs_read_wifi(wifi_ssid_pass_global_buffer, sizeof(wifi_ssid_pass_global_buffer));
-
- if (wifi_ssid_pass_global_buffer[0] == 0)
- {
- strcpy(&wifi_ssid_pass_global_buffer[00], "ezlopitest");
- strcpy(&wifi_ssid_pass_global_buffer[32], "ezlopitest");
- ezlopi_wifi_set_new_wifi_flag();
- }
-
- esp_err_t wifi_error = ezlopi_wifi_connect(&wifi_ssid_pass_global_buffer[0], &wifi_ssid_pass_global_buffer[32]);
- TRACE_W("wifi_error: %u", wifi_error);
}
esp_err_t ezlopi_wifi_connect(const char* ssid, const char* pass)
@@ -352,13 +321,6 @@ esp_err_t ezlopi_wifi_connect(const char* ssid, const char* pass)
if ((NULL != ssid) && (NULL != pass))
{
- if ((0 != strncmp(ssid, &wifi_ssid_pass_global_buffer[0], 32)) || ((0 != strncmp(pass, &wifi_ssid_pass_global_buffer[32], 32))))
- {
- ezlopi_wifi_set_new_wifi_flag();
- strncpy((char*)&wifi_ssid_pass_global_buffer[0], ssid, 32);
- strncpy((char*)&wifi_ssid_pass_global_buffer[32], pass, 32);
- }
-
TRACE_D("SSID: %s, Password: %s,\r\n", ssid, pass);
wifi_config_t wifi_config = {
@@ -400,12 +362,12 @@ esp_err_t ezlopi_wifi_connect(const char* ssid, const char* pass)
int ezlopi_wait_for_wifi_to_connect(uint32_t wait_time_ms)
{
uint32_t ret = 0;
- while (-1 == ezlopi_event_group_wait_for_event(EZLOPI_EVENT_WIFI_CONNECTED, wait_time_ms, 0))
+ while (-1 == ezlopi_event_group_wait_for_event(EZLOPI_EVENT_WIFI_CONNECTED, wait_time_ms, false))
{
vTaskDelay(100 / portTICK_PERIOD_MS);
}
- ret = ezlopi_event_group_wait_for_event(EZLOPI_EVENT_WIFI_CONNECTED, wait_time_ms, 0);
+ ret = ezlopi_event_group_wait_for_event(EZLOPI_EVENT_WIFI_CONNECTED, wait_time_ms, false);
return ret;
}
@@ -415,8 +377,7 @@ static ll_ezlopi_wifi_event_upcall_t* ezlopi_wifi_event_upcall_create(f_ezlopi_w
if (_upcall)
{
_upcall->arg = arg;
- #warning "Krishna needs to test and fix it"
- _upcall->upcall = upcall;
+ _upcall->upcall = upcall;
_upcall->next = NULL;
}
diff --git a/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.h b/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.h
index f26532e2e..c17ce4ede 100644
--- a/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.h
+++ b/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.h
@@ -10,7 +10,7 @@ extern "C"
{
#endif
- typedef void (*f_ezlopi_wifi_event_upcall)(esp_event_base_t event, void* arg);
+ typedef void (*f_ezlopi_wifi_event_upcall)(esp_event_base_t event, int32_t event_id, void *arg);
typedef struct ll_ezlopi_wifi_event_upcall
{
@@ -30,7 +30,6 @@ extern "C"
void ezlopi_wifi_set_new_wifi_flag(void);
void ezlopi_wifi_initialize(void);
esp_err_t ezlopi_wifi_connect(const char* ssid, const char* pass);
- void ezlopi_wifi_connect_from_nvs(void);
void ezlopi_wifi_connect_from_id_bin(void);
int ezlopi_wait_for_wifi_to_connect(uint32_t wait_time_ms);
esp_netif_ip_info_t* ezlopi_wifi_get_ip_infos(void);
diff --git a/ezlopi-doc/ezlopi_cover.png b/ezlopi-doc/ezlopi_cover.png
new file mode 100644
index 000000000..7de531f76
Binary files /dev/null and b/ezlopi-doc/ezlopi_cover.png differ
diff --git a/ezlopi-doc/ezlopi_logo.png b/ezlopi-doc/ezlopi_logo.png
new file mode 100644
index 000000000..14390104c
Binary files /dev/null and b/ezlopi-doc/ezlopi_logo.png differ
diff --git a/ezlop-doc/ezlopi_screenshot.png b/ezlopi-doc/ezlopi_screenshot.png
similarity index 100%
rename from ezlop-doc/ezlopi_screenshot.png
rename to ezlopi-doc/ezlopi_screenshot.png
diff --git a/ezlop-doc/ezlopi_web_flasher.png b/ezlopi-doc/ezlopi_web_flasher.png
similarity index 100%
rename from ezlop-doc/ezlopi_web_flasher.png
rename to ezlopi-doc/ezlopi_web_flasher.png
diff --git a/ezlopi-lua-modules/core/CMakeLists.txt b/ezlopi-lua-modules/core/CMakeLists.txt
index dfa50a13b..f40e01745 100644
--- a/ezlopi-lua-modules/core/CMakeLists.txt
+++ b/ezlopi-lua-modules/core/CMakeLists.txt
@@ -1,4 +1,4 @@
file(GLOB_RECURSE src_files "*.c*")
idf_component_register(SRCS "core_external_gateway_api.c" "core_others_api.c" "core_updaters_api.c" "core_removers_api.c" "core_adders_api.c" "core_getters_api.c" "corelib.c" "${src_files}"
INCLUDE_DIRS "."
- REQUIRES lua ezlopi-util-trace ezlopi-core-factory-info ezlopi-core-devices ezlopi-core-gateway ezlopi-util-version helper_functions )
\ No newline at end of file
+ REQUIRES lua ezlopi-util-trace ezlopi-core-factory-info ezlopi-core-devices ezlopi-core-gateway ezlopi-util-version helper_functions)
\ No newline at end of file
diff --git a/ezlopi-lua-modules/core/core_getters_api.c b/ezlopi-lua-modules/core/core_getters_api.c
index 07fa8ab42..59da10fc5 100644
--- a/ezlopi-lua-modules/core/core_getters_api.c
+++ b/ezlopi-lua-modules/core/core_getters_api.c
@@ -257,10 +257,8 @@ static int __create_lua_table_for_device(lua_State *lua_state, l_ezlopi_device_t
lua_create_table_string_key_value(ezlopi_security_str, controller_info->security);
lua_create_table_bool_key_value(ezlopi_ready_str, controller_info->ready);
lua_create_table_string_key_value(ezlopi_status_str, controller_info->status ? controller_info->status : ezlopi__str);
-
-#warning "Krishna needs to verify below 2 lines"
- lua_create_table_bool_key_value(ezlopi_house_modes_options_str, ezlopi__str);
- lua_create_table_bool_key_value(ezlopi_parent_room_str, ezlopi__str);
+ lua_create_table_string_key_value(ezlopi_house_modes_options_str, ezlopi__str);
+ lua_create_table_string_key_value(ezlopi_parent_room_str, ezlopi__str);
return 1;
}
@@ -347,11 +345,9 @@ static int __create_lua_table_for_gateway(lua_State *lua_state, s_ezlopi_gateway
lua_create_table_string_key_value(ezlopi_name_str, gateway_prop->name);
-#warning "Krishna needs to check below 3 lines"
- lua_create_table_bool_key_value(ezlopi_plugin_id_str, gateway_prop->pluginid);
- lua_create_table_bool_key_value(ezlopi_label_str, gateway_prop->label);
- lua_create_table_bool_key_value(ezlopi_reason_str, ezlopi__str);
-
+ lua_create_table_string_key_value(ezlopi_plugin_id_str, gateway_prop->pluginid);
+ lua_create_table_string_key_value(ezlopi_label_str, gateway_prop->label);
+ lua_create_table_string_key_value(ezlopi_reason_str, ezlopi__str);
lua_create_table_string_key_value(ezlopi_unreachable_reasons_str, ezlopi__str);
lua_create_table_string_key_value(ezlopi_unreachable_actions_str, ezlopi__str);
lua_create_table_bool_key_value(ezlopi_manual_device_adding_str, gateway_prop->manual_device_adding);
diff --git a/ezlopi-lua-modules/helper_functions/lua_helper_functions.h b/ezlopi-lua-modules/helper_functions/lua_helper_functions.h
index d143654dc..47302db3c 100644
--- a/ezlopi-lua-modules/helper_functions/lua_helper_functions.h
+++ b/ezlopi-lua-modules/helper_functions/lua_helper_functions.h
@@ -7,7 +7,7 @@
lua_pushstring(lua_state, value ? value : ezlopi__str); \
lua_settable(lua_state, -3); \
}
-#warning "Compile and check the warning details, Krishna needs to resolve it."
+// #warning "Compile and check the warning details, Krishna needs to resolve it."
#define lua_create_table_bool_key_value(key, value) \
{ \
lua_pushstring(lua_state, key); \
diff --git a/ezlopi-main/CMakeLists.txt b/ezlopi-main/CMakeLists.txt
index 32db2dfc2..b83b39141 100644
--- a/ezlopi-main/CMakeLists.txt
+++ b/ezlopi-main/CMakeLists.txt
@@ -1,12 +1,60 @@
# Include all source files
-file(GLOB_RECURSE SOURCES "*.c")
+file(GLOB_RECURSE config_src "*.c")
-idf_component_register(SRCS ${SOURCES}
- INCLUDE_DIRS "."
- REQUIRES
- ezlopi-user-config
- ezlopi-util-trace
- ezlopi-core-ezlopi
- )
+# Define SDK components
+set(EZLOPI_SDK_COMPONENTS
+ # driver
+ # nghttp
+ # esp_http_server
+ # protocol_examples_common
+)
+# Define ezlopi-components
+set(EZLOPI_COMPONENTS
+ ezlopi-util-trace
+)
+# Define core components
+set(EZLOPI_CORE_COMPONENTS
+ ezlopi-core-ezlopi
+)
+
+# Define HAL components
+set(EZLOPI_HAL_COMPONENTS
+
+)
+
+# Define cloud components
+set(EZLOPI_CLOUD_COMPONENTS
+
+)
+
+# Define sensor device components
+set(EZLOPI_SENSOR_DEVICE_COMPONENTS
+ # Add other sensor device components here
+)
+
+# Define service components
+set(EZLOPI_SERVICES
+ ezlopi-service-ble
+ ezlopi-service-ota
+ ezlopi-service-uart
+ ezlopi-service-modes
+ ezlopi-service-timer
+ ezlopi-service-webprov
+ ezlopi-service-gpioisr
+ ezlopi-service-meshbot
+ ezlopi-service-ws-server
+ ezlopi-service-broadcast
+)
+
+# Register the components
+idf_component_register(SRCS "ezlopi_main.c" "${config_src}"
+ INCLUDE_DIRS "."
+ REQUIRES ${EZLOPI_COMPONENTS}
+ ${EZLOPI_CORE_COMPONENTS}
+ ${EZLOPI_HAL_COMPONENTS}
+ ${EZLOPI_CLOUD_COMPONENTS}
+ ${EZLOPI_SENSOR_DEVICE_COMPONENTS}
+ ${EZLOPI_SERVICES}
+)
diff --git a/ezlopi-main/component.mk b/ezlopi-main/component.mk
new file mode 100644
index 000000000..17fe35eb4
--- /dev/null
+++ b/ezlopi-main/component.mk
@@ -0,0 +1,6 @@
+#
+# "main" pseudo-component makefile.
+#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
+
+
diff --git a/ezlopi-main/ezlopi_main.c b/ezlopi-main/ezlopi_main.c
index 52553861d..57d934aad 100644
--- a/ezlopi-main/ezlopi_main.c
+++ b/ezlopi-main/ezlopi_main.c
@@ -1,27 +1,58 @@
#include
-#include "EZLOPI_USER_CONFIG.h"
-
#include
+#include
+#include
#include
+#include
#include
#include
+
#include "ezlopi_util_trace.h"
+
#include "ezlopi_core_ezlopi.h"
+#include "ezlopi_service_ota.h"
+#include "ezlopi_service_ble.h"
+#include "ezlopi_service_uart.h"
+#include "ezlopi_service_timer.h"
+#include "ezlopi_service_modes.h"
+#include "ezlopi_service_meshbot.h"
+#include "ezlopi_service_gpioisr.h"
+#include "ezlopi_service_webprov.h"
+#include "ezlopi_service_ws_server.h"
+#include "ezlopi_service_broadcast.h"
+
+#define ENABLE_HEARTBIT_LED 0
static void blinky(void* pv);
void app_main(void)
{
+ gpio_install_isr_service(0);
+
+ gpio_isr_service_init();
+ EZPI_SERVICE_uart_init();
- xTaskCreate(blinky, "blinky", 2048, NULL, tskIDLE_PRIORITY, NULL);
ezlopi_init();
+
+ timer_service_init();
+ ezlopi_ble_service_init();
+
+ ezlopi_scenes_meshbot_init();
+ ezlopi_service_modes_init();
+
+ ezlopi_service_ws_server_start();
+ ezlopi_service_web_provisioning_init();
+
+ ota_service_init();
+ ezlopi_service_broadcast_init();
+
+ xTaskCreate(blinky, "blinky", 2 * 2048, NULL, 1, NULL);
}
static void blinky(void* pv)
{
-
-#ifdef EZPI_USR_CONFIG_ENABLE_HEARTBIT_LED
+#if (1 == ENABLE_HEARTBIT_LED)
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << GPIO_NUM_2),
.mode = GPIO_MODE_OUTPUT,
@@ -37,20 +68,21 @@ static void blinky(void* pv)
uint32_t count = 0;
while (1)
{
-
-#ifdef EZPI_USR_CONFIG_ENABLE_HEARTBIT_LED
+#if (1 == ENABLE_HEARTBIT_LED)
state ^= 1;
gpio_set_level(GPIO_NUM_2, state);
#endif
+
if (count++ > 10)
{
- TRACE_D("-----------------------------------------");
- TRACE_D("esp_get_free_heap_size: %.2fKB", (float)(esp_get_free_heap_size() / 1024.0));
- TRACE_D("esp_get_minimum_free_heap_size: %.2fKB", (float)(esp_get_minimum_free_heap_size() / 1024.0));
- TRACE_D("-----------------------------------------");
count = 0;
+
+ TRACE_D("----------------------------------------------");
+ TRACE_D("esp_get_free_heap_size - %f kB", esp_get_free_heap_size() / 1024.0);
+ TRACE_D("esp_get_minimum_free_heap_size: %f kB", esp_get_minimum_free_heap_size() / 1024.0);
+ TRACE_D("----------------------------------------------");
}
- vTaskDelay(1000 / portTICK_RATE_MS);
+ vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
diff --git a/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c b/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c
index 1bc25901f..ff9352164 100644
--- a/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c
+++ b/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c
@@ -18,29 +18,29 @@
// #define DEV_TEST_SETTINGS_EN
-static int __prepare(void *arg);
-static int __init(l_ezlopi_item_t *item);
-static int __set_value(l_ezlopi_item_t *item, void *arg);
-static int __get_value_cjson(l_ezlopi_item_t *item, void *arg);
+static int __prepare(void* arg);
+static int __init(l_ezlopi_item_t* item);
+static int __set_value(l_ezlopi_item_t* item, void* arg);
+static int __get_value_cjson(l_ezlopi_item_t* item, void* arg);
-static void __interrupt_upcall(void *arg);
-static void __toggle_gpio(l_ezlopi_item_t *item);
-static void __write_gpio_value(l_ezlopi_item_t *item);
-static void __set_gpio_value(l_ezlopi_item_t *item, int value);
+static void __interrupt_upcall(void* arg);
+static void __toggle_gpio(l_ezlopi_item_t* item);
+static void __write_gpio_value(l_ezlopi_item_t* item);
+static void __set_gpio_value(l_ezlopi_item_t* item, int value);
#ifdef DEV_TEST_SETTINGS_EN
-static int __settings_callback(e_ezlopi_settings_action_t action, struct l_ezlopi_device_settings_v3 *setting, void *arg, void *user_arg);
-static int __settings_get(void *arg, l_ezlopi_device_settings_v3_t *setting);
-static int __settings_set(void *arg, l_ezlopi_device_settings_v3_t *setting);
-static int __settings_reset(void *arg, l_ezlopi_device_settings_v3_t *setting);
-static int __settings_update(void *arg, l_ezlopi_device_settings_v3_t *setting);
+static int __settings_callback(e_ezlopi_settings_action_t action, struct l_ezlopi_device_settings_v3* setting, void* arg, void* user_arg);
+static int __settings_get(void* arg, l_ezlopi_device_settings_v3_t* setting);
+static int __settings_set(void* arg, l_ezlopi_device_settings_v3_t* setting);
+static int __settings_reset(void* arg, l_ezlopi_device_settings_v3_t* setting);
+static int __settings_update(void* arg, l_ezlopi_device_settings_v3_t* setting);
-static const char *nvs_key_backlight_brightness = "bklt";
+static const char* nvs_key_backlight_brightness = "bklt";
uint32_t settings_ids[2];
#endif // DEV_TEST_SETTINGS_EN
-int device_0001_digitalOut_generic(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int device_0001_digitalOut_generic(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
@@ -78,7 +78,7 @@ int device_0001_digitalOut_generic(e_ezlopi_actions_t action, l_ezlopi_item_t *i
}
#ifdef DEV_TEST_SETTINGS_EN
-static int __settings_callback(e_ezlopi_settings_action_t action, struct l_ezlopi_device_settings_v3 *setting, void *arg, void *user_arg)
+static int __settings_callback(e_ezlopi_settings_action_t action, struct l_ezlopi_device_settings_v3* setting, void* arg, void* user_arg)
{
int ret = 1;
switch (action)
@@ -111,19 +111,19 @@ static int __settings_callback(e_ezlopi_settings_action_t action, struct l_ezlop
return ret;
}
-static int __settings_get(void *arg, l_ezlopi_device_settings_v3_t *setting)
+static int __settings_get(void* arg, l_ezlopi_device_settings_v3_t* setting)
{
int ret = 0;
- cJSON *cjson_propertise = (cJSON *)arg;
+ cJSON* cjson_propertise = (cJSON*)arg;
if (cjson_propertise)
{
if (setting->cloud_properties.setting_id == settings_ids[0])
{
- cJSON *label = cJSON_CreateObject();
- cJSON *description = cJSON_CreateObject();
- cJSON *value = cJSON_CreateObject();
- cJSON *value_default = cJSON_CreateObject();
+ cJSON* label = cJSON_CreateObject();
+ cJSON* description = cJSON_CreateObject();
+ cJSON* value = cJSON_CreateObject();
+ cJSON* value_default = cJSON_CreateObject();
cJSON_AddStringToObject(label, "text", "User defined mode");
cJSON_AddStringToObject(label, "lang_tag", "ezlopi_presence_user_defined_mode_label");
@@ -151,8 +151,8 @@ static int __settings_get(void *arg, l_ezlopi_device_settings_v3_t *setting)
}
else if (setting->cloud_properties.setting_id == settings_ids[1])
{
- cJSON *label = cJSON_CreateObject();
- cJSON *description = cJSON_CreateObject();
+ cJSON* label = cJSON_CreateObject();
+ cJSON* description = cJSON_CreateObject();
cJSON_AddStringToObject(label, "text", "Backlight Brightness");
cJSON_AddStringToObject(label, "lang_tag", "ezlopi_digitalio_pwm_setting_label");
@@ -164,7 +164,7 @@ static int __settings_get(void *arg, l_ezlopi_device_settings_v3_t *setting)
cJSON_AddItemToObject(cjson_propertise, "description", description);
cJSON_AddStringToObject(cjson_propertise, ezlopi_valueType_str, "int");
- s_digio_settings_t *settings_data = (s_digio_settings_t *)setting->user_arg;
+ s_digio_settings_t* settings_data = (s_digio_settings_t*)setting->user_arg;
cJSON_AddNumberToObject(cjson_propertise, ezlopi_value_str, settings_data->settings_int_data);
cJSON_AddNumberToObject(cjson_propertise, "valueMin", 0);
@@ -177,10 +177,10 @@ static int __settings_get(void *arg, l_ezlopi_device_settings_v3_t *setting)
return ret;
}
-static int __settings_set(void *arg, l_ezlopi_device_settings_v3_t *setting)
+static int __settings_set(void* arg, l_ezlopi_device_settings_v3_t* setting)
{
int ret = 0;
- cJSON *cjson_propertise = (cJSON *)arg;
+ cJSON* cjson_propertise = (cJSON*)arg;
if (cjson_propertise)
{
if (setting->cloud_properties.setting_id == settings_ids[0])
@@ -192,7 +192,7 @@ static int __settings_set(void *arg, l_ezlopi_device_settings_v3_t *setting)
CJSON_GET_VALUE_INT(cjson_propertise, ezlopi_value_str, value);
TRACE_D("Setting Value : %d", value);
- s_digio_settings_t *settings_data = (s_digio_settings_t *)setting->user_arg;
+ s_digio_settings_t* settings_data = (s_digio_settings_t*)setting->user_arg;
settings_data->settings_int_data = value;
if (!ezlopi_nvs_write_int32(value, nvs_key_backlight_brightness))
@@ -205,7 +205,7 @@ static int __settings_set(void *arg, l_ezlopi_device_settings_v3_t *setting)
}
return ret;
}
-static int __settings_reset(void *arg, l_ezlopi_device_settings_v3_t *setting)
+static int __settings_reset(void* arg, l_ezlopi_device_settings_v3_t* setting)
{
int ret = 0;
if (setting->cloud_properties.setting_id == settings_ids[0])
@@ -213,7 +213,7 @@ static int __settings_reset(void *arg, l_ezlopi_device_settings_v3_t *setting)
}
else if (setting->cloud_properties.setting_id == settings_ids[1])
{
- s_digio_settings_t *settings_data = (s_digio_settings_t *)setting->user_arg;
+ s_digio_settings_t* settings_data = (s_digio_settings_t*)setting->user_arg;
settings_data->settings_int_data = 50; // 50 being default value
if (!ezlopi_nvs_write_int32(settings_data->settings_int_data, nvs_key_backlight_brightness))
@@ -224,10 +224,10 @@ static int __settings_reset(void *arg, l_ezlopi_device_settings_v3_t *setting)
return ret;
}
-static int __settings_update(void *arg, l_ezlopi_device_settings_v3_t *setting)
+static int __settings_update(void* arg, l_ezlopi_device_settings_v3_t* setting)
{
int ret = 0;
- cJSON *cjson_propertise = (cJSON *)arg;
+ cJSON* cjson_propertise = (cJSON*)arg;
if (cjson_propertise)
{
if (setting->cloud_properties.setting_id == settings_ids[0])
@@ -235,7 +235,7 @@ static int __settings_update(void *arg, l_ezlopi_device_settings_v3_t *setting)
}
else if (setting->cloud_properties.setting_id == settings_ids[1])
{
- s_digio_settings_t *settings_data = (s_digio_settings_t *)setting->user_arg;
+ s_digio_settings_t* settings_data = (s_digio_settings_t*)setting->user_arg;
cJSON_AddNumberToObject(cjson_propertise, ezlopi_value_str, settings_data->settings_int_data);
}
}
@@ -244,7 +244,7 @@ static int __settings_update(void *arg, l_ezlopi_device_settings_v3_t *setting)
#endif // DEV_TEST_SETTINGS_EN
-static void __setup_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cjson_device)
+static void __setup_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cjson_device)
{
// uint32_t device_id = 0;
// char *device_name = NULL;
@@ -260,7 +260,7 @@ static void __setup_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj
device->cloud_properties.device_type_id = NULL;
}
-static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
+static void __setup_item_properties(l_ezlopi_item_t* item, cJSON* cjson_device)
{
int tmp_var = 0;
item->cloud_properties.has_getter = true;
@@ -274,7 +274,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
CJSON_GET_VALUE_INT(cjson_device, ezlopi_dev_type_str, item->interface_type);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_is_ip_str, item->interface.gpio.gpio_in.enable);
- CJSON_GET_VALUE_INT(cjson_device, ezlopi_gpio_in_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_gpio_in_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_ip_inv_str, item->interface.gpio.gpio_in.invert);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_val_ip_str, item->interface.gpio.gpio_in.value);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_pullup_ip_str, tmp_var);
@@ -282,7 +282,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
item->interface.gpio.gpio_in.interrupt = GPIO_INTR_DISABLE;
item->interface.gpio.gpio_out.enable = true;
- CJSON_GET_VALUE_INT(cjson_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
+ CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_op_inv_str, item->interface.gpio.gpio_out.invert);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_val_op_str, item->interface.gpio.gpio_out.value);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_pullup_op_str, tmp_var);
@@ -290,7 +290,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
item->interface.gpio.gpio_out.pull = tmp_var ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY;
}
-static int __prepare(void *arg)
+static int __prepare(void* arg)
{
int ret = 0;
@@ -299,17 +299,17 @@ static int __prepare(void *arg)
settings_ids[1] = ezlopi_cloud_generate_settings_id();
#endif
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (arg)
{
- cJSON *cjson_device = prep_arg->cjson_device;
+ cJSON* cjson_device = prep_arg->cjson_device;
if (cjson_device)
{
- l_ezlopi_device_t *device = ezlopi_device_add_device(cjson_device);
+ l_ezlopi_device_t* device = ezlopi_device_add_device(cjson_device);
if (device)
{
__setup_device_cloud_properties(device, cjson_device);
- l_ezlopi_item_t *item = ezlopi_device_add_item_to_device(device, device_0001_digitalOut_generic);
+ l_ezlopi_item_t* item = ezlopi_device_add_item_to_device(device, device_0001_digitalOut_generic);
if (item)
{
item->cloud_properties.device_id = device->cloud_properties.device_id;
@@ -318,19 +318,19 @@ static int __prepare(void *arg)
}
#ifdef DEV_TEST_SETTINGS_EN
- l_ezlopi_device_settings_v3_t *setting_user_defined = ezlopi_device_add_settings_to_device_v3(device, __settings_callback);
+ l_ezlopi_device_settings_v3_t* setting_user_defined = ezlopi_device_add_settings_to_device_v3(device, __settings_callback);
if (setting_user_defined)
{
setting_user_defined->cloud_properties.setting_id = settings_ids[0];
ret = 1;
}
- l_ezlopi_device_settings_v3_t *setting_brightness = ezlopi_device_add_settings_to_device_v3(device, __settings_callback);
+ l_ezlopi_device_settings_v3_t* setting_brightness = ezlopi_device_add_settings_to_device_v3(device, __settings_callback);
if (setting_brightness)
{
setting_brightness->cloud_properties.setting_id = settings_ids[1];
- s_digio_settings_t *settings_value = (s_digio_settings_t *)malloc(sizeof(s_digio_settings_t));
+ s_digio_settings_t* settings_value = (s_digio_settings_t*)malloc(sizeof(s_digio_settings_t));
memset(settings_value, 0, sizeof(s_digio_settings_t));
if (ezlopi_nvs_read_int32(&settings_value->settings_int_data, nvs_key_backlight_brightness))
@@ -345,7 +345,7 @@ static int __prepare(void *arg)
}
}
- setting_brightness->user_arg = (void *)settings_value;
+ setting_brightness->user_arg = (void*)settings_value;
TRACE_E("settings_data: %p", settings_value);
TRACE_E("setting->user_arg: %p", setting_brightness->user_arg);
@@ -366,39 +366,72 @@ static int __prepare(void *arg)
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- if (255 != item->interface.gpio.gpio_out.gpio_num)
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num) &&
+ (255 != item->interface.gpio.gpio_out.gpio_num))
{
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ const gpio_config_t io_conf = {
+ .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
+ .mode = GPIO_MODE_OUTPUT,
+ .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLUP_ENABLE
+ : GPIO_PULLUP_DISABLE,
+ .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLDOWN_ENABLE
+ : GPIO_PULLDOWN_DISABLE,
+ .intr_type = GPIO_INTR_DISABLE,
+ };
+
+ if (0 == gpio_config(&io_conf))
{
- const gpio_config_t io_conf = {
- .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
- .mode = GPIO_MODE_OUTPUT,
- .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLUP_ENABLE
- : GPIO_PULLUP_DISABLE,
- .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLDOWN_ENABLE
- : GPIO_PULLDOWN_DISABLE,
- .intr_type = GPIO_INTR_DISABLE,
- };
-
- gpio_config(&io_conf);
// digital_io_write_gpio_value(item);
__write_gpio_value(item);
ret = 1;
}
+ else
+ {
+ ret = -1;
+ }
}
+ }
+
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num) &&
+ (-1 != item->interface.gpio.gpio_in.gpio_num) &&
+ (255 != item->interface.gpio.gpio_in.gpio_num))
+ {
+ const gpio_config_t io_conf = {
+ .pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
+ .mode = GPIO_MODE_INPUT,
+ .pull_up_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLUP_ONLY) ||
+ (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLUP_ENABLE
+ : GPIO_PULLUP_DISABLE,
+ .pull_down_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLDOWN_ONLY) ||
+ (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLDOWN_ENABLE
+ : GPIO_PULLDOWN_DISABLE,
+ .intr_type = (GPIO_PULLUP_ONLY == item->interface.gpio.gpio_in.pull)
+ ? GPIO_INTR_POSEDGE
+ : GPIO_INTR_NEGEDGE,
+ };
+
+ TRACE_D("enabling interrup for pin: %d", item->interface.gpio.gpio_in.gpio_num);
+
+ gpio_config(&io_conf);
+ gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
+ ret = 1;
+ }
- if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num) &&
- (-1 != item->interface.gpio.gpio_in.gpio_num) &&
- (255 != item->interface.gpio.gpio_in.gpio_num))
+ if (0 == ret)
+ {
+ ret = -1;
+ if (item->user_arg)
{
const gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
@@ -416,125 +449,131 @@ static int __init(l_ezlopi_item_t *item)
: GPIO_INTR_NEGEDGE,
};
- gpio_config(&io_conf);
- gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
- ret = 1;
+ if (0 == gpio_config(&io_conf))
+ {
+ gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
+static int __get_value_cjson(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- cJSON *cjson_propertise = (cJSON *)arg;
- if (cjson_propertise)
+ if (item && arg)
{
- cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_out.value);
- cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_out.value ? true : false));
- ret = 1;
+ cJSON* cjson_propertise = (cJSON*)arg;
+ if (cjson_propertise)
+ {
+ cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_out.value);
+ cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_out.value ? true : false));
+ ret = 1;
+ }
}
-
return ret;
}
-static void __set_gpio_value(l_ezlopi_item_t *item, int value)
+static void __set_gpio_value(l_ezlopi_item_t* item, int value)
{
gpio_set_level(item->interface.gpio.gpio_out.gpio_num, value);
item->interface.gpio.gpio_out.value = value;
}
-static int __set_value(l_ezlopi_item_t *item, void *arg)
+static int __set_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- cJSON *cjson_params = (cJSON *)arg;
-
- if (NULL != cjson_params)
+ if (item && arg)
{
- CJSON_TRACE("cjson_params", cjson_params);
+ cJSON* cjson_params = (cJSON*)arg;
- int value = 0;
- cJSON *cj_value = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
- if (cj_value)
+ if (NULL != cjson_params)
{
- switch (cj_value->type)
+ CJSON_TRACE("cjson_params", cjson_params);
+
+ int value = 0;
+ cJSON* cj_value = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
+ if (cj_value)
{
- case cJSON_False:
- value = 0;
- break;
- case cJSON_True:
- value = 1;
- break;
- case cJSON_Number:
- value = cj_value->valueint;
- break;
-
- default:
- break;
+ switch (cj_value->type)
+ {
+ case cJSON_False:
+ value = 0;
+ break;
+ case cJSON_True:
+ value = 1;
+ break;
+ case cJSON_Number:
+ value = cj_value->valueint;
+ break;
+
+ default:
+ break;
+ }
}
- }
- TRACE_S("item_name: %s", item->cloud_properties.item_name);
- TRACE_S("gpio_num: %d", item->interface.gpio.gpio_out.gpio_num);
- TRACE_S("item_id: 0x%08x", item->cloud_properties.item_id);
- TRACE_S("prev value: %d", item->interface.gpio.gpio_out.value);
- TRACE_S("cur value: %d", value);
+ TRACE_I("item_name: %s", item->cloud_properties.item_name);
+ TRACE_I("gpio_num: %d", item->interface.gpio.gpio_out.gpio_num);
+ TRACE_I("item_id: 0x%08x", item->cloud_properties.item_id);
+ TRACE_I("prev value: %d", item->interface.gpio.gpio_out.value);
+ TRACE_I("cur value: %d", value);
- if (255 != item->interface.gpio.gpio_out.gpio_num)
- {
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ if (255 != item->interface.gpio.gpio_out.gpio_num)
{
- __set_gpio_value(item, value);
- ezlopi_device_value_updated_from_device_v3(item);
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ {
+ __set_gpio_value(item, value);
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- else
- {
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
- while (curr_device)
+ else
{
- l_ezlopi_item_t *curr_item = curr_device->items;
- while (curr_item)
+ l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
+ while (curr_device)
{
- if ((EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT == curr_item->interface_type) && (255 != curr_item->interface.gpio.gpio_out.gpio_num))
+ l_ezlopi_item_t* curr_item = curr_device->items;
+ while (curr_item)
{
- TRACE_D("GPIO-pin: %d", curr_item->interface.gpio.gpio_out.gpio_num);
- TRACE_D("value: %d", value);
- __set_gpio_value(curr_item, value);
- ezlopi_device_value_updated_from_device_v3(curr_item);
+ if ((EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT == curr_item->interface_type) && (255 != curr_item->interface.gpio.gpio_out.gpio_num))
+ {
+ TRACE_D("GPIO-pin: %d", curr_item->interface.gpio.gpio_out.gpio_num);
+ TRACE_D("value: %d", value);
+ __set_gpio_value(curr_item, value);
+ ezlopi_device_value_updated_from_device_v3(curr_item);
+ }
+ curr_item = curr_item->next;
}
- curr_item = curr_item->next;
+ curr_device = curr_device->next;
}
- curr_device = curr_device->next;
- }
- item->interface.gpio.gpio_out.value = value;
- ezlopi_device_value_updated_from_device_v3(item);
+ item->interface.gpio.gpio_out.value = value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
-
return ret;
}
-static void __write_gpio_value(l_ezlopi_item_t *item)
+static void __write_gpio_value(l_ezlopi_item_t* item)
{
uint32_t write_value = (0 == item->interface.gpio.gpio_out.invert) ? item->interface.gpio.gpio_out.value : (item->interface.gpio.gpio_out.value ? 0 : 1);
gpio_set_level(item->interface.gpio.gpio_out.gpio_num, write_value);
}
-static void __interrupt_upcall(void *arg)
+static void __interrupt_upcall(void* arg)
{
- l_ezlopi_item_t *item = (l_ezlopi_item_t *)arg;
+ l_ezlopi_item_t* item = (l_ezlopi_item_t*)arg;
if (item)
{
__toggle_gpio(item);
@@ -542,7 +581,7 @@ static void __interrupt_upcall(void *arg)
}
}
-static void __toggle_gpio(l_ezlopi_item_t *item)
+static void __toggle_gpio(l_ezlopi_item_t* item)
{
uint32_t write_value = !(item->interface.gpio.gpio_out.value);
gpio_set_level(item->interface.gpio.gpio_out.gpio_num, write_value);
diff --git a/ezlopi-sensors-devices/device-0002-digitalOut-relay/device_0002_digitalOut_relay.c b/ezlopi-sensors-devices/device-0002-digitalOut-relay/device_0002_digitalOut_relay.c
index a8bacd456..10b707eda 100644
--- a/ezlopi-sensors-devices/device-0002-digitalOut-relay/device_0002_digitalOut_relay.c
+++ b/ezlopi-sensors-devices/device-0002-digitalOut-relay/device_0002_digitalOut_relay.c
@@ -99,7 +99,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
item->interface.gpio.gpio_in.interrupt = GPIO_INTR_DISABLE;
item->interface.gpio.gpio_out.enable = true;
- CJSON_GET_VALUE_INT(cjson_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
+ CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_op_inv_str, item->interface.gpio.gpio_out.invert);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_val_op_str, item->interface.gpio.gpio_out.value);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_pullup_op_str, tmp_var);
@@ -144,34 +144,37 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (255 != item->interface.gpio.gpio_out.gpio_num)
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num) &&
+ (255 != item->interface.gpio.gpio_out.gpio_num))
{
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ const gpio_config_t io_conf = {
+ .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
+ .mode = GPIO_MODE_OUTPUT,
+ .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLUP_ENABLE
+ : GPIO_PULLUP_DISABLE,
+ .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLDOWN_ENABLE
+ : GPIO_PULLDOWN_DISABLE,
+ .intr_type = GPIO_INTR_DISABLE,
+ };
+
+ if (0 == gpio_config(&io_conf))
{
- const gpio_config_t io_conf = {
- .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
- .mode = GPIO_MODE_OUTPUT,
- .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLUP_ENABLE
- : GPIO_PULLUP_DISABLE,
- .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLDOWN_ENABLE
- : GPIO_PULLDOWN_DISABLE,
- .intr_type = GPIO_INTR_DISABLE,
- };
-
- gpio_config(&io_conf);
// digital_io_write_gpio_value(item);
__write_gpio_value(item);
ret = 1;
}
+ else
+ {
+ ret = -1;
+ }
}
-
- if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num) &&
- (-1 != item->interface.gpio.gpio_in.gpio_num) &&
- (255 != item->interface.gpio.gpio_in.gpio_num))
+ else if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num) &&
+ (-1 != item->interface.gpio.gpio_in.gpio_num) &&
+ (255 != item->interface.gpio.gpio_in.gpio_num))
{
const gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
@@ -188,19 +191,20 @@ static int __init(l_ezlopi_item_t *item)
? GPIO_INTR_POSEDGE
: GPIO_INTR_NEGEDGE,
};
-
- gpio_config(&io_conf);
- gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
- ret = 1;
+ if (0 == gpio_config(&io_conf))
+ {
+ gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
@@ -210,14 +214,16 @@ static int __init(l_ezlopi_item_t *item)
static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON *cjson_propertise = (cJSON *)arg;
- if (cjson_propertise)
+ if (item && arg)
{
- cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_out.value);
- cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_out.value ? true : false));
- ret = 1;
+ cJSON *cjson_propertise = (cJSON *)arg;
+ if (cjson_propertise)
+ {
+ cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_out.value);
+ cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_out.value ? true : false));
+ ret = 1;
+ }
}
-
return ret;
}
@@ -230,79 +236,75 @@ static void __set_gpio_value(l_ezlopi_item_t *item, int value)
static int __set_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON *cjson_params = (cJSON *)arg;
-
- if (NULL != cjson_params)
+ if (item && arg)
{
- CJSON_TRACE("cjson_params", cjson_params);
+ cJSON *cjson_params = (cJSON *)arg;
- int value = 0;
- cJSON *cj_value = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
- if (cj_value)
+ if (NULL != cjson_params)
{
- switch (cj_value->type)
- {
- case cJSON_False:
- {
- value = 0;
- break;
- }
- case cJSON_True:
- {
- value = 1;
- break;
- }
- case cJSON_Number:
- {
- value = cj_value->valueint;
- break;
- }
+ CJSON_TRACE("cjson_params", cjson_params);
- default:
- break;
+ int value = 0;
+ cJSON *cj_value = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
+ if (cj_value)
+ {
+ switch (cj_value->type)
+ {
+ case cJSON_False:
+ value = 0;
+ break;
+ case cJSON_True:
+ value = 1;
+ break;
+ case cJSON_Number:
+ value = cj_value->valueint;
+ break;
+
+ default:
+ break;
+ }
}
- }
- TRACE_S("item_name: %s", item->cloud_properties.item_name);
- TRACE_S("gpio_num: %d", item->interface.gpio.gpio_out.gpio_num);
- TRACE_S("item_id: %08x", item->cloud_properties.item_id);
- TRACE_S("prev value: %d", item->interface.gpio.gpio_out.value);
- TRACE_S("cur value: %d", value);
+ TRACE_S("item_name: %s", item->cloud_properties.item_name);
+ TRACE_S("gpio_num: %d", item->interface.gpio.gpio_out.gpio_num);
+ TRACE_S("item_id: 0x%08x", item->cloud_properties.item_id);
+ TRACE_S("prev value: %d", item->interface.gpio.gpio_out.value);
+ TRACE_S("cur value: %d", value);
- if (255 != item->interface.gpio.gpio_out.gpio_num)
- {
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ if (255 != item->interface.gpio.gpio_out.gpio_num)
{
- __set_gpio_value(item, value);
- ezlopi_device_value_updated_from_device_v3(item);
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ {
+ __set_gpio_value(item, value);
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- else
- {
- // in case of master switch
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
- while (curr_device)
+ else
{
- l_ezlopi_item_t *curr_item = curr_device->items;
- while (curr_item)
+ // in case of master switch
+ l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ while (curr_device)
{
- if ((EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT == curr_item->interface_type) && (255 != curr_item->interface.gpio.gpio_out.gpio_num))
+ l_ezlopi_item_t *curr_item = curr_device->items;
+ while (curr_item)
{
- TRACE_D("GPIO-pin: %d", curr_item->interface.gpio.gpio_out.gpio_num);
- TRACE_D("value: %d", value);
- __set_gpio_value(curr_item, value);
- ezlopi_device_value_updated_from_device_v3(curr_item);
+ if ((EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT == curr_item->interface_type) && (255 != curr_item->interface.gpio.gpio_out.gpio_num))
+ {
+ TRACE_D("GPIO-pin: %d", curr_item->interface.gpio.gpio_out.gpio_num);
+ TRACE_D("value: %d", value);
+ __set_gpio_value(curr_item, value);
+ ezlopi_device_value_updated_from_device_v3(curr_item);
+ }
+ curr_item = curr_item->next;
}
- curr_item = curr_item->next;
+ curr_device = curr_device->next;
}
- curr_device = curr_device->next;
- }
- item->interface.gpio.gpio_out.value = value;
- ezlopi_device_value_updated_from_device_v3(item);
+ item->interface.gpio.gpio_out.value = value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
-
return ret;
}
diff --git a/ezlopi-sensors-devices/device-0003-digitalOut-plug/device_0003_digitalOut_plug.c b/ezlopi-sensors-devices/device-0003-digitalOut-plug/device_0003_digitalOut_plug.c
index 6fada8c98..72277d881 100644
--- a/ezlopi-sensors-devices/device-0003-digitalOut-plug/device_0003_digitalOut_plug.c
+++ b/ezlopi-sensors-devices/device-0003-digitalOut-plug/device_0003_digitalOut_plug.c
@@ -92,7 +92,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
CJSON_GET_VALUE_INT(cjson_device, ezlopi_dev_type_str, item->interface_type);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_is_ip_str, item->interface.gpio.gpio_in.enable);
- CJSON_GET_VALUE_INT(cjson_device, ezlopi_gpio_in_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_gpio_in_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_ip_inv_str, item->interface.gpio.gpio_in.invert);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_val_ip_str, item->interface.gpio.gpio_in.value);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_pullup_ip_str, tmp_var);
@@ -100,7 +100,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
item->interface.gpio.gpio_in.interrupt = GPIO_INTR_DISABLE;
item->interface.gpio.gpio_out.enable = true;
- CJSON_GET_VALUE_INT(cjson_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
+ CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_op_inv_str, item->interface.gpio.gpio_out.invert);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_val_op_str, item->interface.gpio.gpio_out.value);
CJSON_GET_VALUE_INT(cjson_device, ezlopi_pullup_op_str, tmp_var);
@@ -145,34 +145,38 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (255 != item->interface.gpio.gpio_out.gpio_num)
+
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num) &&
+ (255 != item->interface.gpio.gpio_out.gpio_num))
{
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ const gpio_config_t io_conf = {
+ .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
+ .mode = GPIO_MODE_OUTPUT,
+ .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLUP_ENABLE
+ : GPIO_PULLUP_DISABLE,
+ .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLDOWN_ENABLE
+ : GPIO_PULLDOWN_DISABLE,
+ .intr_type = GPIO_INTR_DISABLE,
+ };
+
+ if (0 == gpio_config(&io_conf))
{
- const gpio_config_t io_conf = {
- .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
- .mode = GPIO_MODE_OUTPUT,
- .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLUP_ENABLE
- : GPIO_PULLUP_DISABLE,
- .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLDOWN_ENABLE
- : GPIO_PULLDOWN_DISABLE,
- .intr_type = GPIO_INTR_DISABLE,
- };
-
- gpio_config(&io_conf);
// digital_io_write_gpio_value(item);
__write_gpio_value(item);
ret = 1;
}
+ else
+ {
+ ret = -1;
+ }
}
-
- if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num) &&
- (-1 != item->interface.gpio.gpio_in.gpio_num) &&
- (255 != item->interface.gpio.gpio_in.gpio_num))
+ else if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num) &&
+ (-1 != item->interface.gpio.gpio_in.gpio_num) &&
+ (255 != item->interface.gpio.gpio_in.gpio_num))
{
const gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
@@ -190,18 +194,20 @@ static int __init(l_ezlopi_item_t *item)
: GPIO_INTR_NEGEDGE,
};
- gpio_config(&io_conf);
- gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
- ret = 1;
+ if (0 == gpio_config(&io_conf))
+ {
+ gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
@@ -211,14 +217,16 @@ static int __init(l_ezlopi_item_t *item)
static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON *cjson_propertise = (cJSON *)arg;
- if (cjson_propertise)
+ if (item && arg)
{
- cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_out.value);
- cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_out.value ? true : false));
- ret = 1;
+ cJSON *cjson_propertise = (cJSON *)arg;
+ if (cjson_propertise)
+ {
+ cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_out.value);
+ cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_out.value ? true : false));
+ ret = 1;
+ }
}
-
return ret;
}
@@ -231,72 +239,74 @@ static void __set_gpio_value(l_ezlopi_item_t *item, int value)
static int __set_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON *cjson_params = (cJSON *)arg;
-
- if (NULL != cjson_params)
+ if (item && arg)
{
- CJSON_TRACE("cjson_params", cjson_params);
+ cJSON *cjson_params = (cJSON *)arg;
- int value = 0;
- cJSON *cj_value = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
- if (cj_value)
+ if (NULL != cjson_params)
{
- switch (cj_value->type)
+ CJSON_TRACE("cjson_params", cjson_params);
+
+ int value = 0;
+ cJSON *cj_value = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
+ if (cj_value)
{
- case cJSON_False:
- value = 0;
- break;
- case cJSON_True:
- value = 1;
- break;
- case cJSON_Number:
- value = cj_value->valueint;
- break;
-
- default:
- break;
+ switch (cj_value->type)
+ {
+ case cJSON_False:
+ value = 0;
+ break;
+ case cJSON_True:
+ value = 1;
+ break;
+ case cJSON_Number:
+ value = cj_value->valueint;
+ break;
+
+ default:
+ break;
+ }
}
- }
- TRACE_S("item_name: %s", item->cloud_properties.item_name);
- TRACE_S("gpio_num: %d", item->interface.gpio.gpio_out.gpio_num);
- TRACE_S("item_id: 0x%08x", item->cloud_properties.item_id);
- TRACE_S("prev value: %d", item->interface.gpio.gpio_out.value);
- TRACE_S("cur value: %d", value);
+ TRACE_S("item_name: %s", item->cloud_properties.item_name);
+ TRACE_S("gpio_num: %d", item->interface.gpio.gpio_out.gpio_num);
+ TRACE_S("item_id: 0x%08x", item->cloud_properties.item_id);
+ TRACE_S("prev value: %d", item->interface.gpio.gpio_out.value);
+ TRACE_S("cur value: %d", value);
- if (255 != item->interface.gpio.gpio_out.gpio_num)
- {
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ if (255 != item->interface.gpio.gpio_out.gpio_num)
{
- __set_gpio_value(item, value);
- ezlopi_device_value_updated_from_device_v3(item);
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ {
+ __set_gpio_value(item, value);
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- else
- {
- l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
- while (curr_device)
+ else
{
- l_ezlopi_item_t *curr_item = curr_device->items;
- while (curr_item)
+ l_ezlopi_device_t *curr_device = ezlopi_device_get_head();
+ while (curr_device)
{
- if ((EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT == curr_item->interface_type) && (255 != curr_item->interface.gpio.gpio_out.gpio_num))
+ l_ezlopi_item_t *curr_item = curr_device->items;
+ while (curr_item)
{
- TRACE_D("GPIO-pin: %d", curr_item->interface.gpio.gpio_out.gpio_num);
- TRACE_D("value: %d", value);
- __set_gpio_value(curr_item, value);
- ezlopi_device_value_updated_from_device_v3(curr_item);
+ if ((EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT == curr_item->interface_type) && (255 != curr_item->interface.gpio.gpio_out.gpio_num))
+ {
+ TRACE_D("GPIO-pin: %d", curr_item->interface.gpio.gpio_out.gpio_num);
+ TRACE_D("value: %d", value);
+ __set_gpio_value(curr_item, value);
+ ezlopi_device_value_updated_from_device_v3(curr_item);
+ }
+ curr_item = curr_item->next;
}
- curr_item = curr_item->next;
+ curr_device = curr_device->next;
}
- curr_device = curr_device->next;
- }
- item->interface.gpio.gpio_out.value = value;
- ezlopi_device_value_updated_from_device_v3(item);
+ item->interface.gpio.gpio_out.value = value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
-
return ret;
}
diff --git a/ezlopi-sensors-devices/device-0004-digitalIn-generic/device_0004_digitalIn_generic.c b/ezlopi-sensors-devices/device-0004-digitalIn-generic/device_0004_digitalIn_generic.c
index 7f5b2ad45..91d1d6028 100644
--- a/ezlopi-sensors-devices/device-0004-digitalIn-generic/device_0004_digitalIn_generic.c
+++ b/ezlopi-sensors-devices/device-0004-digitalIn-generic/device_0004_digitalIn_generic.c
@@ -84,7 +84,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
item->interface.gpio.gpio_in.enable = true;
CJSON_GET_VALUE_INT(cjson_device, ezlopi_dev_type_str, item->interface_type);
- CJSON_GET_VALUE_INT(cjson_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cjson_device, "logic_inv", item->interface.gpio.gpio_in.invert);
CJSON_GET_VALUE_INT(cjson_device, "pull_up", tmp_var);
item->interface.gpio.gpio_in.pull = tmp_var ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY;
@@ -94,9 +94,9 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)
static int __prepare(void *arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (arg)
{
+ s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
cJSON *cjson_device = prep_arg->cjson_device;
if (cjson_device)
{
@@ -148,19 +148,20 @@ static int __init(l_ezlopi_item_t *item)
: GPIO_INTR_NEGEDGE,
};
- gpio_config(&io_conf);
- gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
-
- ret = 1;
+ if (0 == gpio_config(&io_conf))
+ {
+ gpio_isr_service_register_v3(item, __interrupt_upcall, 1000);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
@@ -170,12 +171,15 @@ static int __init(l_ezlopi_item_t *item)
static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON *cjson_propertise = (cJSON *)arg;
- if (cjson_propertise)
+ if (item && arg)
{
- cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_in.value);
- cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? true : false));
- ret = 1;
+ cJSON *cjson_propertise = (cJSON *)arg;
+ if (cjson_propertise)
+ {
+ cJSON_AddBoolToObject(cjson_propertise, ezlopi_value_str, item->interface.gpio.gpio_in.value);
+ cJSON_AddStringToObject(cjson_propertise, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? true : false));
+ ret = 1;
+ }
}
return ret;
diff --git a/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/CMakeLists.txt b/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/CMakeLists.txt
index 6a1375f20..82fa3f79c 100644
--- a/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/CMakeLists.txt
+++ b/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/CMakeLists.txt
@@ -2,10 +2,12 @@
idf_component_register(SRCS "device_0009_other_RMT_SK6812.c"
INCLUDE_DIRS "."
- REQUIRES ezlopi-util-trace
+ REQUIRES
driver
led_strip
+ ezlopi-util-trace
+
ezlopi-core-timer
ezlopi-core-cloud
ezlopi-core-actions
diff --git a/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/device_0009_other_RMT_SK6812.c b/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/device_0009_other_RMT_SK6812.c
index 222a780ef..486c2eacc 100644
--- a/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/device_0009_other_RMT_SK6812.c
+++ b/ezlopi-sensors-devices/device-0009-other-RMT-SK6812/device_0009_other_RMT_SK6812.c
@@ -22,22 +22,22 @@
typedef struct s_dimmer_args
{
led_strip_t sk6812_strip;
- l_ezlopi_item_t *switch_item;
- l_ezlopi_item_t *dimmer_item;
- l_ezlopi_item_t *dimmer_up_item;
- l_ezlopi_item_t *dimmer_down_item;
- l_ezlopi_item_t *dimmer_stop_item;
- l_ezlopi_item_t *rgb_color_item;
+ l_ezlopi_item_t* switch_item;
+ l_ezlopi_item_t* dimmer_item;
+ l_ezlopi_item_t* dimmer_up_item;
+ l_ezlopi_item_t* dimmer_down_item;
+ l_ezlopi_item_t* dimmer_stop_item;
+ l_ezlopi_item_t* rgb_color_item;
uint8_t previous_brightness;
bool sk6812_led_strip_initialized;
} s_dimmer_args_t;
-static int __prepare(void *arg);
-static int __init(l_ezlopi_item_t *item);
-static int __set_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
+static int __prepare(void* arg);
+static int __init(l_ezlopi_item_t* item);
+static int __set_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
-int device_0009_other_RMT_SK6812(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int device_0009_other_RMT_SK6812(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
@@ -73,70 +73,72 @@ int device_0009_other_RMT_SK6812(e_ezlopi_actions_t action, l_ezlopi_item_t *ite
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
-
- led_strip_t *sk6812_strip = (led_strip_t *)item->user_arg;
- cJSON *cjson_properties = (cJSON *)arg;
- if ((NULL != cjson_properties) && (NULL != sk6812_strip))
+ if (item && arg)
{
- if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
+ led_strip_t *sk6812_strip = (led_strip_t *)item->user_arg;
+ cJSON *cjson_properties = (cJSON *)arg;
+ if ((NULL != cjson_properties) && (NULL != sk6812_strip))
{
- cJSON *color_json = cJSON_AddObjectToObject(cjson_properties, ezlopi_value_str);
- if (color_json)
+ if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
+ {
+ cJSON *color_json = cJSON_AddObjectToObject(cjson_properties, ezlopi_value_str);
+ if (color_json)
+ {
+ int green = sk6812_strip->buf[0];
+ int red = sk6812_strip->buf[1];
+ int blue = sk6812_strip->buf[2];
+ cJSON_AddNumberToObject(color_json, "red", red);
+ cJSON_AddNumberToObject(color_json, "green", green);
+ cJSON_AddNumberToObject(color_json, "blue", blue);
+ cJSON_AddNumberToObject(color_json, "cwhite", ((red << 16) | (green << 8) | (blue)));
+ char *formatted_val = ezlopi_valueformatter_rgb(red, green, blue);
+ if (formatted_val)
+ {
+ cJSON_AddStringToObject(cjson_properties, ezlopi_valueFormatted_str, formatted_val);
+ free(formatted_val);
+ }
+ }
+ }
+ else if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
{
- int green = sk6812_strip->buf[0];
- int red = sk6812_strip->buf[1];
- int blue = sk6812_strip->buf[2];
- cJSON_AddNumberToObject(color_json, "red", red);
- cJSON_AddNumberToObject(color_json, "green", green);
- cJSON_AddNumberToObject(color_json, "blue", blue);
- cJSON_AddNumberToObject(color_json, "cwhite", ((red << 16) | (green << 8) | (blue)));
- char *formatted_val = ezlopi_valueformatter_rgb(red, green, blue);
+ item->interface.pwm.duty_cycle = (int)ceil(((sk6812_strip->brightness * 100.0) / 255.0));
+ cJSON_AddNumberToObject(cjson_properties, ezlopi_value_str, item->interface.pwm.duty_cycle);
+ char *formatted_val = ezlopi_valueformatter_int32(item->interface.pwm.duty_cycle);
if (formatted_val)
{
cJSON_AddStringToObject(cjson_properties, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
}
- }
- else if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
- {
- item->interface.pwm.duty_cycle = (int)ceil(((sk6812_strip->brightness * 100.0) / 255.0));
- cJSON_AddNumberToObject(cjson_properties, ezlopi_value_str, item->interface.pwm.duty_cycle);
- char *formatted_val = ezlopi_valueformatter_int32(item->interface.pwm.duty_cycle);
- if (formatted_val)
+ else if (ezlopi_item_name_switch == item->cloud_properties.item_name)
{
+ item->interface.gpio.gpio_in.value = (0 == sk6812_strip->brightness) ? 0 : 1;
+ cJSON_AddBoolToObject(cjson_properties, ezlopi_value_str, item->interface.gpio.gpio_in.value);
+ const char *formatted_val = ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? true : false);
cJSON_AddStringToObject(cjson_properties, ezlopi_valueFormatted_str, formatted_val);
- free(formatted_val);
}
}
- else if (ezlopi_item_name_switch == item->cloud_properties.item_name)
- {
- item->interface.gpio.gpio_in.value = (0 == sk6812_strip->brightness) ? 0 : 1;
- cJSON_AddBoolToObject(cjson_properties, ezlopi_value_str, item->interface.gpio.gpio_in.value);
- const char *formatted_val = ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? true : false);
- cJSON_AddStringToObject(cjson_properties, ezlopi_valueFormatted_str, formatted_val);
- }
}
return ret;
}
-static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __set_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- if (arg && item)
+ if (item && arg)
{
- cJSON *cjson_params = (cJSON *)arg;
- s_dimmer_args_t *dimmer_args = (s_dimmer_args_t *)item->user_arg;
+ cJSON* cjson_params = (cJSON*)arg;
+ s_dimmer_args_t* dimmer_args = (s_dimmer_args_t*)item->user_arg;
if (NULL != dimmer_args)
{
if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
{
- cJSON *cjson_params_color_values = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
+ cJSON* cjson_params_color_values = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
rgb_t color = {
.red = 0,
@@ -176,7 +178,7 @@ static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
}
else
{
- TRACE_I("item->cloud_properties.item_name => %s", item->cloud_properties.item_name);
+ TRACE_D("item->cloud_properties.item_name => %s", item->cloud_properties.item_name);
}
}
}
@@ -184,64 +186,77 @@ static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- s_dimmer_args_t *dimmer_args = (s_dimmer_args_t *)item->user_arg;
-
- if (0 == dimmer_args->sk6812_led_strip_initialized)
+ if (GPIO_IS_VALID_GPIO(item->interface.pwm.gpio_num))
{
- dimmer_args->sk6812_strip.type = LED_STRIP_SK6812;
- dimmer_args->sk6812_strip.length = 1;
- dimmer_args->sk6812_strip.gpio = item->interface.pwm.gpio_num;
- dimmer_args->sk6812_strip.buf = NULL;
- dimmer_args->sk6812_strip.brightness = 255;
- dimmer_args->sk6812_strip.channel = RMT_CHANNEL_0;
-
- led_strip_install();
- esp_err_t err = led_strip_init(&dimmer_args->sk6812_strip);
- if (ESP_OK == err)
+ s_dimmer_args_t *dimmer_args = (s_dimmer_args_t *)item->user_arg;
+ if (dimmer_args)
{
- rgb_t color = {
- .red = 255,
- .green = 255,
- .blue = 255,
- };
-
- err |= led_strip_fill(&dimmer_args->sk6812_strip, 0, dimmer_args->sk6812_strip.length, color);
- if (ESP_OK == (err = led_strip_set_brightness(&dimmer_args->sk6812_strip, 255)))
+ if (0 == dimmer_args->sk6812_led_strip_initialized)
{
- if (ESP_OK == (err = led_strip_flush(&dimmer_args->sk6812_strip)))
+ dimmer_args->sk6812_strip.type = LED_STRIP_SK6812;
+ dimmer_args->sk6812_strip.length = 1;
+ dimmer_args->sk6812_strip.gpio = item->interface.pwm.gpio_num;
+ dimmer_args->sk6812_strip.buf = NULL;
+ dimmer_args->sk6812_strip.brightness = 255;
+ dimmer_args->sk6812_strip.channel = RMT_CHANNEL_0;
+
+ led_strip_install();
+ esp_err_t err = led_strip_init(&dimmer_args->sk6812_strip);
+ if (ESP_OK == err)
+ {
+ rgb_t color = {
+ .red = 255,
+ .green = 255,
+ .blue = 255,
+ };
+
+ err |= led_strip_fill(&dimmer_args->sk6812_strip, 0, dimmer_args->sk6812_strip.length, color);
+ if (ESP_OK == (err = led_strip_set_brightness(&dimmer_args->sk6812_strip, 255)))
+ {
+ if (ESP_OK == (err = led_strip_flush(&dimmer_args->sk6812_strip)))
+ {
+ ret = 1;
+ dimmer_args->sk6812_led_strip_initialized = true;
+ }
+ }
+ }
+
+ if (ESP_OK != err)
{
- ret = 1;
- dimmer_args->sk6812_led_strip_initialized = true;
+ TRACE_E("Couldn't initiate device!, error: %d", err);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
}
}
+ else
+ {
+ TRACE_E("Here");
+ ret = -1;
+ }
}
-
- if (ESP_OK != err)
+ else
{
- TRACE_E("Couldn't initiate device!, error: %d", err);
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
}
}
- if (0 == ret)
+ else
{
- TRACE_E("Here");
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static void __prepare_device_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -255,43 +270,43 @@ static void __prepare_device_properties(l_ezlopi_device_t *device, cJSON *cj_dev
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_SK6812_RGB_color_item(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_SK6812_RGB_color_item(l_ezlopi_item_t* item, cJSON* cj_device)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.item_name = ezlopi_item_name_rgbcolor,
- item->cloud_properties.show = true;
+ item->cloud_properties.show = true;
item->cloud_properties.scale = NULL;
item->cloud_properties.value_type = value_type_rgb;
item->interface_type = EZLOPI_DEVICE_INTERFACE_PWM;
item->interface.pwm.channel = 0;
item->interface.pwm.value = 0;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
}
-static void __prepare_SK6812_RGB_dimmer_item(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_SK6812_RGB_dimmer_item(l_ezlopi_item_t* item, cJSON* cj_device)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.item_name = ezlopi_item_name_dimmer,
- item->cloud_properties.show = true;
+ item->cloud_properties.show = true;
item->cloud_properties.scale = NULL;
item->cloud_properties.value_type = value_type_int;
item->interface_type = EZLOPI_DEVICE_INTERFACE_PWM;
item->interface.pwm.channel = 0;
item->interface.pwm.value = 0;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
}
-static void __prepare_SK6812_RGB_dimmer_up_item(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_SK6812_RGB_dimmer_up_item(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
@@ -302,13 +317,13 @@ static void __prepare_SK6812_RGB_dimmer_up_item(l_ezlopi_item_t *item, cJSON *cj
item->cloud_properties.value_type = value_type_int;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
}
-static void __prepare_SK6812_RGB_dimmer_down_item(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_SK6812_RGB_dimmer_down_item(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
@@ -319,13 +334,13 @@ static void __prepare_SK6812_RGB_dimmer_down_item(l_ezlopi_item_t *item, cJSON *
item->cloud_properties.value_type = value_type_int;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
}
-static void __prepare_SK6812_RGB_dimmer_stop_item(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_SK6812_RGB_dimmer_stop_item(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
@@ -336,19 +351,19 @@ static void __prepare_SK6812_RGB_dimmer_stop_item(l_ezlopi_item_t *item, cJSON *
item->cloud_properties.value_type = value_type_int;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
}
-static void __prepare_SK6812_LED_onoff_switch_item(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_SK6812_LED_onoff_switch_item(l_ezlopi_item_t* item, cJSON* cj_device)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.item_name = ezlopi_item_name_switch,
- item->cloud_properties.show = true;
+ item->cloud_properties.show = true;
item->cloud_properties.scale = NULL;
item->cloud_properties.value_type = value_type_bool;
item->interface_type = EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT;
@@ -362,19 +377,19 @@ static void __prepare_SK6812_LED_onoff_switch_item(l_ezlopi_item_t *item, cJSON
item->interface.gpio.gpio_in.enable = false;
}
-static int __prepare(void *arg)
+static int __prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg && prep_arg->cjson_device)
{
- l_ezlopi_device_t *device = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t* device = ezlopi_device_add_device(prep_arg->cjson_device);
if (device)
{
__prepare_device_properties(device, prep_arg->cjson_device);
- s_dimmer_args_t *dimmer_args = malloc(sizeof(s_dimmer_args_t));
+ s_dimmer_args_t* dimmer_args = malloc(sizeof(s_dimmer_args_t));
if (dimmer_args)
{
memset(dimmer_args, 0, sizeof(s_dimmer_args_t));
diff --git a/ezlopi-sensors-devices/device-0022-PWM-dimmable-lamp/device_0022_PWM_dimmable_lamp.c b/ezlopi-sensors-devices/device-0022-PWM-dimmable-lamp/device_0022_PWM_dimmable_lamp.c
index c114528ab..be09161a0 100644
--- a/ezlopi-sensors-devices/device-0022-PWM-dimmable-lamp/device_0022_PWM_dimmable_lamp.c
+++ b/ezlopi-sensors-devices/device-0022-PWM-dimmable-lamp/device_0022_PWM_dimmable_lamp.c
@@ -119,11 +119,11 @@ static int __list_cjson_value(l_ezlopi_item_t *item, void *arg)
if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
{
int dimmable_value_percentage = (int)floor(((dimmable_bulb_arg->current_brightness_value * 100.0) / 4095.0));
- cJSON_AddNumberToObject(param, "value", dimmable_value_percentage);
+ cJSON_AddNumberToObject(param, ezlopi_value_str, dimmable_value_percentage);
char *formatted_val = ezlopi_valueformatter_int(dimmable_value_percentage);
if (formatted_val)
{
- cJSON_AddStringToObject(param, "valueFormatted", formatted_val);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
cJSON_AddNumberToObject(param, "minValue", 0);
@@ -131,39 +131,39 @@ static int __list_cjson_value(l_ezlopi_item_t *item, void *arg)
}
else if (ezlopi_item_name_dimmer_up == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(param, "value", 0);
+ cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
- cJSON_AddStringToObject(param, "valueFormatted", formatted_val);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
}
else if (ezlopi_item_name_dimmer_down == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(param, "value", 0);
+ cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
- cJSON_AddStringToObject(param, "valueFormatted", formatted_val);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
}
else if (ezlopi_item_name_dimmer_stop == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(param, "value", 0);
+ cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
- cJSON_AddStringToObject(param, "valueFormatted", formatted_val);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
}
else if (ezlopi_item_name_switch == item->cloud_properties.item_name)
{
bool switch_state = (0 == dimmable_bulb_arg->current_brightness_value) ? false : true;
- cJSON_AddBoolToObject(param, "value", switch_state);
- cJSON_AddStringToObject(param, "valueFormatted", ezlopi_valueformatter_bool(switch_state));
+ cJSON_AddBoolToObject(param, ezlopi_value_str, switch_state);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(switch_state));
}
}
@@ -188,31 +188,31 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
}
else if (ezlopi_item_name_dimmer_up == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(param, "value", 0);
+ cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
- cJSON_AddStringToObject(param, "valueFormatted", formatted_val);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
}
else if (ezlopi_item_name_dimmer_down == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(param, "value", 0);
+ cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
- cJSON_AddStringToObject(param, "valueFormatted", formatted_val);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
}
else if (ezlopi_item_name_dimmer_stop == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(param, "value", 0);
+ cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
- cJSON_AddStringToObject(param, "valueFormatted", formatted_val);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
}
@@ -232,27 +232,46 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- s_dimmable_bulb_properties_t *dimmable_bulb_arg = (s_dimmable_bulb_properties_t *)item->user_arg;
- if ((NULL != dimmable_bulb_arg) && (0 == dimmable_bulb_arg->dimmable_bulb_initialized))
+ if (GPIO_IS_VALID_GPIO(item->interface.pwm.gpio_num))
{
- s_ezlopi_channel_speed_t *ezlopi_dimmable_channel_speed = ezlopi_pwm_init(item->interface.pwm.gpio_num, item->interface.pwm.pwm_resln, item->interface.pwm.freq_hz, item->interface.pwm.duty_cycle);
- item->interface.pwm.channel = ezlopi_dimmable_channel_speed->channel;
- TRACE_I("Channel is %d", item->interface.pwm.channel);
- item->interface.pwm.speed_mode = ezlopi_dimmable_channel_speed->speed_mode;
- dimmable_bulb_arg->current_brightness_value = item->interface.pwm.duty_cycle;
- dimmable_bulb_arg->previous_brightness_value = item->interface.pwm.duty_cycle;
- dimmable_bulb_arg->dimmable_bulb_initialized = true;
- ezlopi_pwm_change_duty(item->interface.pwm.channel, item->interface.pwm.speed_mode, item->interface.pwm.duty_cycle);
- ret = 1;
+ s_dimmable_bulb_properties_t *dimmable_bulb_arg = (s_dimmable_bulb_properties_t *)item->user_arg;
+ if (dimmable_bulb_arg)
+ {
+ if (0 == dimmable_bulb_arg->dimmable_bulb_initialized)
+ {
+ s_ezlopi_channel_speed_t *ezlopi_dimmable_channel_speed = ezlopi_pwm_init(item->interface.pwm.gpio_num, item->interface.pwm.pwm_resln,
+ item->interface.pwm.freq_hz, item->interface.pwm.duty_cycle);
+ if (ezlopi_dimmable_channel_speed)
+ {
+ item->interface.pwm.channel = ezlopi_dimmable_channel_speed->channel;
+ TRACE_I("Channel is %d", item->interface.pwm.channel);
+ item->interface.pwm.speed_mode = ezlopi_dimmable_channel_speed->speed_mode;
+ dimmable_bulb_arg->current_brightness_value = item->interface.pwm.duty_cycle;
+ dimmable_bulb_arg->previous_brightness_value = item->interface.pwm.duty_cycle;
+ dimmable_bulb_arg->dimmable_bulb_initialized = true;
+ ezlopi_pwm_change_duty(item->interface.pwm.channel, item->interface.pwm.speed_mode, item->interface.pwm.duty_cycle);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
+ }
+ else
+ {
+ ret = -1;
+ }
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -283,7 +302,7 @@ static void __prepare_dimmer_item_properties(l_ezlopi_item_t *item, cJSON *cj_de
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
@@ -300,7 +319,7 @@ static void __prepare_dimmer_up_item_properties(l_ezlopi_item_t *item, cJSON *cj
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
@@ -317,7 +336,7 @@ static void __prepare_dimmer_down_item_properties(l_ezlopi_item_t *item, cJSON *
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
@@ -334,7 +353,7 @@ static void __prepare_dimmer_stop_item_properties(l_ezlopi_item_t *item, cJSON *
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
item->interface.pwm.pwm_resln = 12;
@@ -351,7 +370,7 @@ static void __prepare_dimmer_switch_item_properties(l_ezlopi_item_t *item, cJSON
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_out.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_out.gpio_num);
item->interface.gpio.gpio_in.enable = false;
item->interface.gpio.gpio_out.enable = true;
item->interface.gpio.gpio_out.interrupt = false;
diff --git a/ezlopi-sensors-devices/device-0036-PWM-servo-MG996R/device_0036_PWM_servo_MG996R.c b/ezlopi-sensors-devices/device-0036-PWM-servo-MG996R/device_0036_PWM_servo_MG996R.c
index cebfcae67..2aa246e6b 100644
--- a/ezlopi-sensors-devices/device-0036-PWM-servo-MG996R/device_0036_PWM_servo_MG996R.c
+++ b/ezlopi-sensors-devices/device-0036-PWM-servo-MG996R/device_0036_PWM_servo_MG996R.c
@@ -69,7 +69,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device)
{
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.item_name = ezlopi_item_name_dimmer;
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
@@ -78,7 +78,7 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.value_type = value_type_int;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
- CJSON_GET_VALUE_INT(cj_device, "gpio", item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.pwm.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "duty_cycle", item->interface.pwm.duty_cycle);
CJSON_GET_VALUE_INT(cj_device, "freq_hz", item->interface.pwm.freq_hz);
#if CONFIG_IDF_TARGET_ESP32C3
@@ -121,23 +121,26 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- static s_ezlopi_channel_speed_t *servo_item = NULL;
if (GPIO_IS_VALID_GPIO(item->interface.pwm.gpio_num))
{
+ static s_ezlopi_channel_speed_t *servo_item = NULL;
servo_item = ezlopi_pwm_init(item->interface.pwm.gpio_num, item->interface.pwm.pwm_resln,
item->interface.pwm.freq_hz, item->interface.pwm.duty_cycle);
- item->interface.pwm.channel = servo_item->channel;
- item->interface.pwm.speed_mode = servo_item->speed_mode;
- ret = 1;
+ if (servo_item)
+ {
+ item->interface.pwm.channel = servo_item->channel;
+ item->interface.pwm.speed_mode = servo_item->speed_mode;
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -146,21 +149,24 @@ static int __init(l_ezlopi_item_t *item)
static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON *cj_result = (cJSON *)arg;
- if (cj_result && item)
+ if (item && arg)
{
- int value = 0;
- CJSON_GET_VALUE_INT(cj_result, "value", value);
+ cJSON *cj_result = (cJSON *)arg;
+ if (cj_result && item)
+ {
+ int value = 0;
+ CJSON_GET_VALUE_INT(cj_result, "value", value);
- TRACE_S("gpio_num: %d", item->interface.pwm.gpio_num);
- TRACE_S("item_id: %d", item->cloud_properties.item_id);
- TRACE_S("cur value: %d", value);
+ TRACE_I("gpio_num: %d", item->interface.pwm.gpio_num);
+ TRACE_I("item_id: %d", item->cloud_properties.item_id);
+ TRACE_I("cur value: %d", value);
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.pwm.gpio_num))
- {
- int target_value = (int)(((value * 17) / 100) + 13);
- TRACE_S("target value: %d", target_value);
- ezlopi_pwm_change_duty(item->interface.pwm.channel, item->interface.pwm.speed_mode, target_value);
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.pwm.gpio_num))
+ {
+ int target_value = (int)(((value * 17) / 100) + 13);
+ TRACE_I("target value: %d", target_value);
+ ezlopi_pwm_change_duty(item->interface.pwm.channel, item->interface.pwm.speed_mode, target_value);
+ }
}
}
return ret;
@@ -169,31 +175,37 @@ static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
-
- cJSON *cj_result = (cJSON *)arg;
- if (cj_result)
+ if (item && arg)
{
- uint32_t duty = ezlopi_pwm_get_duty(item->interface.pwm.channel, item->interface.pwm.speed_mode);
- TRACE_S("raw duty value: %d", duty);
-
- if (duty < 13)
+ cJSON *cj_result = (cJSON *)arg;
+ if (cj_result)
{
- duty = 13;
- TRACE_W("new _ raw duty value: %d", duty);
- }
- int target_duty = (int)(((duty - 13) * 100) / 17);
- TRACE_S("target duty value: %d", target_duty);
+ uint32_t duty = ezlopi_pwm_get_duty(item->interface.pwm.channel, item->interface.pwm.speed_mode);
+ TRACE_I("raw duty value: %d", duty);
- if (target_duty > 100)
- {
- target_duty = 100;
- TRACE_W("new _ target duty value: %d", duty);
- }
+ if (duty < 13)
+ {
+ duty = 13;
+ TRACE_W("new _ raw duty value: %d", duty);
+ }
+ int target_duty = (int)(((duty - 13) * 100) / 17);
+ TRACE_I("target duty value: %d", target_duty);
- char *formatted_val = ezlopi_valueformatter_int(target_duty);
- cJSON_AddStringToObject(cj_result, "valueFormatted", formatted_val);
- cJSON_AddNumberToObject(cj_result, "value", target_duty);
- ret = 1;
+ if (target_duty > 100)
+ {
+ target_duty = 100;
+ TRACE_W("new _ target duty value: %d", duty);
+ }
+
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, target_duty);
+ char *formatted_val = ezlopi_valueformatter_int(target_duty);
+ if (formatted_val)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, formatted_val);
+ free(formatted_val);
+ }
+ ret = 1;
+ }
}
return ret;
@@ -307,7 +319,7 @@ static s_ezlopi_device_properties_t *ezlopi_servo_motor_MG_996R_prepare(cJSON *c
ezlopi_servo_motor_MG_996R_properties->ezlopi_cloud.room_id = ezlopi_cloud_generate_room_id();
ezlopi_servo_motor_MG_996R_properties->ezlopi_cloud.item_id = ezlopi_cloud_generate_item_id();
- // CJSON_GET_VALUE_INT(cjson_device, ezlopi_dev_name_str, ezlopi_servo_motor_MG_996R_properties->interface.pwm.gpio_num);
+ // CJSON_GET_VALUE_INT(cjson_device, ezlopi_gpio_str, ezlopi_servo_motor_MG_996R_properties->interface.pwm.gpio_num);
// CJSON_GET_VALUE_INT(cjson_device, "duty_cycle", ezlopi_servo_motor_MG_996R_properties->interface.pwm.duty_cycle);
// CJSON_GET_VALUE_INT(cjson_device, "freq_hz", ezlopi_servo_motor_MG_996R_properties->interface.pwm.freq_hz);
// CJSON_GET_VALUE_INT(cjson_device, "pwm_resln", ezlopi_servo_motor_MG_996R_properties->interface.pwm.pwm_resln);
@@ -349,10 +361,10 @@ static int ezlopi_servo_motor_MG_996R_set_value(s_ezlopi_device_properties_t *pr
int value = 0;
CJSON_GET_VALUE_INT(cjson_params, ezlopi_value_str, value);
- TRACE_S("item_name: %s", properties->ezlopi_cloud.item_name);
- TRACE_S("gpio_num: %d", properties->interface.pwm.gpio_num);
- TRACE_S("item_id: %d", properties->ezlopi_cloud.item_id);
- TRACE_S("cur value: %d", value);
+ TRACE_I("item_name: %s", properties->ezlopi_cloud.item_name);
+ TRACE_I("gpio_num: %d", properties->interface.pwm.gpio_num);
+ TRACE_I("item_id: %d", properties->ezlopi_cloud.item_id);
+ TRACE_I("cur value: %d", value);
if (GPIO_IS_VALID_OUTPUT_GPIO(properties->interface.pwm.gpio_num))
{
diff --git a/ezlopi-sensors-devices/device-0038-other-RGB/device_0038_other_RGB.c b/ezlopi-sensors-devices/device-0038-other-RGB/device_0038_other_RGB.c
index 1ea5608be..7cfcf6d63 100644
--- a/ezlopi-sensors-devices/device-0038-other-RGB/device_0038_other_RGB.c
+++ b/ezlopi-sensors-devices/device-0038-other-RGB/device_0038_other_RGB.c
@@ -16,9 +16,9 @@
typedef struct s_rgb_args
{
bool RGB_LED_initialized;
- l_ezlopi_item_t *RGB_LED_item;
- l_ezlopi_item_t *RGB_LED_dimmer_item;
- l_ezlopi_item_t *RGB_LED_onoff_switch_item;
+ l_ezlopi_item_t* RGB_LED_item;
+ l_ezlopi_item_t* RGB_LED_dimmer_item;
+ l_ezlopi_item_t* RGB_LED_onoff_switch_item;
float brightness;
s_ezlopi_pwm_t red_struct;
@@ -27,12 +27,12 @@ typedef struct s_rgb_args
float previous_dim_factor;
} s_rgb_args_t;
-static int __prepare(void *arg);
-static int __init(l_ezlopi_item_t *item);
-static int __set_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
+static int __prepare(void* arg);
+static int __init(l_ezlopi_item_t* item);
+static int __set_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
-int device_0038_other_RGB(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int device_0038_other_RGB(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
@@ -68,155 +68,185 @@ int device_0038_other_RGB(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void
return ret;
}
-static int RGB_LED_change_color_value(s_rgb_args_t *rgb_args)
+static int RGB_LED_change_color_value(s_rgb_args_t* rgb_args)
{
int ret = 0;
-
- TRACE_I("Brightness value is %d, %d, %d", (uint8_t)(rgb_args->red_struct.value * rgb_args->brightness), (uint8_t)(rgb_args->green_struct.value * rgb_args->brightness),
+ if (rgb_args)
+ {
+ TRACE_D("Brightness value is %d, %d, %d", (uint8_t)(rgb_args->red_struct.value * rgb_args->brightness), (uint8_t)(rgb_args->green_struct.value * rgb_args->brightness),
(uint8_t)(rgb_args->blue_struct.value * rgb_args->brightness));
- ezlopi_pwm_change_duty(rgb_args->red_struct.channel, rgb_args->red_struct.speed_mode, (uint8_t)(rgb_args->red_struct.value * rgb_args->brightness));
- ezlopi_pwm_change_duty(rgb_args->green_struct.channel, rgb_args->green_struct.speed_mode, (uint8_t)(rgb_args->green_struct.value * rgb_args->brightness));
- ezlopi_pwm_change_duty(rgb_args->blue_struct.channel, rgb_args->blue_struct.speed_mode, (uint8_t)(rgb_args->blue_struct.value * rgb_args->brightness));
-
+ ezlopi_pwm_change_duty(rgb_args->red_struct.channel, rgb_args->red_struct.speed_mode, (uint8_t)(rgb_args->red_struct.value * rgb_args->brightness));
+ ezlopi_pwm_change_duty(rgb_args->green_struct.channel, rgb_args->green_struct.speed_mode, (uint8_t)(rgb_args->green_struct.value * rgb_args->brightness));
+ ezlopi_pwm_change_duty(rgb_args->blue_struct.channel, rgb_args->blue_struct.speed_mode, (uint8_t)(rgb_args->blue_struct.value * rgb_args->brightness));
+ }
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
-
- cJSON *cjson_params = (cJSON *)arg;
- s_rgb_args_t *rgb_args = (s_rgb_args_t *)item->user_arg;
-
- if ((NULL != cjson_params) && (NULL != rgb_args))
+ if (item && arg)
{
- if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
+ cJSON* cjson_params = (cJSON*)arg;
+ s_rgb_args_t* rgb_args = (s_rgb_args_t*)item->user_arg;
+
+ if ((NULL != cjson_params) && (NULL != rgb_args))
{
- cJSON *color_values = cJSON_AddObjectToObject(cjson_params, ezlopi_value_str);
- if (color_values)
+ if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(color_values, "red", rgb_args->red_struct.value);
- cJSON_AddNumberToObject(color_values, "green", rgb_args->green_struct.value);
- cJSON_AddNumberToObject(color_values, "blue", rgb_args->blue_struct.value);
- char *formatted_val = ezlopi_valueformatter_rgb(rgb_args->red_struct.value, rgb_args->green_struct.value, rgb_args->blue_struct.value);
- cJSON_AddStringToObject(cjson_params, ezlopi_valueFormatted_str, formatted_val);
- free(formatted_val);
+ cJSON* color_values = cJSON_AddObjectToObject(cjson_params, ezlopi_value_str);
+ if (color_values)
+ {
+ cJSON_AddNumberToObject(color_values, "red", rgb_args->red_struct.value);
+ cJSON_AddNumberToObject(color_values, "green", rgb_args->green_struct.value);
+ cJSON_AddNumberToObject(color_values, "blue", rgb_args->blue_struct.value);
+ char* formatted_val = ezlopi_valueformatter_rgb(rgb_args->red_struct.value, rgb_args->green_struct.value, rgb_args->blue_struct.value);
+ if (formatted_val)
+ {
+ cJSON_AddStringToObject(cjson_params, ezlopi_valueFormatted_str, formatted_val);
+ free(formatted_val);
+ }
+ }
+ }
+ if (ezlopi_item_name_switch == item->cloud_properties.item_name)
+ {
+ int state = ((0 == rgb_args->brightness) ? 0 : 1);
+ cJSON_AddBoolToObject(cjson_params, ezlopi_value_str, state);
+ cJSON_AddStringToObject(cjson_params, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(state ? true : false));
+ }
+ if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
+ {
+ int dim_percentage = (int)(rgb_args->brightness * 100);
+ cJSON_AddNumberToObject(cjson_params, ezlopi_value_str, dim_percentage);
+ char* formatted_val = ezlopi_valueformatter_int(dim_percentage);
+ if (formatted_val)
+ {
+ cJSON_AddStringToObject(cjson_params, ezlopi_valueFormatted_str, formatted_val);
+ free(formatted_val);
+ }
}
- }
- if (ezlopi_item_name_switch == item->cloud_properties.item_name)
- {
- int state = ((0 == rgb_args->brightness) ? 0 : 1);
- cJSON_AddBoolToObject(cjson_params, ezlopi_value_str, state);
- cJSON_AddStringToObject(cjson_params, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(state ? true : false));
- }
- if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
- {
- int dim_percentage = (int)(rgb_args->brightness * 100);
- cJSON_AddNumberToObject(cjson_params, ezlopi_value_str, dim_percentage);
- char *formatted_val = ezlopi_valueformatter_int(dim_percentage);
- cJSON_AddStringToObject(cjson_params, ezlopi_valueFormatted_str, formatted_val);
- free(formatted_val);
}
}
return ret;
}
-static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __set_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- cJSON *cjson_params = (cJSON *)arg;
- s_rgb_args_t *rgb_args = (s_rgb_args_t *)item->user_arg;
-
- if ((NULL != cjson_params) && (NULL != rgb_args))
+ if (item && arg)
{
- if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
+ cJSON* cjson_params = (cJSON*)arg;
+ s_rgb_args_t* rgb_args = (s_rgb_args_t*)item->user_arg;
+ if ((NULL != cjson_params) && (NULL != rgb_args))
{
- cJSON *cjson_params_rgb_values = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
+ if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
+ {
+ cJSON* cjson_params_rgb_values = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
- CJSON_TRACE("cjson_params_rgb_values", cjson_params_rgb_values);
+ CJSON_TRACE("cjson_params_rgb_values", cjson_params_rgb_values);
- CJSON_GET_VALUE_INT(cjson_params_rgb_values, "red", rgb_args->red_struct.value);
- CJSON_GET_VALUE_INT(cjson_params_rgb_values, "green", rgb_args->green_struct.value);
- CJSON_GET_VALUE_INT(cjson_params_rgb_values, "blue", rgb_args->blue_struct.value);
+ CJSON_GET_VALUE_INT(cjson_params_rgb_values, "red", rgb_args->red_struct.value);
+ CJSON_GET_VALUE_INT(cjson_params_rgb_values, "green", rgb_args->green_struct.value);
+ CJSON_GET_VALUE_INT(cjson_params_rgb_values, "blue", rgb_args->blue_struct.value);
- RGB_LED_change_color_value(rgb_args);
- }
- if (ezlopi_item_name_switch == item->cloud_properties.item_name)
- {
- int led_state = 0;
- CJSON_GET_VALUE_INT(cjson_params, ezlopi_value_str, led_state);
- rgb_args->previous_dim_factor = ((0 == led_state) ? rgb_args->brightness : rgb_args->previous_dim_factor);
- rgb_args->brightness = ((0 == led_state) ? 0.0 : ((0 == rgb_args->previous_dim_factor) ? 1.0 : rgb_args->previous_dim_factor));
- TRACE_I("Brightness value is %d, %d, %d", (uint8_t)(rgb_args->red_struct.value * rgb_args->brightness), (uint8_t)(rgb_args->green_struct.value * rgb_args->brightness),
+ RGB_LED_change_color_value(rgb_args);
+ }
+ if (ezlopi_item_name_switch == item->cloud_properties.item_name)
+ {
+ int led_state = 0;
+ CJSON_GET_VALUE_INT(cjson_params, ezlopi_value_str, led_state);
+ rgb_args->previous_dim_factor = ((0 == led_state) ? rgb_args->brightness : rgb_args->previous_dim_factor);
+ rgb_args->brightness = ((0 == led_state) ? 0.0 : ((0 == rgb_args->previous_dim_factor) ? 1.0 : rgb_args->previous_dim_factor));
+ TRACE_D("Brightness value is %d, %d, %d", (uint8_t)(rgb_args->red_struct.value * rgb_args->brightness), (uint8_t)(rgb_args->green_struct.value * rgb_args->brightness),
(uint8_t)(rgb_args->blue_struct.value * rgb_args->brightness));
- RGB_LED_change_color_value(rgb_args);
- ezlopi_device_value_updated_from_device_v3(rgb_args->RGB_LED_dimmer_item);
- }
- if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
- {
- int dim_percent = 0;
- CJSON_GET_VALUE_INT(cjson_params, ezlopi_value_str, dim_percent);
- float dim_brightness_factor = dim_percent / 100.0;
- TRACE_I("dim_percent %d, dim_brightness_factor is %f", dim_percent, dim_brightness_factor);
- rgb_args->brightness = dim_brightness_factor;
- RGB_LED_change_color_value(rgb_args);
- ezlopi_device_value_updated_from_device_v3(rgb_args->RGB_LED_onoff_switch_item);
+ RGB_LED_change_color_value(rgb_args);
+ ezlopi_device_value_updated_from_device_v3(rgb_args->RGB_LED_dimmer_item);
+ }
+ if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
+ {
+ int dim_percent = 0;
+ CJSON_GET_VALUE_INT(cjson_params, ezlopi_value_str, dim_percent);
+ float dim_brightness_factor = dim_percent / 100.0;
+ TRACE_D("dim_percent %d, dim_brightness_factor is %f", dim_percent, dim_brightness_factor);
+ rgb_args->brightness = dim_brightness_factor;
+ RGB_LED_change_color_value(rgb_args);
+ ezlopi_device_value_updated_from_device_v3(rgb_args->RGB_LED_onoff_switch_item);
+ }
}
}
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- s_rgb_args_t *rgb_args = (s_rgb_args_t *)item->user_arg;
-
- if ((NULL != rgb_args) && (!rgb_args->RGB_LED_initialized))
+ s_rgb_args_t* rgb_args = (s_rgb_args_t*)item->user_arg;
+ if (rgb_args)
{
- s_ezlopi_channel_speed_t *RGB_LED_red_channel_speed = ezlopi_pwm_init(rgb_args->red_struct.gpio_num, rgb_args->red_struct.pwm_resln, rgb_args->red_struct.freq_hz, rgb_args->red_struct.duty_cycle);
- s_ezlopi_channel_speed_t *RGB_LED_green_channel_speed = ezlopi_pwm_init(rgb_args->green_struct.gpio_num, rgb_args->green_struct.pwm_resln, rgb_args->green_struct.freq_hz, rgb_args->green_struct.duty_cycle);
- s_ezlopi_channel_speed_t *RGB_LED_blue_channel_speed = ezlopi_pwm_init(rgb_args->blue_struct.gpio_num, rgb_args->blue_struct.pwm_resln, rgb_args->blue_struct.freq_hz, rgb_args->blue_struct.duty_cycle);
-
- rgb_args->red_struct.channel = RGB_LED_red_channel_speed->channel;
- rgb_args->red_struct.speed_mode = RGB_LED_red_channel_speed->speed_mode;
- TRACE_I("red channel is %d", rgb_args->red_struct.channel);
-
- rgb_args->green_struct.channel = RGB_LED_green_channel_speed->channel;
- rgb_args->green_struct.speed_mode = RGB_LED_green_channel_speed->speed_mode;
- TRACE_I("green channel is %d", rgb_args->green_struct.channel);
-
- rgb_args->blue_struct.channel = RGB_LED_blue_channel_speed->channel;
- rgb_args->blue_struct.speed_mode = RGB_LED_blue_channel_speed->speed_mode;
- TRACE_I("blue channel is %d", rgb_args->blue_struct.channel);
-
- free(RGB_LED_red_channel_speed);
- free(RGB_LED_green_channel_speed);
- free(RGB_LED_blue_channel_speed);
-
- RGB_LED_change_color_value(rgb_args);
-
- rgb_args->RGB_LED_initialized = true;
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(rgb_args->red_struct.gpio_num) &&
+ GPIO_IS_VALID_GPIO(rgb_args->green_struct.gpio_num) &&
+ GPIO_IS_VALID_GPIO(rgb_args->blue_struct.gpio_num))
+ {
+ if (false == rgb_args->RGB_LED_initialized)
+ {
+ s_ezlopi_channel_speed_t* RGB_LED_red_channel_speed = ezlopi_pwm_init(rgb_args->red_struct.gpio_num, rgb_args->red_struct.pwm_resln, rgb_args->red_struct.freq_hz, rgb_args->red_struct.duty_cycle);
+ if (RGB_LED_red_channel_speed)
+ {
+ rgb_args->red_struct.channel = RGB_LED_red_channel_speed->channel;
+ rgb_args->red_struct.speed_mode = RGB_LED_red_channel_speed->speed_mode;
+ TRACE_D("red channel is %d", rgb_args->red_struct.channel);
+ free(RGB_LED_red_channel_speed);
+ }
+
+ s_ezlopi_channel_speed_t* RGB_LED_green_channel_speed = ezlopi_pwm_init(rgb_args->green_struct.gpio_num, rgb_args->green_struct.pwm_resln, rgb_args->green_struct.freq_hz, rgb_args->green_struct.duty_cycle);
+ if (RGB_LED_green_channel_speed)
+ {
+ rgb_args->green_struct.channel = RGB_LED_green_channel_speed->channel;
+ rgb_args->green_struct.speed_mode = RGB_LED_green_channel_speed->speed_mode;
+ TRACE_D("green channel is %d", rgb_args->green_struct.channel);
+ free(RGB_LED_green_channel_speed);
+ }
+
+ s_ezlopi_channel_speed_t* RGB_LED_blue_channel_speed = ezlopi_pwm_init(rgb_args->blue_struct.gpio_num, rgb_args->blue_struct.pwm_resln, rgb_args->blue_struct.freq_hz, rgb_args->blue_struct.duty_cycle);
+ if (RGB_LED_blue_channel_speed)
+ {
+ rgb_args->blue_struct.channel = RGB_LED_blue_channel_speed->channel;
+ rgb_args->blue_struct.speed_mode = RGB_LED_blue_channel_speed->speed_mode;
+ TRACE_D("blue channel is %d", rgb_args->blue_struct.channel);
+ free(RGB_LED_blue_channel_speed);
+ }
+
+ RGB_LED_change_color_value(rgb_args);
+
+ rgb_args->RGB_LED_initialized = true;
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -230,7 +260,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_RGB_LED_user_args(s_rgb_args_t *rgb_args, cJSON *cj_device)
+static void __prepare_RGB_LED_user_args(s_rgb_args_t* rgb_args, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, rgb_args->red_struct.gpio_num);
CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio2_str, rgb_args->green_struct.gpio_num);
@@ -254,13 +284,13 @@ static void __prepare_RGB_LED_user_args(s_rgb_args_t *rgb_args, cJSON *cj_device
rgb_args->brightness = 0.0;
}
-static void __prepare_RGB_LED_item(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static void __prepare_RGB_LED_item(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.item_name = ezlopi_item_name_rgbcolor,
- item->cloud_properties.show = true;
+ item->cloud_properties.show = true;
item->cloud_properties.scale = NULL;
item->cloud_properties.value_type = value_type_rgb;
item->interface_type = EZLOPI_DEVICE_INTERFACE_PWM;
@@ -273,13 +303,13 @@ static void __prepare_RGB_LED_item(l_ezlopi_item_t *item, cJSON *cj_device, void
item->user_arg = user_arg;
}
-static void __prepare_RGB_LED_onoff_switch_item(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static void __prepare_RGB_LED_onoff_switch_item(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.item_name = ezlopi_item_name_switch,
- item->cloud_properties.show = true;
+ item->cloud_properties.show = true;
item->cloud_properties.scale = NULL;
item->cloud_properties.value_type = value_type_bool;
item->interface_type = EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT;
@@ -294,13 +324,13 @@ static void __prepare_RGB_LED_onoff_switch_item(l_ezlopi_item_t *item, cJSON *cj
item->user_arg = user_arg;
}
-static void __prepare_RGB_LED_dimmer_item(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static void __prepare_RGB_LED_dimmer_item(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.item_name = ezlopi_item_name_dimmer,
- item->cloud_properties.show = true;
+ item->cloud_properties.show = true;
item->cloud_properties.scale = NULL;
item->cloud_properties.value_type = value_type_int;
item->interface_type = EZLOPI_DEVICE_INTERFACE_PWM;
@@ -313,17 +343,17 @@ static void __prepare_RGB_LED_dimmer_item(l_ezlopi_item_t *item, cJSON *cj_devic
item->user_arg = user_arg;
}
-static int __prepare(void *arg)
+static int __prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg && prep_arg->cjson_device)
{
- l_ezlopi_device_t *RGB_device = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t* RGB_device = ezlopi_device_add_device(prep_arg->cjson_device);
if (RGB_device)
{
- s_rgb_args_t *rgb_args = malloc(sizeof(s_rgb_args_t));
+ s_rgb_args_t* rgb_args = malloc(sizeof(s_rgb_args_t));
if (rgb_args)
{
memset(rgb_args, 0, sizeof(s_rgb_args_t));
diff --git a/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/mpu6050.c b/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/mpu6050.c
index 00ece77d4..944b1641f 100644
--- a/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/mpu6050.c
+++ b/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/mpu6050.c
@@ -171,49 +171,52 @@ void __mpu6050_get_data(l_ezlopi_item_t *item)
uint8_t address_val = 0;
s_mpu6050_data_t *user_data = (s_mpu6050_data_t *)item->user_arg;
- if ((err = mpu6050_check_data_ready_INTR(item, &Check_Register)) == MPU6050_ERR_OK)
+ if (user_data)
{
- if (Check_Register & DATA_RDY_INT_FLAG)
+ if ((err = mpu6050_check_data_ready_INTR(item, &Check_Register)) == MPU6050_ERR_OK)
{
- address_val = (ACCEL_X_H);
- ezlopi_i2c_master_write_to_device(&item->interface.i2c_master, &address_val, 1);
- ezlopi_i2c_master_read_from_device(&item->interface.i2c_master, (tmp_buf), MPU6050_REG_COUNT_LEN); //(tmp_buf+i), 1);
+ if (Check_Register & DATA_RDY_INT_FLAG)
+ {
+ address_val = (ACCEL_X_H);
+ ezlopi_i2c_master_write_to_device(&item->interface.i2c_master, &address_val, 1);
+ ezlopi_i2c_master_read_from_device(&item->interface.i2c_master, (tmp_buf), MPU6050_REG_COUNT_LEN); //(tmp_buf+i), 1);
+ }
+ // user_data->extract_counts++;
+ // TRACE_I("Total Extracted : [%d]", user_data->extract_counts);
}
- // user_data->extract_counts++;
- // TRACE_S("Total Extracted : [%d]", user_data->extract_counts);
- }
- else
- {
- TRACE_E("Data not ready ... Error type:- %d ", err);
- for (uint8_t try = 10; ((try > 0) && !(Check_Register & DATA_RDY_INT_FLAG)); try--)
+ else
{
- if (MPU6050_ERR_OK == mpu6050_check_data_ready_INTR(item, &Check_Register))
+ TRACE_E("Data not ready ... Error type:- %d ", err);
+ for (uint8_t try = 10; ((try > 0) && !(Check_Register & DATA_RDY_INT_FLAG)); try--)
{
- TRACE_E(" Check Register ... 0x3AH : {%#x}", Check_Register);
- if (Check_Register & DATA_RDY_INT_FLAG)
+ if (MPU6050_ERR_OK == mpu6050_check_data_ready_INTR(item, &Check_Register))
{
- break;
+ TRACE_E(" Check Register ... 0x3AH : {%#x}", Check_Register);
+ if (Check_Register & DATA_RDY_INT_FLAG)
+ {
+ break;
+ }
}
}
}
- }
- // Configure data structure // total 14 bytes
- RAW_DATA.raw_ax = (int16_t)(tmp_buf[0] << 8 | tmp_buf[1]); // acc_x = 59(0x3B) [msb] & 60(0x3C) [lsb]
- RAW_DATA.raw_ay = (int16_t)(tmp_buf[2] << 8 | tmp_buf[3]); // acc_y = 61 & 62
- RAW_DATA.raw_az = (int16_t)(tmp_buf[4] << 8 | tmp_buf[5]); // acc_z = 63 & 64
- RAW_DATA.raw_t = (int16_t)(tmp_buf[6] << 8 | tmp_buf[7]); // tp = 65 & 66
- RAW_DATA.raw_gx = (int16_t)(tmp_buf[8] << 8 | tmp_buf[9]); // gx = 67 & 68
- RAW_DATA.raw_gy = (int16_t)(tmp_buf[10] << 8 | tmp_buf[11]); // gy = 69 & 70
- RAW_DATA.raw_gz = (int16_t)(tmp_buf[12] << 8 | tmp_buf[13]); // gz = 71 & 72
+ // Configure data structure // total 14 bytes
+ RAW_DATA.raw_ax = (int16_t)(tmp_buf[0] << 8 | tmp_buf[1]); // acc_x = 59(0x3B) [msb] & 60(0x3C) [lsb]
+ RAW_DATA.raw_ay = (int16_t)(tmp_buf[2] << 8 | tmp_buf[3]); // acc_y = 61 & 62
+ RAW_DATA.raw_az = (int16_t)(tmp_buf[4] << 8 | tmp_buf[5]); // acc_z = 63 & 64
+ RAW_DATA.raw_t = (int16_t)(tmp_buf[6] << 8 | tmp_buf[7]); // tp = 65 & 66
+ RAW_DATA.raw_gx = (int16_t)(tmp_buf[8] << 8 | tmp_buf[9]); // gx = 67 & 68
+ RAW_DATA.raw_gy = (int16_t)(tmp_buf[10] << 8 | tmp_buf[11]); // gy = 69 & 70
+ RAW_DATA.raw_gz = (int16_t)(tmp_buf[12] << 8 | tmp_buf[13]); // gz = 71 & 72
- user_data->ax = (RAW_DATA.raw_ax / acc_mpu6050_calib_val) * MPU6050_STANDARD_G_TO_ACCEL_CONVERSION_VALUE; // in m/s^2
- user_data->ay = (RAW_DATA.raw_ay / acc_mpu6050_calib_val) * MPU6050_STANDARD_G_TO_ACCEL_CONVERSION_VALUE; // in m/s^2
- user_data->az = (RAW_DATA.raw_az / acc_mpu6050_calib_val) * MPU6050_STANDARD_G_TO_ACCEL_CONVERSION_VALUE; // in m/s^2
- user_data->gx = ((RAW_DATA.raw_gx - user_data->gyro_x_offset) / gyro_mpu6050_calib_val) / 6.0f; // -> revolutions per minute = degrees per second ÷ 6
- user_data->gy = ((RAW_DATA.raw_gy - user_data->gyro_y_offset) / gyro_mpu6050_calib_val) / 6.0f; // -> revolutions per minute = degrees per second ÷ 6
- user_data->gz = ((RAW_DATA.raw_gz - user_data->gyro_z_offset) / gyro_mpu6050_calib_val) / 6.0f; // -> revolutions per minute = degrees per second ÷ 6
- user_data->tmp = ((RAW_DATA.raw_t / 340) + 36.530f);
+ user_data->ax = (RAW_DATA.raw_ax / acc_mpu6050_calib_val) * MPU6050_STANDARD_G_TO_ACCEL_CONVERSION_VALUE; // in m/s^2
+ user_data->ay = (RAW_DATA.raw_ay / acc_mpu6050_calib_val) * MPU6050_STANDARD_G_TO_ACCEL_CONVERSION_VALUE; // in m/s^2
+ user_data->az = (RAW_DATA.raw_az / acc_mpu6050_calib_val) * MPU6050_STANDARD_G_TO_ACCEL_CONVERSION_VALUE; // in m/s^2
+ user_data->gx = ((RAW_DATA.raw_gx - user_data->gyro_x_offset) / gyro_mpu6050_calib_val) / 6.0f; // -> revolutions per minute = degrees per second ÷ 6
+ user_data->gy = ((RAW_DATA.raw_gy - user_data->gyro_y_offset) / gyro_mpu6050_calib_val) / 6.0f; // -> revolutions per minute = degrees per second ÷ 6
+ user_data->gz = ((RAW_DATA.raw_gz - user_data->gyro_z_offset) / gyro_mpu6050_calib_val) / 6.0f; // -> revolutions per minute = degrees per second ÷ 6
+ user_data->tmp = ((RAW_DATA.raw_t / 340) + 36.530f);
+ }
}
}
diff --git a/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/sensor_0005_I2C_MPU6050.c b/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/sensor_0005_I2C_MPU6050.c
index 6174ae6fb..74bad0a86 100644
--- a/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/sensor_0005_I2C_MPU6050.c
+++ b/ezlopi-sensors-devices/sensor-0005-I2C-MPU6050/sensor_0005_I2C_MPU6050.c
@@ -88,9 +88,9 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj
if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
{
item->interface.i2c_master.enable = true;
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
- CJSON_GET_VALUE_INT(cj_device, "gpio_sda", item->interface.i2c_master.sda);
- CJSON_GET_VALUE_INT(cj_device, "gpio_scl", item->interface.i2c_master.scl);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_sda_str, item->interface.i2c_master.sda);
+ CJSON_GET_VALUE_INT(cj_device,ezlopi_gpio_scl_str, item->interface.i2c_master.scl);
CJSON_GET_VALUE_INT(cj_device, "slave_addr", item->interface.i2c_master.address);
item->interface.i2c_master.clock_speed = 100000;
@@ -210,24 +210,31 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (true == item->interface.i2c_master.enable)
+ s_mpu6050_data_t *user_data = (s_mpu6050_data_t *)item->user_arg;
+ if (user_data)
{
- ezlopi_i2c_master_init(&item->interface.i2c_master);
- if (MPU6050_ERR_OK == __mpu6050_config_device(item))
+ if (item->interface.i2c_master.enable)
{
- TRACE_S("Configuration Complete.... ");
- xTaskCreate(__mpu6050_calibration_task, "MPU6050_Calibration_Task", 2048, item, 1, NULL);
+ ezlopi_i2c_master_init(&item->interface.i2c_master);
+ if (MPU6050_ERR_OK == __mpu6050_config_device(item))
+ {
+ TRACE_I("Configuration Complete.... ");
+ xTaskCreate(__mpu6050_calibration_task, "MPU6050_Calibration_Task", 2048, item, 1, NULL);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- ret = 1;
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -236,67 +243,94 @@ static int __init(l_ezlopi_item_t *item)
static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON *cj_result = (cJSON *)arg;
- if (cj_result && item)
+ if (item && arg)
{
- s_mpu6050_data_t *user_data = (s_mpu6050_data_t *)item->user_arg;
- if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
+ cJSON *cj_result = (cJSON *)arg;
+ if (cj_result)
{
- TRACE_S("Accel-x : %.2fm/s^2", user_data->ax);
- cJSON_AddNumberToObject(cj_result, "value", user_data->ax);
- char *valueFormatted = ezlopi_valueformatter_float(user_data->ax);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
- {
- TRACE_S("Accel-y : %.2fm/s^2", user_data->ay);
- cJSON_AddNumberToObject(cj_result, "value", user_data->ay);
- char *valueFormatted = ezlopi_valueformatter_float(user_data->ay);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
- {
- TRACE_S("Accel-z : %.2fm/s^2", user_data->az);
- cJSON_AddNumberToObject(cj_result, "value", user_data->az);
- char *valueFormatted = ezlopi_valueformatter_float(user_data->az);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_temp == item->cloud_properties.item_name)
- {
- TRACE_S("Temp : %.2f*C", user_data->tmp);
- cJSON_AddNumberToObject(cj_result, "value", user_data->tmp);
- char *valueFormatted = ezlopi_valueformatter_float(user_data->tmp);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_gyroscope_x_axis == item->cloud_properties.item_name)
- {
- TRACE_S("Gyro-x : %d rpm", (int)user_data->gx);
- cJSON_AddNumberToObject(cj_result, "value", ((int)user_data->gx));
- char *valueFormatted = ezlopi_valueformatter_int((int)user_data->gx);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_gyroscope_y_axis == item->cloud_properties.item_name)
- {
- TRACE_S("Gyro-y : %d rpm", (int)user_data->gy);
- cJSON_AddNumberToObject(cj_result, "value", ((int)user_data->gy));
- char *valueFormatted = ezlopi_valueformatter_int((int)user_data->gy);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_gyroscope_z_axis == item->cloud_properties.item_name)
- {
- TRACE_S("Gyro-z : %d rpm", (int)user_data->gz);
- cJSON_AddNumberToObject(cj_result, "value", ((int)user_data->gz));
- char *valueFormatted = ezlopi_valueformatter_int((int)user_data->gz);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
+ s_mpu6050_data_t *user_data = (s_mpu6050_data_t *)item->user_arg;
+ if (user_data)
+ {
+ if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
+ {
+ TRACE_I("Accel-x : %.2fm/s^2", user_data->ax);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->ax);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->ax);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
+ {
+ TRACE_I("Accel-y : %.2fm/s^2", user_data->ay);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->ay);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->ay);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
+ {
+ TRACE_I("Accel-z : %.2fm/s^2", user_data->az);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->az);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->az);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_temp == item->cloud_properties.item_name)
+ {
+ TRACE_I("Temp : %.2f*C", user_data->tmp);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->tmp);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->tmp);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_gyroscope_x_axis == item->cloud_properties.item_name)
+ {
+ TRACE_I("Gyro-x : %d rpm", (int)user_data->gx);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, ((int)user_data->gx));
+ char *valueFormatted = ezlopi_valueformatter_int((int)user_data->gx);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_gyroscope_y_axis == item->cloud_properties.item_name)
+ {
+ TRACE_I("Gyro-y : %d rpm", (int)user_data->gy);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, ((int)user_data->gy));
+ char *valueFormatted = ezlopi_valueformatter_int((int)user_data->gy);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_gyroscope_z_axis == item->cloud_properties.item_name)
+ {
+ TRACE_I("Gyro-z : %d rpm", (int)user_data->gz);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, ((int)user_data->gz));
+ char *valueFormatted = ezlopi_valueformatter_int((int)user_data->gz);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ ret = 1;
+ }
}
- ret = 1;
}
return ret;
}
@@ -308,7 +342,7 @@ static int __notify(l_ezlopi_item_t *item)
if (item)
{
s_mpu6050_data_t *user_data = (s_mpu6050_data_t *)item->user_arg;
- if (user_data->calibration_complete)
+ if ((user_data) && user_data->calibration_complete)
{
if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
{
@@ -335,43 +369,42 @@ static int __notify(l_ezlopi_item_t *item)
}
// }
}
- if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
{
if (fabs(__prev[1] - user_data->ay) > 0.5)
{
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
{
if (fabs(__prev[2] - user_data->az) > 0.5)
{
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_temp == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_temp == item->cloud_properties.item_name)
{
if (fabs(__prev[3] - user_data->tmp) > 0.5)
{
ezlopi_device_value_updated_from_device_v3(item);
}
}
-
- if (ezlopi_item_name_gyroscope_x_axis == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_gyroscope_x_axis == item->cloud_properties.item_name)
{
if (fabs(__prev[4] - user_data->gx) > 0.5)
{
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_gyroscope_y_axis == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_gyroscope_y_axis == item->cloud_properties.item_name)
{
if (fabs(__prev[5] - user_data->gy) > 0.5)
{
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_gyroscope_z_axis == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_gyroscope_z_axis == item->cloud_properties.item_name)
{
if (fabs(__prev[6] - user_data->gz) > 0.5)
{
@@ -391,71 +424,73 @@ static void __mpu6050_calibration_task(void *params) // calibrate task
if (item)
{
s_mpu6050_data_t *user_data = (s_mpu6050_data_t *)item->user_arg;
+ if (user_data)
+ {
+ uint8_t buf[MPU6050_REG_COUNT_LEN] = {0}; // 0 - 13
+ uint8_t dummy[MPU6050_REG_COUNT_LEN] = {0};
- uint8_t buf[MPU6050_REG_COUNT_LEN] = {0}; // 0 - 13
- uint8_t dummy[MPU6050_REG_COUNT_LEN] = {0};
-
- float calibrationData[3] = {0};
- uint8_t Check_Register = 0;
- esp_err_t err = ESP_OK;
- TRACE_W(".....................Calculating Paramter");
-
- uint8_t write_buffer[] = {REG_INTR_STATUS}; // REG_INTR_STATUS;
- uint8_t address_val = (ACCEL_X_H);
+ float calibrationData[3] = {0};
+ uint8_t Check_Register = 0;
+ esp_err_t err = ESP_OK;
+ TRACE_W(".....................Calculating Paramter");
- for (uint8_t i = CALIBRATION_SAMPLES + 50; i > 0; i--)
- {
- err = ezlopi_i2c_master_write_to_device(&item->interface.i2c_master, write_buffer, 1);
- err = ezlopi_i2c_master_read_from_device(&item->interface.i2c_master, &Check_Register, 1);
+ uint8_t write_buffer[] = {REG_INTR_STATUS}; // REG_INTR_STATUS;
+ uint8_t address_val = (ACCEL_X_H);
- if (ESP_OK == err)
+ for (uint8_t i = CALIBRATION_SAMPLES + 50; i > 0; i--)
{
- if (Check_Register & DATA_RDY_INT_FLAG)
- {
- err = ezlopi_i2c_master_write_to_device(&item->interface.i2c_master, &address_val, 1);
- err = ezlopi_i2c_master_read_from_device(&item->interface.i2c_master, (buf), MPU6050_REG_COUNT_LEN);
- }
- if (i <= CALIBRATION_SAMPLES)
+ err = ezlopi_i2c_master_write_to_device(&item->interface.i2c_master, write_buffer, 1);
+ err = ezlopi_i2c_master_read_from_device(&item->interface.i2c_master, &Check_Register, 1);
+
+ if (ESP_OK == err)
{
- if (ESP_OK != err)
+ if (Check_Register & DATA_RDY_INT_FLAG)
{
- buf[8] = dummy[8];
- buf[9] = dummy[9];
- buf[10] = dummy[10];
- buf[11] = dummy[11];
- buf[12] = dummy[12];
- buf[13] = dummy[13];
+ err = ezlopi_i2c_master_write_to_device(&item->interface.i2c_master, &address_val, 1);
+ err = ezlopi_i2c_master_read_from_device(&item->interface.i2c_master, (buf), MPU6050_REG_COUNT_LEN);
}
- else
+ if (i <= CALIBRATION_SAMPLES)
{
- dummy[8] = buf[8];
- dummy[9] = buf[9];
- dummy[10] = buf[10];
- dummy[11] = buf[11];
- dummy[12] = buf[12];
- dummy[13] = buf[13];
+ if (ESP_OK != err)
+ {
+ buf[8] = dummy[8];
+ buf[9] = dummy[9];
+ buf[10] = dummy[10];
+ buf[11] = dummy[11];
+ buf[12] = dummy[12];
+ buf[13] = dummy[13];
+ }
+ else
+ {
+ dummy[8] = buf[8];
+ dummy[9] = buf[9];
+ dummy[10] = buf[10];
+ dummy[11] = buf[11];
+ dummy[12] = buf[12];
+ dummy[13] = buf[13];
+ }
+ calibrationData[0] += (float)((int16_t)(buf[8] << 8 | buf[9])); // mean_raw_gx = 67 & 68;
+ calibrationData[1] += (float)((int16_t)(buf[10] << 8 | buf[11])); // mean_raw_gy = 69 & 70;
+ calibrationData[2] += (float)((int16_t)(buf[12] << 8 | buf[13])); // mean_raw_gz = 71 & 72;
}
- calibrationData[0] += (float)((int16_t)(buf[8] << 8 | buf[9])); // mean_raw_gx = 67 & 68;
- calibrationData[1] += (float)((int16_t)(buf[10] << 8 | buf[11])); // mean_raw_gy = 69 & 70;
- calibrationData[2] += (float)((int16_t)(buf[12] << 8 | buf[13])); // mean_raw_gz = 71 & 72;
+ }
+ else
+ {
+ TRACE_E("Data not ready ... [%d]", i);
}
}
- else
- {
- TRACE_E("Data not ready ... [%d]", i);
- }
- }
- user_data->gyro_x_offset = calibrationData[0] / (CALIBRATION_SAMPLES);
- user_data->gyro_y_offset = calibrationData[1] / (CALIBRATION_SAMPLES);
- user_data->gyro_z_offset = calibrationData[2] / (CALIBRATION_SAMPLES);
+ user_data->gyro_x_offset = calibrationData[0] / (CALIBRATION_SAMPLES);
+ user_data->gyro_y_offset = calibrationData[1] / (CALIBRATION_SAMPLES);
+ user_data->gyro_z_offset = calibrationData[2] / (CALIBRATION_SAMPLES);
- TRACE_S("Scale :--- new_gy_offset_X=%.2f | new_gy_offset_Y=%.2f | new_gy_offset_Z=%.2f ",
- user_data->gyro_x_offset,
- user_data->gyro_y_offset,
- user_data->gyro_z_offset);
- TRACE_W("......................CALIBRATION COMPLETE");
- user_data->calibration_complete = true;
+ TRACE_S("Scale :--- new_gy_offset_X=%.2f | new_gy_offset_Y=%.2f | new_gy_offset_Z=%.2f ",
+ user_data->gyro_x_offset,
+ user_data->gyro_y_offset,
+ user_data->gyro_z_offset);
+ TRACE_W("......................CALIBRATION COMPLETE");
+ user_data->calibration_complete = true;
+ }
}
vTaskDelete(NULL);
}
diff --git a/ezlopi-sensors-devices/sensor-0006-I2C-ADXL345/sensor_0006_I2C_ADXL345.c b/ezlopi-sensors-devices/sensor-0006-I2C-ADXL345/sensor_0006_I2C_ADXL345.c
index 914e468df..8e99a1be1 100644
--- a/ezlopi-sensors-devices/sensor-0006-I2C-ADXL345/sensor_0006_I2C_ADXL345.c
+++ b/ezlopi-sensors-devices/sensor-0006-I2C-ADXL345/sensor_0006_I2C_ADXL345.c
@@ -14,15 +14,15 @@
#include "sensor_0006_I2C_ADXL345.h"
-static int __prepare(void *arg);
-static int __init(l_ezlopi_item_t *item);
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __notify(l_ezlopi_item_t *item);
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
-static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_data);
-static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device);
+static int __prepare(void* arg);
+static int __init(l_ezlopi_item_t* item);
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __notify(l_ezlopi_item_t* item);
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
+static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, void* user_data);
+static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device);
-int sensor_0006_I2C_ADXL345(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0006_I2C_ADXL345(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -56,9 +56,9 @@ int sensor_0006_I2C_ADXL345(e_ezlopi_actions_t action, l_ezlopi_item_t *item, vo
return ret;
}
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
ASSIGN_DEVICE_NAME_V2(device, device_name);
device->cloud_properties.device_id = ezlopi_cloud_generate_device_id();
@@ -68,7 +68,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.device_type_id = NULL;
device->cloud_properties.device_type = dev_type_sensor;
}
-static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_data)
+static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, void* user_data)
{
if (item)
{
@@ -81,16 +81,16 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_da
item->user_arg = user_data;
}
}
-static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
if (item && cj_device)
{
if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
{
item->interface.i2c_master.enable = true;
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
- CJSON_GET_VALUE_INT(cj_device, "gpio_sda", item->interface.i2c_master.sda);
- CJSON_GET_VALUE_INT(cj_device, "gpio_scl", item->interface.i2c_master.scl);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_sda_str, item->interface.i2c_master.sda);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_scl_str, item->interface.i2c_master.scl);
CJSON_GET_VALUE_INT(cj_device, "slave_addr", item->interface.i2c_master.address);
item->interface.i2c_master.clock_speed = 100000;
if (0 == item->interface.i2c_master.address)
@@ -105,36 +105,36 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj
}
}
-static int __prepare(void *arg)
+static int __prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg && prep_arg->cjson_device)
{
- cJSON *cj_device = prep_arg->cjson_device;
- s_adxl345_data_t *user_data = (s_adxl345_data_t *)malloc(sizeof(s_adxl345_data_t));
+ cJSON* cj_device = prep_arg->cjson_device;
+ s_adxl345_data_t* user_data = (s_adxl345_data_t*)malloc(sizeof(s_adxl345_data_t));
if (NULL != user_data)
{
memset(user_data, 0, sizeof(s_adxl345_data_t));
- l_ezlopi_device_t *adxl345_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* adxl345_device = ezlopi_device_add_device(cj_device);
if (adxl345_device)
{
__prepare_device_cloud_properties(adxl345_device, cj_device);
- l_ezlopi_item_t *x_item = ezlopi_device_add_item_to_device(adxl345_device, sensor_0006_I2C_ADXL345);
+ l_ezlopi_item_t* x_item = ezlopi_device_add_item_to_device(adxl345_device, sensor_0006_I2C_ADXL345);
if (x_item)
{
x_item->cloud_properties.item_name = ezlopi_item_name_acceleration_x_axis;
__prepare_item_cloud_properties(x_item, user_data);
__prepare_item_interface_properties(x_item, cj_device);
}
- l_ezlopi_item_t *y_item = ezlopi_device_add_item_to_device(adxl345_device, sensor_0006_I2C_ADXL345);
+ l_ezlopi_item_t* y_item = ezlopi_device_add_item_to_device(adxl345_device, sensor_0006_I2C_ADXL345);
if (y_item)
{
y_item->cloud_properties.item_name = ezlopi_item_name_acceleration_y_axis;
__prepare_item_cloud_properties(y_item, user_data);
__prepare_item_interface_properties(y_item, cj_device);
}
- l_ezlopi_item_t *z_item = ezlopi_device_add_item_to_device(adxl345_device, sensor_0006_I2C_ADXL345);
+ l_ezlopi_item_t* z_item = ezlopi_device_add_item_to_device(adxl345_device, sensor_0006_I2C_ADXL345);
if (z_item)
{
z_item->cloud_properties.item_name = ezlopi_item_name_acceleration_z_axis;
@@ -161,101 +161,126 @@ static int __prepare(void *arg)
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- if (item->interface.i2c_master.enable)
+ s_adxl345_data_t *user_data = (s_adxl345_data_t *)item->user_arg;
+ if (user_data)
{
- ezlopi_i2c_master_init(&item->interface.i2c_master);
- if (0 == __adxl345_configure_device(item))
+ if (item->interface.i2c_master.enable)
{
- TRACE_S("Configuration Complete...");
+ ezlopi_i2c_master_init(&item->interface.i2c_master);
+ if (0 == __adxl345_configure_device(item)) // ESP_OK
+ {
+ TRACE_S("Configuration Complete...");
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- ret = 1;
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- cJSON *cj_result = (cJSON *)arg;
- if (cj_result && item)
+ if (item && arg)
{
- float acceleration_value;
- s_adxl345_data_t *user_data = (s_adxl345_data_t *)item->user_arg;
- if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
+ cJSON *cj_result = (cJSON *)arg;
+ if (cj_result)
{
- acceleration_value = (user_data->acc_x * ADXL345_CONVERTER_FACTOR_MG_TO_G * ADXL345_STANDARD_G_TO_ACCEL_CONVERSION_VALUE);
- cJSON_AddNumberToObject(cj_result, "value", acceleration_value);
- char *valueFormatted = ezlopi_valueformatter_float(acceleration_value);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
- {
- acceleration_value = (user_data->acc_y * ADXL345_CONVERTER_FACTOR_MG_TO_G * ADXL345_STANDARD_G_TO_ACCEL_CONVERSION_VALUE);
- cJSON_AddNumberToObject(cj_result, "value", acceleration_value);
- char *valueFormatted = ezlopi_valueformatter_float(acceleration_value);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- }
- if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
- {
- acceleration_value = (user_data->acc_z * ADXL345_CONVERTER_FACTOR_MG_TO_G * ADXL345_STANDARD_G_TO_ACCEL_CONVERSION_VALUE);
- cJSON_AddNumberToObject(cj_result, "value", acceleration_value);
- char *valueFormatted = ezlopi_valueformatter_float(acceleration_value);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
+ float acceleration_value = 0;
+ s_adxl345_data_t *user_data = (s_adxl345_data_t *)item->user_arg;
+ if (user_data)
+ {
+ if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
+ {
+ acceleration_value = (user_data->acc_x * ADXL345_CONVERTER_FACTOR_MG_TO_G * ADXL345_STANDARD_G_TO_ACCEL_CONVERSION_VALUE);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, acceleration_value);
+ char *valueFormatted = ezlopi_valueformatter_float(acceleration_value);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
+ {
+ acceleration_value = (user_data->acc_y * ADXL345_CONVERTER_FACTOR_MG_TO_G * ADXL345_STANDARD_G_TO_ACCEL_CONVERSION_VALUE);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, acceleration_value);
+ char *valueFormatted = ezlopi_valueformatter_float(acceleration_value);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
+ {
+ acceleration_value = (user_data->acc_z * ADXL345_CONVERTER_FACTOR_MG_TO_G * ADXL345_STANDARD_G_TO_ACCEL_CONVERSION_VALUE);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, acceleration_value);
+ char *valueFormatted = ezlopi_valueformatter_float(acceleration_value);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ ret = 1;
+ }
}
- ret = 1;
}
return ret;
}
-static int __notify(l_ezlopi_item_t *item)
+static int __notify(l_ezlopi_item_t* item)
{
int ret = 0;
- static float __prev[3] = {0};
+ static float __prev[3] = { 0 };
if (item)
{
s_adxl345_data_t *user_data = (s_adxl345_data_t *)item->user_arg;
- if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
+ if (user_data)
{
- __prev[0] = user_data->acc_x;
- __adxl345_get_axis_value(item);
- if (fabs((__prev[0] - user_data->acc_x) > 0.5))
+ if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
{
- ezlopi_device_value_updated_from_device_v3(item);
+ __prev[0] = user_data->acc_x;
+ __adxl345_get_axis_value(item);
+ if (fabs((__prev[0] - user_data->acc_x) > 0.5))
+ {
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
- {
- __prev[1] = user_data->acc_y;
- if (fabs((__prev[1] - user_data->acc_x) > 0.5))
+ if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
{
- ezlopi_device_value_updated_from_device_v3(item);
+ __prev[1] = user_data->acc_y;
+ if (fabs((__prev[1] - user_data->acc_x) > 0.5))
+ {
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
- {
- __prev[2] = user_data->acc_z;
- if (fabs((__prev[2] - user_data->acc_x) > 0.5))
+ if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
{
- ezlopi_device_value_updated_from_device_v3(item);
+ __prev[2] = user_data->acc_z;
+ if (fabs((__prev[2] - user_data->acc_x) > 0.5))
+ {
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
diff --git a/ezlopi-sensors-devices/sensor-0007-I2C-GY271/sensor_0007_I2C_GY271.c b/ezlopi-sensors-devices/sensor-0007-I2C-GY271/sensor_0007_I2C_GY271.c
index 7a311073b..e9896a59c 100644
--- a/ezlopi-sensors-devices/sensor-0007-I2C-GY271/sensor_0007_I2C_GY271.c
+++ b/ezlopi-sensors-devices/sensor-0007-I2C-GY271/sensor_0007_I2C_GY271.c
@@ -15,16 +15,16 @@
#include "sensor_0007_I2C_GY271.h"
//------------------------------------------------------------------------------------------------------------------------------------------------------------
-static int __prepare(void* arg);
-static int __init(l_ezlopi_item_t* item);
-static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
-static int __notify(l_ezlopi_item_t* item);
+static int __prepare(void *arg);
+static int __init(l_ezlopi_item_t *item);
+static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
+static int __notify(l_ezlopi_item_t *item);
// static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
-static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, void* user_data);
-static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device);
-static void __gy271_calibration_task(void* params);
+static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_data);
+static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device);
+static void __gy271_calibration_task(void *params);
//------------------------------------------------------------------------------------------------------------------------------------------------------------
-int sensor_0007_I2C_GY271(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
+int sensor_0007_I2C_GY271(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
{
int ret = 0;
switch (action)
@@ -58,9 +58,9 @@ int sensor_0007_I2C_GY271(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------
-static void __prepare_device_cloud_properties_parent_x(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_cloud_properties_parent_x(l_ezlopi_device_t *device, cJSON *cj_device)
{
- char* device_name = NULL;
+ char *device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
char device_full_name[50];
snprintf(device_full_name, 50, "%s_%s", device_name, "Mag_strength_x");
@@ -73,9 +73,9 @@ static void __prepare_device_cloud_properties_parent_x(l_ezlopi_device_t* device
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_device_cloud_properties_child_y(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_cloud_properties_child_y(l_ezlopi_device_t *device, cJSON *cj_device)
{
- char* device_name = NULL;
+ char *device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
char device_full_name[50];
snprintf(device_full_name, 50, "%s_%s", device_name, "Mag_strength_y");
@@ -88,9 +88,9 @@ static void __prepare_device_cloud_properties_child_y(l_ezlopi_device_t* device,
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_device_cloud_properties_child_z(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_cloud_properties_child_z(l_ezlopi_device_t *device, cJSON *cj_device)
{
- char* device_name = NULL;
+ char *device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
char device_full_name[50];
snprintf(device_full_name, 50, "%s_%s", device_name, "Mag_strength_z");
@@ -103,9 +103,9 @@ static void __prepare_device_cloud_properties_child_z(l_ezlopi_device_t* device,
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_device_cloud_properties_child_azi(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_cloud_properties_child_azi(l_ezlopi_device_t *device, cJSON *cj_device)
{
- char* device_name = NULL;
+ char *device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
char device_full_name[50];
snprintf(device_full_name, 50, "%s_%s", device_name, "Azimuth Angle");
@@ -118,9 +118,9 @@ static void __prepare_device_cloud_properties_child_azi(l_ezlopi_device_t* devic
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_device_cloud_properties_child_temp(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_cloud_properties_child_temp(l_ezlopi_device_t *device, cJSON *cj_device)
{
- char* device_name = NULL;
+ char *device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
char device_full_name[50];
snprintf(device_full_name, 50, "%s_%s", device_name, "Temperature");
@@ -133,7 +133,7 @@ static void __prepare_device_cloud_properties_child_temp(l_ezlopi_device_t* devi
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, void* user_data)
+static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_data)
{
if (item)
{
@@ -144,16 +144,16 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, void* user_da
item->user_arg = user_data;
}
}
-static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device)
+static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device)
{
if (item && cj_device)
{
if (ezlopi_item_name_magnetic_strength_x_axis == item->cloud_properties.item_name)
{
item->interface.i2c_master.enable = true;
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
- CJSON_GET_VALUE_INT(cj_device, "gpio_sda", item->interface.i2c_master.sda);
- CJSON_GET_VALUE_INT(cj_device, "gpio_scl", item->interface.i2c_master.scl);
+ CJSON_GET_VALUE_INT(cj_device,ezlopi_dev_type_str, item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_sda_str, item->interface.i2c_master.sda);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_scl_str, item->interface.i2c_master.scl);
CJSON_GET_VALUE_INT(cj_device, "slave_addr", item->interface.i2c_master.address);
item->interface.i2c_master.clock_speed = 100000;
@@ -169,22 +169,22 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj
}
}
-static int __prepare(void* arg)
+static int __prepare(void *arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
+ s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (prep_arg && prep_arg->cjson_device)
{
- cJSON* cj_device = prep_arg->cjson_device;
- s_gy271_data_t* user_data = (s_gy271_data_t*)malloc(sizeof(s_gy271_data_t));
- if (NULL != user_data)
+ cJSON *cj_device = prep_arg->cjson_device;
+ s_gy271_data_t *user_data = (s_gy271_data_t *)malloc(sizeof(s_gy271_data_t));
+ if (user_data)
{
memset(user_data, 0, sizeof(s_gy271_data_t));
- l_ezlopi_device_t* gy271_device_parent_x_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t *gy271_device_parent_x_device = ezlopi_device_add_device(cj_device);
if (gy271_device_parent_x_device)
{
__prepare_device_cloud_properties_parent_x(gy271_device_parent_x_device, cj_device);
- l_ezlopi_item_t* gyro_x_item = ezlopi_device_add_item_to_device(gy271_device_parent_x_device, sensor_0007_I2C_GY271);
+ l_ezlopi_item_t *gyro_x_item = ezlopi_device_add_item_to_device(gy271_device_parent_x_device, sensor_0007_I2C_GY271);
if (gyro_x_item)
{
__prepare_item_cloud_properties(gyro_x_item, user_data);
@@ -194,12 +194,12 @@ static int __prepare(void* arg)
gyro_x_item->cloud_properties.scale = scales_guass;
__prepare_item_interface_properties(gyro_x_item, cj_device);
}
- l_ezlopi_device_t* gy271_device_child_y_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t *gy271_device_child_y_device = ezlopi_device_add_device(cj_device);
if (gy271_device_child_y_device)
{
__prepare_device_cloud_properties_child_y(gy271_device_child_y_device, cj_device);
gy271_device_child_y_device->cloud_properties.parent_device_id = gy271_device_parent_x_device->cloud_properties.device_id; // assigning parent_device_id to child_device
- l_ezlopi_item_t* gyro_y_item = ezlopi_device_add_item_to_device(gy271_device_child_y_device, sensor_0007_I2C_GY271);
+ l_ezlopi_item_t *gyro_y_item = ezlopi_device_add_item_to_device(gy271_device_child_y_device, sensor_0007_I2C_GY271);
if (gyro_y_item)
{
__prepare_item_cloud_properties(gyro_y_item, user_data);
@@ -211,12 +211,12 @@ static int __prepare(void* arg)
}
}
- l_ezlopi_device_t* gy271_device_child_z_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t *gy271_device_child_z_device = ezlopi_device_add_device(cj_device);
if (gy271_device_child_z_device)
{
__prepare_device_cloud_properties_child_z(gy271_device_child_z_device, cj_device);
gy271_device_child_z_device->cloud_properties.parent_device_id = gy271_device_parent_x_device->cloud_properties.device_id; // assigning parent_device_id to child_device
- l_ezlopi_item_t* gyro_z_item = ezlopi_device_add_item_to_device(gy271_device_child_z_device, sensor_0007_I2C_GY271);
+ l_ezlopi_item_t *gyro_z_item = ezlopi_device_add_item_to_device(gy271_device_child_z_device, sensor_0007_I2C_GY271);
if (gyro_z_item)
{
__prepare_item_cloud_properties(gyro_z_item, user_data);
@@ -227,12 +227,12 @@ static int __prepare(void* arg)
__prepare_item_interface_properties(gyro_z_item, cj_device);
}
}
- l_ezlopi_device_t* gy271_device_child_azi_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t *gy271_device_child_azi_device = ezlopi_device_add_device(cj_device);
if (gy271_device_child_azi_device)
{
__prepare_device_cloud_properties_child_azi(gy271_device_child_azi_device, cj_device);
gy271_device_child_azi_device->cloud_properties.parent_device_id = gy271_device_parent_x_device->cloud_properties.device_id; // assigning parent_device_id to child_device
- l_ezlopi_item_t* gyro_azi_item = ezlopi_device_add_item_to_device(gy271_device_child_azi_device, sensor_0007_I2C_GY271);
+ l_ezlopi_item_t *gyro_azi_item = ezlopi_device_add_item_to_device(gy271_device_child_azi_device, sensor_0007_I2C_GY271);
if (gyro_azi_item)
{
__prepare_item_cloud_properties(gyro_azi_item, user_data);
@@ -243,12 +243,12 @@ static int __prepare(void* arg)
__prepare_item_interface_properties(gyro_azi_item, cj_device);
}
}
- l_ezlopi_device_t* gy271_device_child_temp_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t *gy271_device_child_temp_device = ezlopi_device_add_device(cj_device);
if (gy271_device_child_temp_device)
{
__prepare_device_cloud_properties_child_temp(gy271_device_child_temp_device, cj_device);
gy271_device_child_temp_device->cloud_properties.parent_device_id = gy271_device_parent_x_device->cloud_properties.device_id; // assigning parent_device_id to child_device
- l_ezlopi_item_t* gyro_temp_item = ezlopi_device_add_item_to_device(gy271_device_child_temp_device, sensor_0007_I2C_GY271);
+ l_ezlopi_item_t *gyro_temp_item = ezlopi_device_add_item_to_device(gy271_device_child_temp_device, sensor_0007_I2C_GY271);
if (gyro_temp_item)
{
__prepare_item_cloud_properties(gyro_temp_item, user_data);
@@ -272,108 +272,119 @@ static int __prepare(void* arg)
return ret;
}
-static int __init(l_ezlopi_item_t* item)
+static int __init(l_ezlopi_item_t *item)
{
int ret = 0;
-
if (item)
{
- if (item->interface.i2c_master.enable)
+ s_gy271_data_t *user_data = (s_gy271_data_t *)item->user_arg;
+ if (user_data)
{
- ezlopi_i2c_master_init(&item->interface.i2c_master);
- TRACE_I("I2C initialized to channel %d", item->interface.i2c_master.channel);
- if (0 == __gy271_configure(item))
+ if (item->interface.i2c_master.enable)
{
- TRACE_S(" CONFIGURATION Compplete _____ Calibration Started _____");
- xTaskCreate(__gy271_calibration_task, "GY271_Calibration_Task", 2 * 2048, item, 1, NULL);
+ ezlopi_i2c_master_init(&item->interface.i2c_master);
+ TRACE_I("I2C initialized to channel %d", item->interface.i2c_master.channel);
+ if (0 == __gy271_configure(item)) // ESP_OK
+ {
+ // TRACE_D(" CONFIGURATION Compplete _____ Calibration Started _____");
+ xTaskCreate(__gy271_calibration_task, "GY271_Calibration_Task", 2 * 2048, item, 1, NULL);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- ret = 1;
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
+static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON* cj_result = (cJSON*)arg;
- if (cj_result && item)
+ if (item && arg)
{
- s_gy271_data_t* user_data = (s_gy271_data_t*)item->user_arg;
-
- if (ezlopi_item_name_magnetic_strength_x_axis == item->cloud_properties.item_name)
+ cJSON *cj_result = (cJSON *)arg;
+ if (cj_result)
{
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->X);
- char* valueFormatted = ezlopi_valueformatter_float(user_data->X);
- if (valueFormatted)
+ s_gy271_data_t *user_data = (s_gy271_data_t *)item->user_arg;
+ if (user_data)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
- free(valueFormatted);
- }
- }
- if (ezlopi_item_name_magnetic_strength_y_axis == item->cloud_properties.item_name)
- {
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->Y);
- char* valueFormatted = ezlopi_valueformatter_float(user_data->Y);
- if (valueFormatted)
- {
- cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
- free(valueFormatted);
- }
- }
- if (ezlopi_item_name_magnetic_strength_z_axis == item->cloud_properties.item_name)
- {
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->Z);
- char* valueFormatted = ezlopi_valueformatter_float(user_data->Z);
- if (valueFormatted)
- {
- cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
- free(valueFormatted);
- }
- }
- if (ezlopi_item_name_angle_position == item->cloud_properties.item_name)
- {
+ if (ezlopi_item_name_magnetic_strength_x_axis == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->X);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->X);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_magnetic_strength_y_axis == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->Y);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->Y);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_magnetic_strength_z_axis == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->Z);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->Z);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ if (ezlopi_item_name_angle_position == item->cloud_properties.item_name)
+ {
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (user_data->azimuth));
- char* valueFormatted = ezlopi_valueformatter_int(user_data->azimuth);
- if (valueFormatted)
- {
- cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
- free(valueFormatted);
- }
- }
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (user_data->azimuth));
+ char *valueFormatted = ezlopi_valueformatter_int(user_data->azimuth);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
- if (ezlopi_item_name_temp == item->cloud_properties.item_name)
- {
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->T);
- char* valueFormatted = ezlopi_valueformatter_float(user_data->T);
- if (valueFormatted)
- {
- cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
- free(valueFormatted);
+ if (ezlopi_item_name_temp == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, user_data->T);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->T);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
+ ret = 1;
}
- ret = 1;
}
return ret;
}
-static int __notify(l_ezlopi_item_t* item)
+static int __notify(l_ezlopi_item_t *item)
{
- static float __prev[5] = { 0 };
+ static float __prev[5] = {0};
int ret = 0;
if (item)
{
- s_gy271_data_t* user_data = (s_gy271_data_t*)item->user_arg;
+ s_gy271_data_t *user_data = (s_gy271_data_t *)item->user_arg;
if (user_data->calibration_complete)
{
if (ezlopi_item_name_magnetic_strength_x_axis == item->cloud_properties.item_name)
@@ -426,63 +437,65 @@ static int __notify(l_ezlopi_item_t* item)
return ret;
}
-static void __gy271_calibration_task(void* params) // calibrate task
+static void __gy271_calibration_task(void *params) // calibrate task
{
vTaskDelay(4000 / portTICK_PERIOD_MS);
- l_ezlopi_item_t* item = (l_ezlopi_item_t*)params;
+ l_ezlopi_item_t *item = (l_ezlopi_item_t *)params;
if (item)
{
- int calibrationData[3][2] = { {0, 0}, // xmin,xmax
+ int calibrationData[3][2] = {{0, 0}, // xmin,xmax
{0, 0}, // ymin,ymax
- {0, 0} }; // zmin,zmax// Initialization added!
- s_gy271_data_t* user_data = (s_gy271_data_t*)item->user_arg;
-
- for (uint16_t i = 0; i <= 50; i++)
+ {0, 0}}; // zmin,zmax// Initialization added!
+ s_gy271_data_t *user_data = (s_gy271_data_t *)item->user_arg;
+ if (user_data)
{
- __gy271_get_raw_max_min_values(item, calibrationData);
- vTaskDelay(200 / portTICK_PERIOD_MS);
- }
+ for (uint16_t i = 0; i <= 50; i++)
+ {
+ __gy271_get_raw_max_min_values(item, calibrationData);
+ vTaskDelay(200 / portTICK_PERIOD_MS);
+ }
- TRACE_W(".....................Calculating Paramter.......................");
- // Calculate the : 1.bias_axis , 2.delta_axis , 3.delta_avg , 4.scale_axis
- // 1. bias_axis{x,y,z}
- user_data->calib_factor.bias_axis[0] = ((long)(calibrationData[0][1] + calibrationData[0][0]) / 2); // x-axis
- user_data->calib_factor.bias_axis[1] = ((long)(calibrationData[1][1] + calibrationData[1][0]) / 2); // y-axis
- user_data->calib_factor.bias_axis[2] = ((long)(calibrationData[2][1] + calibrationData[2][0]) / 2); // z-axis
+ TRACE_W(".....................Calculating Paramter.......................");
+ // Calculate the : 1.bias_axis , 2.delta_axis , 3.delta_avg , 4.scale_axis
+ // 1. bias_axis{x,y,z}
+ user_data->calib_factor.bias_axis[0] = ((long)(calibrationData[0][1] + calibrationData[0][0]) / 2); // x-axis
+ user_data->calib_factor.bias_axis[1] = ((long)(calibrationData[1][1] + calibrationData[1][0]) / 2); // y-axis
+ user_data->calib_factor.bias_axis[2] = ((long)(calibrationData[2][1] + calibrationData[2][0]) / 2); // z-axis
- // 2. delta_axis{x,y,z}
- user_data->calib_factor.delta_axis[0] = (long)(calibrationData[0][1] - calibrationData[0][0]); // x-axis
- user_data->calib_factor.delta_axis[1] = (long)(calibrationData[1][1] - calibrationData[1][0]); // y-axis
- user_data->calib_factor.delta_axis[2] = (long)(calibrationData[2][1] - calibrationData[2][0]); // z-axis
+ // 2. delta_axis{x,y,z}
+ user_data->calib_factor.delta_axis[0] = (long)(calibrationData[0][1] - calibrationData[0][0]); // x-axis
+ user_data->calib_factor.delta_axis[1] = (long)(calibrationData[1][1] - calibrationData[1][0]); // y-axis
+ user_data->calib_factor.delta_axis[2] = (long)(calibrationData[2][1] - calibrationData[2][0]); // z-axis
- // 3. delta_avg
- user_data->calib_factor.delta_avg = ((float)((user_data->calib_factor.delta_axis[0]) +
- (user_data->calib_factor.delta_axis[1]) +
- (user_data->calib_factor.delta_axis[2])) /
- 3.0f);
+ // 3. delta_avg
+ user_data->calib_factor.delta_avg = ((float)((user_data->calib_factor.delta_axis[0]) +
+ (user_data->calib_factor.delta_axis[1]) +
+ (user_data->calib_factor.delta_axis[2])) /
+ 3.0f);
- // 4. Scale_axis{x,y,z}
- user_data->calib_factor.scale_axis[0] = user_data->calib_factor.delta_avg / user_data->calib_factor.delta_axis[0]; // x-axis
- user_data->calib_factor.scale_axis[1] = user_data->calib_factor.delta_avg / user_data->calib_factor.delta_axis[1]; // y-axis
- user_data->calib_factor.scale_axis[2] = user_data->calib_factor.delta_avg / user_data->calib_factor.delta_axis[2]; // z-axis
+ // 4. Scale_axis{x,y,z}
+ user_data->calib_factor.scale_axis[0] = user_data->calib_factor.delta_avg / user_data->calib_factor.delta_axis[0]; // x-axis
+ user_data->calib_factor.scale_axis[1] = user_data->calib_factor.delta_avg / user_data->calib_factor.delta_axis[1]; // y-axis
+ user_data->calib_factor.scale_axis[2] = user_data->calib_factor.delta_avg / user_data->calib_factor.delta_axis[2]; // z-axis
- TRACE_I("Bias :--- _Xaxis=%6ld | _Yaxis=%6ld | _Zaxis=%6ld ",
- user_data->calib_factor.bias_axis[0],
- user_data->calib_factor.bias_axis[1],
- user_data->calib_factor.bias_axis[2]);
+ TRACE_I("Bias :--- _Xaxis=%6ld | _Yaxis=%6ld | _Zaxis=%6ld ",
+ user_data->calib_factor.bias_axis[0],
+ user_data->calib_factor.bias_axis[1],
+ user_data->calib_factor.bias_axis[2]);
- TRACE_I("Delta :--- _Xaxis=%6ld | _Yaxis=%6ld | _Zaxis=%6ld ",
- user_data->calib_factor.delta_axis[0],
- user_data->calib_factor.delta_axis[1],
- user_data->calib_factor.delta_axis[2]);
- TRACE_I("Delta_AVG :--- %6f", user_data->calib_factor.delta_avg);
+ TRACE_I("Delta :--- _Xaxis=%6ld | _Yaxis=%6ld | _Zaxis=%6ld ",
+ user_data->calib_factor.delta_axis[0],
+ user_data->calib_factor.delta_axis[1],
+ user_data->calib_factor.delta_axis[2]);
+ TRACE_I("Delta_AVG :--- %6f", user_data->calib_factor.delta_avg);
- TRACE_I("Scale :--- _Xaxis=%6f | _Yaxis=%6f | _Zaxis=%6f ",
- user_data->calib_factor.scale_axis[0],
- user_data->calib_factor.scale_axis[1],
- user_data->calib_factor.scale_axis[0]);
- TRACE_W("......................CALIBRATION COMPLETE.....................");
- user_data->calibration_complete = true;
+ TRACE_I("Scale :--- _Xaxis=%6f | _Yaxis=%6f | _Zaxis=%6f ",
+ user_data->calib_factor.scale_axis[0],
+ user_data->calib_factor.scale_axis[1],
+ user_data->calib_factor.scale_axis[0]);
+ TRACE_W("......................CALIBRATION COMPLETE.....................");
+ user_data->calibration_complete = true;
+ }
}
vTaskDelete(NULL);
}
diff --git a/ezlopi-sensors-devices/sensor-0008-I2C-LTR303ALS/sensor_0008_I2C_LTR303ALS.c b/ezlopi-sensors-devices/sensor-0008-I2C-LTR303ALS/sensor_0008_I2C_LTR303ALS.c
index 13e404ad8..adde0c854 100644
--- a/ezlopi-sensors-devices/sensor-0008-I2C-LTR303ALS/sensor_0008_I2C_LTR303ALS.c
+++ b/ezlopi-sensors-devices/sensor-0008-I2C-LTR303ALS/sensor_0008_I2C_LTR303ALS.c
@@ -60,34 +60,40 @@ int sensor_0008_I2C_LTR303ALS(e_ezlopi_actions_t action, l_ezlopi_item_t *item,
static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
-
- cJSON *cj_param = (cJSON *)arg;
- ltr303_data_t *als_ltr303_data = (ltr303_data_t *)item->user_arg;
- if (cj_param && als_ltr303_data)
+ if (item)
{
- cJSON_AddNumberToObject(cj_param, ezlopi_value_str, als_ltr303_data->lux);
- char *valueFormatted = ezlopi_valueformatter_double(als_ltr303_data->lux);
- cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ cJSON *cj_param = (cJSON *)arg;
+ ltr303_data_t *als_ltr303_data = (ltr303_data_t *)item->user_arg;
+ if (cj_param && als_ltr303_data)
+ {
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, als_ltr303_data->lux);
+ char *valueFormatted = ezlopi_valueformatter_double(als_ltr303_data->lux);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
-
return ret;
}
static int __notify(l_ezlopi_item_t *item)
{
int ret = 0;
-
- ltr303_data_t *als_ltr303_data = (ltr303_data_t *)item->user_arg;
- if (als_ltr303_data)
+ if (item)
{
- ltr303_data_t temp_data;
- if (ESP_OK == ltr303_get_val(&temp_data))
+ ltr303_data_t *als_ltr303_data = (ltr303_data_t *)item->user_arg;
+ if (als_ltr303_data)
{
- if (fabs(als_ltr303_data->lux - temp_data.lux) > 0.2)
+ ltr303_data_t temp_data;
+ if (ESP_OK == ltr303_get_val(&temp_data))
{
- als_ltr303_data->lux = temp_data.lux;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs(als_ltr303_data->lux - temp_data.lux) > 0.2)
+ {
+ als_ltr303_data->lux = temp_data.lux;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
}
@@ -98,24 +104,31 @@ static int __notify(l_ezlopi_item_t *item)
static int __init(l_ezlopi_item_t *item)
{
int ret = 0;
-
- ltr303_data_t *als_ltr303_data = (ltr303_data_t *)item->user_arg;
if (item)
{
- if ((item->interface.i2c_master.enable) && (NULL != als_ltr303_data))
+ ltr303_data_t *als_ltr303_data = (ltr303_data_t *)item->user_arg;
+ if (als_ltr303_data)
{
- ltr303_setup(item->interface.i2c_master.sda, item->interface.i2c_master.scl, true);
- ltr303_get_val(als_ltr303_data);
- ret = 1;
+ if (item->interface.i2c_master.enable)
+ {
+ if (ESP_OK == ltr303_setup(item->interface.i2c_master.sda, item->interface.i2c_master.scl, true))
+ {
+ ltr303_get_val(als_ltr303_data);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
diff --git a/ezlopi-sensors-devices/sensor-0010-I2C-BME680/sensor_0010_I2C_BME680.c b/ezlopi-sensors-devices/sensor-0010-I2C-BME680/sensor_0010_I2C_BME680.c
index b3a288615..8d306c0f1 100644
--- a/ezlopi-sensors-devices/sensor-0010-I2C-BME680/sensor_0010_I2C_BME680.c
+++ b/ezlopi-sensors-devices/sensor-0010-I2C-BME680/sensor_0010_I2C_BME680.c
@@ -15,15 +15,15 @@
#include "bme680_bsec.h"
#include "sensor_0010_I2C_BME680.h"
-static int __prepare(void *arg);
-static int __init(l_ezlopi_item_t *item);
-static int __notify(l_ezlopi_item_t *item);
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
+static int __prepare(void* arg);
+static int __init(l_ezlopi_item_t* item);
+static int __notify(l_ezlopi_item_t* item);
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
-static void __prepare_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg);
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
+static void __prepare_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg);
-int sensor_0010_I2C_BME680(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0010_I2C_BME680(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
switch (action)
{
@@ -56,9 +56,9 @@ int sensor_0010_I2C_BME680(e_ezlopi_actions_t action, l_ezlopi_item_t *item, voi
return 0;
}
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
ASSIGN_DEVICE_NAME_V2(device, device_name);
@@ -69,9 +69,9 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static void __prepare_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -82,8 +82,8 @@ static void __prepare_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device,
{
item->interface.i2c_master.enable = true;
item->interface.i2c_master.clock_speed = 100000;
- CJSON_GET_VALUE_INT(cj_device, "gpio_scl", item->interface.i2c_master.scl);
- CJSON_GET_VALUE_INT(cj_device, "gpio_sda", item->interface.i2c_master.sda);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_scl_str, item->interface.i2c_master.scl);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_sda_str, item->interface.i2c_master.sda);
CJSON_GET_VALUE_INT(cj_device, "slave_addr", item->interface.i2c_master.address);
}
else
@@ -92,23 +92,23 @@ static void __prepare_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device,
}
}
-static int __prepare(void *arg)
+static int __prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg && prep_arg->cjson_device)
{
- cJSON *cj_device = prep_arg->cjson_device;
- bme680_data_t *user_data = (bme680_data_t *)malloc(sizeof(bme680_data_t));
+ cJSON* cj_device = prep_arg->cjson_device;
+ bme680_data_t* user_data = (bme680_data_t*)malloc(sizeof(bme680_data_t));
if (user_data)
{
memset(user_data, 0, sizeof(bme680_data_t));
- l_ezlopi_device_t *temp_humid_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* temp_humid_device = ezlopi_device_add_device(cj_device);
if (temp_humid_device)
{
temp_humid_device->cloud_properties.category = category_temperature;
__prepare_device_cloud_properties(temp_humid_device, cj_device);
- l_ezlopi_item_t *temperature_item = ezlopi_device_add_item_to_device(temp_humid_device, sensor_0010_I2C_BME680);
+ l_ezlopi_item_t* temperature_item = ezlopi_device_add_item_to_device(temp_humid_device, sensor_0010_I2C_BME680);
if (temperature_item)
{
temperature_item->cloud_properties.item_name = ezlopi_item_name_temp;
@@ -116,7 +116,7 @@ static int __prepare(void *arg)
temperature_item->cloud_properties.scale = scales_celsius;
__prepare_cloud_properties(temperature_item, cj_device, user_data);
}
- l_ezlopi_item_t *humidity_item = ezlopi_device_add_item_to_device(temp_humid_device, sensor_0010_I2C_BME680);
+ l_ezlopi_item_t* humidity_item = ezlopi_device_add_item_to_device(temp_humid_device, sensor_0010_I2C_BME680);
if (humidity_item)
{
humidity_item->cloud_properties.item_name = ezlopi_item_name_humidity;
@@ -131,12 +131,12 @@ static int __prepare(void *arg)
}
}
- l_ezlopi_device_t *pressure_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* pressure_device = ezlopi_device_add_device(cj_device);
if (pressure_device)
{
pressure_device->cloud_properties.category = category_level_sensor;
__prepare_device_cloud_properties(pressure_device, cj_device);
- l_ezlopi_item_t *pressure_item = ezlopi_device_add_item_to_device(pressure_device, sensor_0010_I2C_BME680);
+ l_ezlopi_item_t* pressure_item = ezlopi_device_add_item_to_device(pressure_device, sensor_0010_I2C_BME680);
if (pressure_item)
{
pressure_item->cloud_properties.item_name = ezlopi_item_name_atmospheric_pressure;
@@ -151,12 +151,12 @@ static int __prepare(void *arg)
}
}
- l_ezlopi_device_t *aqi_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* aqi_device = ezlopi_device_add_device(cj_device);
if (aqi_device)
{
aqi_device->cloud_properties.category = category_level_sensor;
__prepare_device_cloud_properties(aqi_device, cj_device);
- l_ezlopi_item_t *aqi_item = ezlopi_device_add_item_to_device(aqi_device, sensor_0010_I2C_BME680);
+ l_ezlopi_item_t* aqi_item = ezlopi_device_add_item_to_device(aqi_device, sensor_0010_I2C_BME680);
if (aqi_item)
{
aqi_item->cloud_properties.item_name = ezlopi_item_name_volatile_organic_compound_level;
@@ -171,12 +171,12 @@ static int __prepare(void *arg)
}
}
- l_ezlopi_device_t *altitude_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* altitude_device = ezlopi_device_add_device(cj_device);
if (altitude_device)
{
altitude_device->cloud_properties.category = category_level_sensor;
__prepare_device_cloud_properties(altitude_device, cj_device);
- l_ezlopi_item_t *altitude_item = ezlopi_device_add_item_to_device(altitude_device, sensor_0010_I2C_BME680);
+ l_ezlopi_item_t* altitude_item = ezlopi_device_add_item_to_device(altitude_device, sensor_0010_I2C_BME680);
if (altitude_item)
{
altitude_item->cloud_properties.item_name = ezlopi_item_name_distance;
@@ -191,12 +191,12 @@ static int __prepare(void *arg)
}
}
- l_ezlopi_device_t *co2_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* co2_device = ezlopi_device_add_device(cj_device);
if (co2_device)
{
co2_device->cloud_properties.category = category_level_sensor;
__prepare_device_cloud_properties(co2_device, cj_device);
- l_ezlopi_item_t *co2_item = ezlopi_device_add_item_to_device(co2_device, sensor_0010_I2C_BME680);
+ l_ezlopi_item_t* co2_item = ezlopi_device_add_item_to_device(co2_device, sensor_0010_I2C_BME680);
if (co2_item)
{
co2_item->cloud_properties.item_name = ezlopi_item_name_co2_level;
@@ -227,145 +227,171 @@ static int __prepare(void *arg)
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- if (true == item->interface.i2c_master.enable)
+ bme680_data_t *user_data = (bme680_data_t *)item->user_arg;
+ if (user_data)
{
- ezlopi_i2c_master_init(&item->interface.i2c_master);
- bme680_setup(item->interface.i2c_master.sda, item->interface.i2c_master.scl, true);
+ if (item->interface.i2c_master.enable)
+ {
+ ezlopi_i2c_master_init(&item->interface.i2c_master);
+ bme680_setup(item->interface.i2c_master.sda, item->interface.i2c_master.scl, true);
+ ret = 1;
+ }
}
- ret = 1;
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- cJSON *cj_device = (cJSON *)arg;
- if (cj_device && item)
+ if (item && arg)
{
- bme680_data_t *user_data = (bme680_data_t *)item->user_arg;
- if (ezlopi_item_name_temp == item->cloud_properties.item_name)
- {
- char *valueFormatted = ezlopi_valueformatter_float(user_data->temperature);
- cJSON_AddStringToObject(cj_device, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddNumberToObject(cj_device, "value", user_data->temperature);
- }
- if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
- {
- char *valueFormatted = ezlopi_valueformatter_float(user_data->humidity);
- cJSON_AddStringToObject(cj_device, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddNumberToObject(cj_device, "value", user_data->humidity);
- }
- if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
- {
- char *valueFormatted = ezlopi_valueformatter_float(user_data->pressure / 1000.0);
- cJSON_AddStringToObject(cj_device, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddNumberToObject(cj_device, "value", (user_data->pressure / 1000.0));
- }
- if (ezlopi_item_name_volatile_organic_compound_level == item->cloud_properties.item_name)
- {
- char *valueFormatted = ezlopi_valueformatter_float(user_data->iaq);
- cJSON_AddStringToObject(cj_device, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddNumberToObject(cj_device, "value", (user_data->iaq));
- }
- if (ezlopi_item_name_distance == item->cloud_properties.item_name)
+ cJSON *cj_device = (cJSON *)arg;
+ if (cj_device)
{
- char *valueFormatted = ezlopi_valueformatter_float(user_data->altitude);
- cJSON_AddStringToObject(cj_device, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddNumberToObject(cj_device, "value", (user_data->altitude));
- }
- if (ezlopi_item_name_co2_level == item->cloud_properties.item_name)
- {
- char *valueFormatted = ezlopi_valueformatter_float(user_data->co2_equivalent);
- cJSON_AddStringToObject(cj_device, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddNumberToObject(cj_device, "value", (user_data->co2_equivalent));
+ bme680_data_t *user_data = (bme680_data_t *)item->user_arg;
+ if (user_data)
+ {
+ if (ezlopi_item_name_temp == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, user_data->temperature);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->temperature);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ else if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, user_data->humidity);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->humidity);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ else if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, (user_data->pressure / 1000.0));
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->pressure / 1000.0);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ else if (ezlopi_item_name_volatile_organic_compound_level == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, (user_data->iaq));
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->iaq);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ else if (ezlopi_item_name_distance == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, (user_data->altitude));
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->altitude);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ else if (ezlopi_item_name_co2_level == item->cloud_properties.item_name)
+ {
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, (user_data->co2_equivalent));
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->co2_equivalent);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ }
}
}
-
return ret;
}
-static int __notify(l_ezlopi_item_t *item)
+static int __notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
bme680_data_t *user_data = (bme680_data_t *)item->user_arg;
- float temperature = user_data->temperature;
- float humidity = user_data->humidity;
- float pressure = user_data->pressure;
- float iaq = user_data->iaq;
- float altitude = user_data->altitude;
- float co2_eqv = user_data->co2_equivalent;
+ if (user_data)
+ {
+ float temperature = user_data->temperature;
+ float humidity = user_data->humidity;
+ float pressure = user_data->pressure;
+ float iaq = user_data->iaq;
+ float altitude = user_data->altitude;
+ float co2_eqv = user_data->co2_equivalent;
- bme680_get_data(user_data);
+ bme680_get_data(user_data);
- if (ezlopi_item_name_temp == item->cloud_properties.item_name)
- {
- if (fabs(user_data->temperature - temperature) > 0.05)
+ if (ezlopi_item_name_temp == item->cloud_properties.item_name)
{
- user_data->temperature = temperature;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs(user_data->temperature - temperature) > 0.05)
+ {
+ user_data->temperature = temperature;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
- {
- if (fabs(user_data->humidity - humidity) > 0.05)
+ if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
{
- user_data->humidity = humidity;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs(user_data->humidity - humidity) > 0.05)
+ {
+ user_data->humidity = humidity;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
- {
- if (fabs((user_data->pressure / 1000.0f) - (pressure / 1000.0f)) > 0.05)
+ if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
{
- user_data->pressure = pressure;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs((user_data->pressure / 1000.0f) - (pressure / 1000.0f)) > 0.05)
+ {
+ user_data->pressure = pressure;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_volatile_organic_compound_level == item->cloud_properties.item_name)
- {
- if (fabs(user_data->iaq - iaq) > 0.05)
+ if (ezlopi_item_name_volatile_organic_compound_level == item->cloud_properties.item_name)
{
- user_data->iaq = iaq;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs(user_data->iaq - iaq) > 0.05)
+ {
+ user_data->iaq = iaq;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_distance == item->cloud_properties.item_name)
- {
- if (fabs(user_data->altitude - altitude) > 0.05)
+ if (ezlopi_item_name_distance == item->cloud_properties.item_name)
{
- user_data->altitude = altitude;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs(user_data->altitude - altitude) > 0.05)
+ {
+ user_data->altitude = altitude;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_co2_level == item->cloud_properties.item_name)
- {
- if (fabs(user_data->co2_equivalent - co2_eqv) > 0.05)
+ if (ezlopi_item_name_co2_level == item->cloud_properties.item_name)
{
- user_data->co2_equivalent = co2_eqv;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs(user_data->co2_equivalent - co2_eqv) > 0.05)
+ {
+ user_data->co2_equivalent = co2_eqv;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
}
diff --git a/ezlopi-sensors-devices/sensor-0012-I2C-BME280/sensor_0012_I2C_BME280.c b/ezlopi-sensors-devices/sensor-0012-I2C-BME280/sensor_0012_I2C_BME280.c
index f8c650f68..c42606b40 100644
--- a/ezlopi-sensors-devices/sensor-0012-I2C-BME280/sensor_0012_I2C_BME280.c
+++ b/ezlopi-sensors-devices/sensor-0012-I2C-BME280/sensor_0012_I2C_BME280.c
@@ -93,32 +93,37 @@ static bool check_double_val_equal(double first, double second)
static int __notify(l_ezlopi_item_t *item)
{
int ret = 0;
-
- s_ezlopi_bmp280_t *sensor_params = (s_ezlopi_bmp280_t *)item->user_arg;
- float temperature, pressure, humidity;
- bool update_cloud = false;
- bmp280_read_float(&item->interface.i2c_master, &sensor_params->bmp280_dev, &temperature, &pressure, &humidity);
- // TRACE_I("Temp: %f, Humidity: %f, pressure: %f", temperature, humidity, pressure);
-
- if (ezlopi_item_name_temp == item->cloud_properties.item_name)
- {
- update_cloud = (!check_double_val_equal(sensor_params->temperature, temperature) ? true : false);
- }
- if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
- {
- update_cloud = (!check_double_val_equal(sensor_params->humidity, humidity) ? true : false);
- }
- if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
- {
- update_cloud = (!check_double_val_equal(sensor_params->pressure, pressure) ? true : false);
- }
- if (update_cloud)
+ if (item)
{
- sensor_params->temperature = temperature;
- sensor_params->humidity = humidity;
- sensor_params->pressure = pressure;
- ezlopi_device_value_updated_from_device_v3(item);
- update_cloud = false;
+ s_ezlopi_bmp280_t *sensor_params = (s_ezlopi_bmp280_t *)item->user_arg;
+ if (sensor_params)
+ {
+ float temperature, pressure, humidity;
+ bool update_cloud = false;
+ bmp280_read_float(&item->interface.i2c_master, &sensor_params->bmp280_dev, &temperature, &pressure, &humidity);
+ // TRACE_I("Temp: %f, Humidity: %f, pressure: %f", temperature, humidity, pressure);
+
+ if (ezlopi_item_name_temp == item->cloud_properties.item_name)
+ {
+ update_cloud = (!check_double_val_equal(sensor_params->temperature, temperature) ? true : false);
+ }
+ if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
+ {
+ update_cloud = (!check_double_val_equal(sensor_params->humidity, humidity) ? true : false);
+ }
+ if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
+ {
+ update_cloud = (!check_double_val_equal(sensor_params->pressure, pressure) ? true : false);
+ }
+ if (update_cloud)
+ {
+ sensor_params->temperature = temperature;
+ sensor_params->humidity = humidity;
+ sensor_params->pressure = pressure;
+ ezlopi_device_value_updated_from_device_v3(item);
+ update_cloud = false;
+ }
+ }
}
return ret;
@@ -127,37 +132,49 @@ static int __notify(l_ezlopi_item_t *item)
static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
-
- char valueFormatted[20];
- cJSON *cj_device = (cJSON *)arg;
- s_ezlopi_bmp280_t *bmp280_sensor_params = (s_ezlopi_bmp280_t *)item->user_arg;
- if (cj_device && bmp280_sensor_params)
+ if (item && arg)
{
- if (ezlopi_item_name_temp == item->cloud_properties.item_name)
+ cJSON *cj_device = (cJSON *)arg;
+ s_ezlopi_bmp280_t *bmp280_sensor_params = (s_ezlopi_bmp280_t *)item->user_arg;
+ if (cj_device && bmp280_sensor_params)
{
- snprintf(valueFormatted, 20, "%0.3f", bmp280_sensor_params->temperature);
- cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_device, ezlopi_value_str, bmp280_sensor_params->temperature);
- cJSON_AddStringToObject(cj_device, ezlopi_scale_str, scales_celsius);
- }
+ if (ezlopi_item_name_temp == item->cloud_properties.item_name)
+ {
+ char *valueFormatted = ezlopi_valueformatter_float(bmp280_sensor_params->temperature);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, bmp280_sensor_params->temperature);
+ cJSON_AddStringToObject(cj_device, ezlopi_scale_str, scales_celsius);
+ }
- if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
- {
- snprintf(valueFormatted, 20, "%0.3f", bmp280_sensor_params->humidity);
- cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_device, ezlopi_value_str, bmp280_sensor_params->humidity);
- cJSON_AddStringToObject(cj_device, ezlopi_scale_str, scales_percent);
- }
+ if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
+ {
+ char *valueFormatted = ezlopi_valueformatter_float(bmp280_sensor_params->humidity);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, bmp280_sensor_params->humidity);
+ cJSON_AddStringToObject(cj_device, ezlopi_scale_str, scales_percent);
+ }
- if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
- {
- snprintf(valueFormatted, 20, "%0.3f", (bmp280_sensor_params->pressure / 1000.0));
- cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_device, ezlopi_value_str, (bmp280_sensor_params->pressure / 1000.0));
- cJSON_AddStringToObject(cj_device, ezlopi_scale_str, scales_kilo_pascal);
+ if (ezlopi_item_name_atmospheric_pressure == item->cloud_properties.item_name)
+ {
+ char *valueFormatted = ezlopi_valueformatter_float((bmp280_sensor_params->pressure / 1000.0));
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_device, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ cJSON_AddNumberToObject(cj_device, ezlopi_value_str, (bmp280_sensor_params->pressure / 1000.0));
+ cJSON_AddStringToObject(cj_device, ezlopi_scale_str, scales_kilo_pascal);
+ }
}
}
-
return ret;
}
@@ -166,10 +183,10 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (item->interface.i2c_master.enable)
+ s_ezlopi_bmp280_t *bmp280_sensor_params = (s_ezlopi_bmp280_t *)item->user_arg;
+ if (bmp280_sensor_params)
{
- s_ezlopi_bmp280_t *bmp280_sensor_params = (s_ezlopi_bmp280_t *)item->user_arg;
- if (bmp280_sensor_params)
+ if (item->interface.i2c_master.enable)
{
ezlopi_i2c_master_init(&item->interface.i2c_master);
bmp280_init_default_params(&bmp280_sensor_params->bmp280_params);
@@ -178,14 +195,10 @@ static int __init(l_ezlopi_item_t *item)
ret = 1;
}
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
diff --git a/ezlopi-sensors-devices/sensor-0015-oneWire-DHT11/sensor_0015_oneWire_DHT11.c b/ezlopi-sensors-devices/sensor-0015-oneWire-DHT11/sensor_0015_oneWire_DHT11.c
index cdba97e14..23143ba9f 100644
--- a/ezlopi-sensors-devices/sensor-0015-oneWire-DHT11/sensor_0015_oneWire_DHT11.c
+++ b/ezlopi-sensors-devices/sensor-0015-oneWire-DHT11/sensor_0015_oneWire_DHT11.c
@@ -1,5 +1,5 @@
#include
-
+
#include "ezlopi_util_trace.h"
#include "ezlopi_core_timer.h"
@@ -20,18 +20,18 @@ typedef struct s_ezlopi_dht11_data
float humidity;
} s_ezlopi_dht11_data_t;
-static int __0015_prepare(void *arg);
-static int __0015_init(l_ezlopi_item_t *item);
-static int __0015_get_value(l_ezlopi_item_t *item, void *args);
-static int __0015_notify(l_ezlopi_item_t *item);
+static int __0015_prepare(void* arg);
+static int __0015_init(l_ezlopi_item_t* item);
+static int __0015_get_value(l_ezlopi_item_t* item, void* args);
+static int __0015_notify(l_ezlopi_item_t* item);
-static int __dht11_setup_item_properties_temperature(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg);
-static int __dht11_setup_item_properties_humidity(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg);
-static int __dht11_setup_device_cloud_properties_temperature(l_ezlopi_device_t *device, cJSON *cj_device);
-static int __dht11_setup_device_cloud_properties_humidity(l_ezlopi_device_t *device, cJSON *cj_device);
+static int __dht11_setup_item_properties_temperature(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg);
+static int __dht11_setup_item_properties_humidity(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg);
+static int __dht11_setup_device_cloud_properties_temperature(l_ezlopi_device_t* device, cJSON* cj_device);
+static int __dht11_setup_device_cloud_properties_humidity(l_ezlopi_device_t* device, cJSON* cj_device);
//-----------------------------------------------------------------------------------------------
-int sensor_0015_oneWire_DHT11(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0015_oneWire_DHT11(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -66,23 +66,23 @@ int sensor_0015_oneWire_DHT11(e_ezlopi_actions_t action, l_ezlopi_item_t *item,
}
//-----------------------------------------------------------------------------------------------
-static int __0015_prepare(void *arg)
+static int __0015_prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg)
{
- cJSON *cjson_device = prep_arg->cjson_device;
+ cJSON* cjson_device = prep_arg->cjson_device;
if (cjson_device)
{
- s_ezlopi_dht11_data_t *dht11_sensor_data = (s_ezlopi_dht11_data_t *)malloc(sizeof(s_ezlopi_dht11_data_t));
+ s_ezlopi_dht11_data_t* dht11_sensor_data = (s_ezlopi_dht11_data_t*)malloc(sizeof(s_ezlopi_dht11_data_t));
if (dht11_sensor_data)
{
- l_ezlopi_device_t *device_temperature = ezlopi_device_add_device(cjson_device);
+ l_ezlopi_device_t* device_temperature = ezlopi_device_add_device(cjson_device);
if (device_temperature)
{
__dht11_setup_device_cloud_properties_temperature(device_temperature, cjson_device);
- l_ezlopi_item_t *item_temperature = ezlopi_device_add_item_to_device(device_temperature, sensor_0015_oneWire_DHT11);
+ l_ezlopi_item_t* item_temperature = ezlopi_device_add_item_to_device(device_temperature, sensor_0015_oneWire_DHT11);
if (item_temperature)
{
item_temperature->cloud_properties.device_id = device_temperature->cloud_properties.device_id;
@@ -94,11 +94,11 @@ static int __0015_prepare(void *arg)
ret = -1;
}
}
- l_ezlopi_device_t *device_humidity = ezlopi_device_add_device(cjson_device);
+ l_ezlopi_device_t* device_humidity = ezlopi_device_add_device(cjson_device);
if (device_humidity)
{
__dht11_setup_device_cloud_properties_humidity(device_humidity, cjson_device);
- l_ezlopi_item_t *item_humidity = ezlopi_device_add_item_to_device(device_humidity, sensor_0015_oneWire_DHT11);
+ l_ezlopi_item_t* item_humidity = ezlopi_device_add_item_to_device(device_humidity, sensor_0015_oneWire_DHT11);
if (item_humidity)
{
item_humidity->cloud_properties.device_id = device_humidity->cloud_properties.device_id;
@@ -121,12 +121,12 @@ static int __0015_prepare(void *arg)
return ret;
}
-static int __dht11_setup_device_cloud_properties_temperature(l_ezlopi_device_t *device, cJSON *cj_device)
+static int __dht11_setup_device_cloud_properties_temperature(l_ezlopi_device_t* device, cJSON* cj_device)
{
int ret = 0;
if (device && cj_device)
{
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
ASSIGN_DEVICE_NAME_V2(device, device_name);
@@ -140,12 +140,12 @@ static int __dht11_setup_device_cloud_properties_temperature(l_ezlopi_device_t *
return ret;
}
-static int __dht11_setup_device_cloud_properties_humidity(l_ezlopi_device_t *device, cJSON *cj_device)
+static int __dht11_setup_device_cloud_properties_humidity(l_ezlopi_device_t* device, cJSON* cj_device)
{
int ret = 0;
if (device && cj_device)
{
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
ASSIGN_DEVICE_NAME_V2(device, device_name);
@@ -159,7 +159,7 @@ static int __dht11_setup_device_cloud_properties_humidity(l_ezlopi_device_t *dev
return ret;
}
-static int __dht11_setup_item_properties_temperature(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static int __dht11_setup_item_properties_temperature(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
int ret = 0;
if (item && cj_device)
@@ -173,16 +173,16 @@ static int __dht11_setup_item_properties_temperature(l_ezlopi_item_t *item, cJSO
item->cloud_properties.scale = scales_celsius;
item->user_arg = user_arg;
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->interface.onewire_master.enable = true;
- CJSON_GET_VALUE_INT(cj_device, "gpio", item->interface.onewire_master.onewire_pin);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.onewire_master.onewire_pin);
}
return ret;
}
-static int __dht11_setup_item_properties_humidity(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static int __dht11_setup_item_properties_humidity(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
int ret = 0;
if (item && cj_device)
@@ -196,70 +196,83 @@ static int __dht11_setup_item_properties_humidity(l_ezlopi_item_t *item, cJSON *
item->cloud_properties.scale = scales_percent;
item->user_arg = user_arg;
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->interface.onewire_master.enable = true;
- CJSON_GET_VALUE_INT(cj_device, "gpio", item->interface.onewire_master.onewire_pin);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.onewire_master.onewire_pin);
}
return ret;
}
-static int __0015_init(l_ezlopi_item_t *item)
+static int __0015_init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.onewire_master.onewire_pin))
- {
- setDHT11gpio(item->interface.onewire_master.onewire_pin);
- ret = 1;
- }
- if (0 == ret)
+ s_ezlopi_dht11_data_t *dht11_data = (s_ezlopi_dht11_data_t *)item->user_arg;
+ if (dht11_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.onewire_master.onewire_pin))
+ {
+ setDHT11gpio(item->interface.onewire_master.onewire_pin);
+ ret = 1;
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
-static int __0015_get_value(l_ezlopi_item_t *item, void *args)
+static int __0015_get_value(l_ezlopi_item_t* item, void* args)
{
int ret = 0;
- cJSON *cj_properties = (cJSON *)args;
+ cJSON* cj_properties = (cJSON*)args;
if (item && cj_properties)
{
- s_ezlopi_dht11_data_t *dht11_data = (s_ezlopi_dht11_data_t *)item->user_arg;
+ s_ezlopi_dht11_data_t* dht11_data = (s_ezlopi_dht11_data_t*)item->user_arg;
if (ezlopi_item_name_temp == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(cj_properties, "value", dht11_data->temperature);
+ cJSON_AddNumberToObject(cj_properties, ezlopi_value_str, dht11_data->temperature);
char *valueFormatted = ezlopi_valueformatter_float(dht11_data->temperature);
- cJSON_AddStringToObject(cj_properties, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddStringToObject(cj_properties, "scale", item->cloud_properties.scale);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_properties, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ cJSON_AddStringToObject(cj_properties, ezlopi_scale_str, item->cloud_properties.scale);
}
if (ezlopi_item_name_humidity == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(cj_properties, "value", dht11_data->humidity);
+ cJSON_AddNumberToObject(cj_properties, ezlopi_value_str, dht11_data->humidity);
char *valueFormatted = ezlopi_valueformatter_float(dht11_data->humidity);
- cJSON_AddStringToObject(cj_properties, "valueFormatted", valueFormatted);
- free(valueFormatted);
- cJSON_AddStringToObject(cj_properties, "scale", item->cloud_properties.scale);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_properties, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ cJSON_AddStringToObject(cj_properties, ezlopi_scale_str, item->cloud_properties.scale);
}
}
return ret;
}
-static int __0015_notify(l_ezlopi_item_t *item)
+static int __0015_notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- s_ezlopi_dht11_data_t *dht11_data = (s_ezlopi_dht11_data_t *)item->user_arg;
+ s_ezlopi_dht11_data_t* dht11_data = (s_ezlopi_dht11_data_t*)item->user_arg;
if (dht11_data)
{
readDHT11();
diff --git a/ezlopi-sensors-devices/sensor-0016-oneWire-DHT22/sensor_0016_oneWire_DHT22.c b/ezlopi-sensors-devices/sensor-0016-oneWire-DHT22/sensor_0016_oneWire_DHT22.c
index bef4598b6..ce1fbe4f0 100644
--- a/ezlopi-sensors-devices/sensor-0016-oneWire-DHT22/sensor_0016_oneWire_DHT22.c
+++ b/ezlopi-sensors-devices/sensor-0016-oneWire-DHT22/sensor_0016_oneWire_DHT22.c
@@ -20,18 +20,18 @@ typedef struct s_ezlopi_dht22_data
float humidity;
} s_ezlopi_dht22_data_t;
-static int dht22_sensor_prepare_v3(void *arg);
-static int dht22_sensor_init_v3(l_ezlopi_item_t *item);
-static int dht22_sensor_get_sensor_value_v3(l_ezlopi_item_t *item, void *args);
-static int dht22_sensor_setup_item_properties_temperature(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg);
-static int dht22_sensor_setup_item_properties_humidity(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg);
+static int dht22_sensor_prepare_v3(void* arg);
+static int dht22_sensor_init_v3(l_ezlopi_item_t* item);
+static int dht22_sensor_get_sensor_value_v3(l_ezlopi_item_t* item, void* args);
+static int dht22_sensor_setup_item_properties_temperature(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg);
+static int dht22_sensor_setup_item_properties_humidity(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg);
-static int dht22_sensor_setup_device_cloud_properties_temperature(l_ezlopi_device_t *device, cJSON *cj_device);
-static int dht22_sensor_setup_device_cloud_properties_humidity(l_ezlopi_device_t *device, cJSON *cj_device);
+static int dht22_sensor_setup_device_cloud_properties_temperature(l_ezlopi_device_t* device, cJSON* cj_device);
+static int dht22_sensor_setup_device_cloud_properties_humidity(l_ezlopi_device_t* device, cJSON* cj_device);
-static int __notify(l_ezlopi_item_t *item);
+static int __notify(l_ezlopi_item_t* item);
-int sensor_0016_oneWire_DHT22(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0016_oneWire_DHT22(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -65,35 +65,43 @@ int sensor_0016_oneWire_DHT22(e_ezlopi_actions_t action, l_ezlopi_item_t *item,
return ret;
}
-static int dht22_sensor_init_v3(l_ezlopi_item_t *item)
+static int dht22_sensor_init_v3(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.onewire_master.onewire_pin))
- {
- setDHT22gpio(item->interface.onewire_master.onewire_pin);
- ret = 1;
- }
- if (0 == ret)
+ s_ezlopi_dht22_data_t *dht22_data = (s_ezlopi_dht22_data_t *)item->user_arg;
+ if (dht22_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.onewire_master.onewire_pin))
{
- free(item->user_arg);
+ setDHT22gpio(item->interface.onewire_master.onewire_pin);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
-static int __notify(l_ezlopi_item_t *item)
+static int __notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- s_ezlopi_dht22_data_t *dht22_data = (s_ezlopi_dht22_data_t *)item->user_arg;
+ s_ezlopi_dht22_data_t* dht22_data = (s_ezlopi_dht22_data_t*)item->user_arg;
if (dht22_data)
{
readDHT22();
@@ -123,22 +131,25 @@ static int __notify(l_ezlopi_item_t *item)
return ret;
}
-static int dht22_sensor_get_sensor_value_v3(l_ezlopi_item_t *item, void *args)
+static int dht22_sensor_get_sensor_value_v3(l_ezlopi_item_t* item, void* args)
{
int ret = 0;
- cJSON *cj_properties = (cJSON *)args;
+ cJSON* cj_properties = (cJSON*)args;
if (item && cj_properties)
{
- s_ezlopi_dht22_data_t *dht22_data = (s_ezlopi_dht22_data_t *)item->user_arg;
+ s_ezlopi_dht22_data_t* dht22_data = (s_ezlopi_dht22_data_t*)item->user_arg;
if (ezlopi_item_name_temp == item->cloud_properties.item_name)
{
cJSON_AddNumberToObject(cj_properties, ezlopi_value_str, dht22_data->temperature);
char *valueFormatted = ezlopi_valueformatter_float(dht22_data->temperature);
- cJSON_AddStringToObject(cj_properties, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_properties, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
cJSON_AddStringToObject(cj_properties, ezlopi_scale_str, item->cloud_properties.scale);
}
@@ -146,32 +157,35 @@ static int dht22_sensor_get_sensor_value_v3(l_ezlopi_item_t *item, void *args)
{
cJSON_AddNumberToObject(cj_properties, ezlopi_value_str, dht22_data->humidity);
char *valueFormatted = ezlopi_valueformatter_float(dht22_data->humidity);
- cJSON_AddStringToObject(cj_properties, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_properties, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
cJSON_AddStringToObject(cj_properties, ezlopi_scale_str, item->cloud_properties.scale);
}
}
return ret;
}
-static int dht22_sensor_prepare_v3(void *arg)
+static int dht22_sensor_prepare_v3(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg)
{
- cJSON *cjson_device = prep_arg->cjson_device;
+ cJSON* cjson_device = prep_arg->cjson_device;
if (cjson_device)
{
- l_ezlopi_device_t *device_temperature = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t* device_temperature = ezlopi_device_add_device(prep_arg->cjson_device);
if (device_temperature)
{
- s_ezlopi_dht22_data_t *dht22_sensor_data_temp = (s_ezlopi_dht22_data_t *)malloc(sizeof(s_ezlopi_dht22_data_t));
+ s_ezlopi_dht22_data_t* dht22_sensor_data_temp = (s_ezlopi_dht22_data_t*)malloc(sizeof(s_ezlopi_dht22_data_t));
if (dht22_sensor_data_temp)
{
dht22_sensor_setup_device_cloud_properties_temperature(device_temperature, cjson_device);
- l_ezlopi_item_t *item_temperature = ezlopi_device_add_item_to_device(device_temperature, sensor_0016_oneWire_DHT22);
+ l_ezlopi_item_t* item_temperature = ezlopi_device_add_item_to_device(device_temperature, sensor_0016_oneWire_DHT22);
if (item_temperature)
{
item_temperature->cloud_properties.device_id = device_temperature->cloud_properties.device_id;
@@ -179,22 +193,23 @@ static int dht22_sensor_prepare_v3(void *arg)
}
else
{
+ ezlopi_device_free_device(device_temperature);
free(dht22_sensor_data_temp);
ret = -1;
}
}
}
- l_ezlopi_device_t *device_humidity = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t* device_humidity = ezlopi_device_add_device(prep_arg->cjson_device);
if (device_humidity)
{
device_humidity->cloud_properties.parent_device_id = device_temperature->cloud_properties.device_id;
- s_ezlopi_dht22_data_t *dht22_sensor_data_hum = (s_ezlopi_dht22_data_t *)malloc(sizeof(s_ezlopi_dht22_data_t));
+ s_ezlopi_dht22_data_t* dht22_sensor_data_hum = (s_ezlopi_dht22_data_t*)malloc(sizeof(s_ezlopi_dht22_data_t));
if (dht22_sensor_data_hum)
{
dht22_sensor_setup_device_cloud_properties_humidity(device_humidity, cjson_device);
- l_ezlopi_item_t *item_humidity = ezlopi_device_add_item_to_device(device_humidity, sensor_0016_oneWire_DHT22);
+ l_ezlopi_item_t* item_humidity = ezlopi_device_add_item_to_device(device_humidity, sensor_0016_oneWire_DHT22);
if (item_humidity)
{
item_humidity->cloud_properties.device_id = device_humidity->cloud_properties.device_id;
@@ -202,6 +217,7 @@ static int dht22_sensor_prepare_v3(void *arg)
}
else
{
+ ezlopi_device_free_device(device_humidity);
free(dht22_sensor_data_hum);
ret = -1;
}
@@ -213,7 +229,7 @@ static int dht22_sensor_prepare_v3(void *arg)
return ret;
}
-static int dht22_sensor_setup_device_cloud_properties_temperature(l_ezlopi_device_t *device, cJSON *cj_device)
+static int dht22_sensor_setup_device_cloud_properties_temperature(l_ezlopi_device_t* device, cJSON* cj_device)
{
int ret = 0;
if (device && cj_device)
@@ -232,7 +248,7 @@ static int dht22_sensor_setup_device_cloud_properties_temperature(l_ezlopi_devic
return ret;
}
-static int dht22_sensor_setup_device_cloud_properties_humidity(l_ezlopi_device_t *device, cJSON *cj_device)
+static int dht22_sensor_setup_device_cloud_properties_humidity(l_ezlopi_device_t* device, cJSON* cj_device)
{
int ret = 0;
if (device && cj_device)
@@ -251,7 +267,7 @@ static int dht22_sensor_setup_device_cloud_properties_humidity(l_ezlopi_device_t
return ret;
}
-static int dht22_sensor_setup_item_properties_temperature(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static int dht22_sensor_setup_item_properties_temperature(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
int ret = 0;
@@ -269,13 +285,13 @@ static int dht22_sensor_setup_item_properties_temperature(l_ezlopi_item_t *item,
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->interface.onewire_master.enable = true;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.onewire_master.onewire_pin);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.onewire_master.onewire_pin);
}
return ret;
}
-static int dht22_sensor_setup_item_properties_humidity(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
+static int dht22_sensor_setup_item_properties_humidity(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
int ret = 0;
diff --git a/ezlopi-sensors-devices/sensor-0017-ADC-potentiometer/sensor_0017_ADC_potentiometer.c b/ezlopi-sensors-devices/sensor-0017-ADC-potentiometer/sensor_0017_ADC_potentiometer.c
index d550b7e9f..830fd7be7 100644
--- a/ezlopi-sensors-devices/sensor-0017-ADC-potentiometer/sensor_0017_ADC_potentiometer.c
+++ b/ezlopi-sensors-devices/sensor-0017-ADC-potentiometer/sensor_0017_ADC_potentiometer.c
@@ -128,20 +128,36 @@ static int __0017_init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
- {
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
- }
- if (0 == ret)
+ s_potentiometer_t *user_data = (s_potentiometer_t *)item->user_arg;
+ if (user_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ {
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -155,11 +171,17 @@ static int __0017_get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (cj_result)
{
s_potentiometer_t *user_data = (s_potentiometer_t *)item->user_arg;
- char *valueFormatted = ezlopi_valueformatter_float(user_data->pot_val);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_result, "value", (user_data->pot_val));
- free(valueFormatted);
- ret = 1;
+ if (user_data)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (user_data->pot_val));
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->pot_val);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ ret = 1;
+ }
}
}
return ret;
@@ -171,16 +193,19 @@ static int __0017_notify(l_ezlopi_item_t *item)
if (item)
{
s_potentiometer_t *user_data = (s_potentiometer_t *)item->user_arg;
- s_ezlopi_analog_data_t adc_data = {.value = 0, .voltage = 0};
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &adc_data);
- float new_pot = (((float)(4095.0f - (adc_data.value)) / 4095.0f) * 100);
-
- if (fabs((user_data->pot_val) - new_pot) > 0.05)
+ if (user_data)
{
- user_data->pot_val = new_pot;
- ezlopi_device_value_updated_from_device_v3(item);
+ s_ezlopi_analog_data_t adc_data = {.value = 0, .voltage = 0};
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &adc_data);
+ float new_pot = (((float)(4095.0f - (adc_data.value)) / 4095.0f) * 100);
+
+ if (fabs((user_data->pot_val) - new_pot) > 0.05)
+ {
+ user_data->pot_val = new_pot;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
+ ret = 1;
}
- ret = 1;
}
return ret;
}
diff --git a/ezlopi-sensors-devices/sensor-0018-other-internal-hall-effect/sensor_0018_other_internal_hall_effect.c b/ezlopi-sensors-devices/sensor-0018-other-internal-hall-effect/sensor_0018_other_internal_hall_effect.c
index 38210cfeb..7b5b4f26c 100644
--- a/ezlopi-sensors-devices/sensor-0018-other-internal-hall-effect/sensor_0018_other_internal_hall_effect.c
+++ b/ezlopi-sensors-devices/sensor-0018-other-internal-hall-effect/sensor_0018_other_internal_hall_effect.c
@@ -19,7 +19,7 @@
#include "sensor_0018_other_internal_hall_effect.h"
-const char* hall_door_window_states[] = {
+const char *hall_door_window_states[] = {
"dw_is_opened",
"dw_is_closed",
"unknown",
@@ -27,20 +27,20 @@ const char* hall_door_window_states[] = {
typedef struct s_hall_data
{
bool calibration_complete;
- char* hall_state;
+ char *hall_state;
int Custom_stable_val;
} s_hall_data_t;
-static int __prepare(void* arg);
-static int __init(l_ezlopi_item_t* item);
-static int __get_item_cjson(l_ezlopi_item_t* item, void* arg);
-static int __get_value_cjson(l_ezlopi_item_t* item, void* arg);
-static int __notify(l_ezlopi_item_t* item);
-static void __setup_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
-static void __setup_item_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data);
-static void __hall_calibration_task(void* params);
+static int __prepare(void *arg);
+static int __init(l_ezlopi_item_t *item);
+static int __get_item_cjson(l_ezlopi_item_t *item, void *arg);
+static int __get_value_cjson(l_ezlopi_item_t *item, void *arg);
+static int __notify(l_ezlopi_item_t *item);
+static void __setup_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
+static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data);
+static void __hall_calibration_task(void *params);
-int sensor_0018_other_internal_hall_effect(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
+int sensor_0018_other_internal_hall_effect(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
{
int ret = 0;
@@ -81,11 +81,11 @@ int sensor_0018_other_internal_hall_effect(e_ezlopi_actions_t action, l_ezlopi_i
return ret;
}
-static void __setup_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __setup_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
{
- char* device_name = NULL;
+ char *device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name)
- ASSIGN_DEVICE_NAME_V2(device, device_name);
+ ASSIGN_DEVICE_NAME_V2(device, device_name);
device->cloud_properties.device_id = ezlopi_cloud_generate_device_id();
device->cloud_properties.category = category_security_sensor;
device->cloud_properties.subcategory = subcategory_door;
@@ -94,7 +94,7 @@ static void __setup_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj
device->cloud_properties.device_type_id = NULL;
}
-static void __setup_item_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data)
+static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data)
{
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.has_getter = true;
@@ -110,22 +110,22 @@ static void __setup_item_properties(l_ezlopi_item_t* item, cJSON* cj_device, voi
item->user_arg = user_data;
}
-static int __prepare(void* arg)
+static int __prepare(void *arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
+ s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (arg && prep_arg->cjson_device)
{
- cJSON* cj_device = prep_arg->cjson_device;
- s_hall_data_t* user_data = (s_hall_data_t*)malloc(sizeof(s_hall_data_t));
+ cJSON *cj_device = prep_arg->cjson_device;
+ s_hall_data_t *user_data = (s_hall_data_t *)malloc(sizeof(s_hall_data_t));
if (user_data)
{
memset(user_data, 0, sizeof(s_hall_data_t));
- l_ezlopi_device_t* hall_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t *hall_device = ezlopi_device_add_device(cj_device);
if (hall_device)
{
__setup_device_cloud_properties(hall_device, cj_device);
- l_ezlopi_item_t* hall_item = ezlopi_device_add_item_to_device(hall_device, sensor_0018_other_internal_hall_effect);
+ l_ezlopi_item_t *hall_item = ezlopi_device_add_item_to_device(hall_device, sensor_0018_other_internal_hall_effect);
if (hall_item)
{
__setup_item_properties(hall_item, cj_device, user_data);
@@ -149,7 +149,7 @@ static int __prepare(void* arg)
return ret;
}
-static int __init(l_ezlopi_item_t* item)
+static int __init(l_ezlopi_item_t *item)
{
int ret = 0;
if (item)
@@ -159,127 +159,141 @@ static int __init(l_ezlopi_item_t* item)
#else
esp_err_t error = ESP_ERR_NOT_FOUND;
#endif
- if (error)
+ s_hall_data_t *user_data = (s_hall_data_t *)item->user_arg;
+ if (user_data)
{
- TRACE_E("Error 'sensor_door_init'. error: %s)", esp_err_to_name(error));
+ if (ESP_OK == error)
+ {
+ TRACE_I("Width configuration was successfully done!");
+ TRACE_W("Calibrating.....");
+ user_data->hall_state = "dw_is_closed";
+ xTaskCreate(__hall_calibration_task, "Hall_Calibration_Task", 2048, item, 1, NULL);
+ ret = 1;
+ }
+ else
+ {
+ TRACE_E("Error 'sensor_door_init'. error: %s)", esp_err_to_name(error));
+ ret = -1;
+ free(user_data);
+ user_data = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
else
- {
- TRACE_I("Width configuration was successfully done!");
- TRACE_W("Calibrating.....");
- s_hall_data_t* user_data = (s_hall_data_t*)item->user_arg;
- user_data->hall_state = "dw_is_closed";
- xTaskCreate(__hall_calibration_task, "Hall_Calibration_Task", 2048, item, 1, NULL);
- ret = 1;
- }
- if (0 == ret)
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static int __get_item_cjson(l_ezlopi_item_t* item, void* arg)
+static int __get_item_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
if (item && arg)
{
- s_hall_data_t* user_data = (s_hall_data_t*)item->user_arg;
-
- cJSON* cj_result = (cJSON*)arg;
- if (cj_result)
+ s_hall_data_t *user_data = (s_hall_data_t *)item->user_arg;
+ if (user_data)
{
- //------------------- POSSIBLE JSON ENUM LPGNTENTS ----------------------------------
- cJSON* json_array_enum = cJSON_CreateArray();
- if (NULL != json_array_enum)
+ cJSON *cj_result = (cJSON *)arg;
+ if (cj_result)
{
- for (uint8_t i = 0; i < HALL_DOOR_WINDOW_MAX; i++)
+ //------------------- POSSIBLE JSON ENUM LPGNTENTS ----------------------------------
+ cJSON *json_array_enum = cJSON_CreateArray();
+ if (NULL != json_array_enum)
{
- cJSON* json_value = cJSON_CreateString(hall_door_window_states[i]);
- if (NULL != json_value)
+ for (uint8_t i = 0; i < HALL_DOOR_WINDOW_MAX; i++)
{
- cJSON_AddItemToArray(json_array_enum, json_value);
+ cJSON *json_value = cJSON_CreateString(hall_door_window_states[i]);
+ if (NULL != json_value)
+ {
+ cJSON_AddItemToArray(json_array_enum, json_value);
+ }
}
+ cJSON_AddItemToObject(cj_result, ezlopi_enum_str, json_array_enum);
}
- cJSON_AddItemToObject(cj_result, "enum", json_array_enum);
+ //--------------------------------------------------------------------------------------
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, user_data->hall_state);
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, user_data->hall_state);
}
- //--------------------------------------------------------------------------------------
- cJSON_AddStringToObject(cj_result, "valueFormatted", user_data->hall_state);
- cJSON_AddStringToObject(cj_result, "value", user_data->hall_state);
+ ret = 1;
}
- ret = 1;
}
return ret;
}
-static int __get_value_cjson(l_ezlopi_item_t* item, void* arg)
+static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
if (item && arg)
{
- s_hall_data_t* user_data = (s_hall_data_t*)item->user_arg;
- cJSON* cj_result = (cJSON*)arg;
- if (cj_result)
+ s_hall_data_t *user_data = (s_hall_data_t *)item->user_arg;
+ if (user_data)
{
- cJSON_AddStringToObject(cj_result, "valueFormatted", user_data->hall_state);
- cJSON_AddStringToObject(cj_result, "value", user_data->hall_state);
+ cJSON *cj_result = (cJSON *)arg;
+ if (cj_result)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, user_data->hall_state);
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, user_data->hall_state);
+ }
+ ret = 1;
}
- ret = 1;
}
return ret;
}
-static int __notify(l_ezlopi_item_t* item)
+static int __notify(l_ezlopi_item_t *item)
{
int ret = 0;
if (item)
{
- s_hall_data_t* user_data = (s_hall_data_t*)item->user_arg;
- if (user_data->calibration_complete)
+ s_hall_data_t *user_data = (s_hall_data_t *)item->user_arg;
+ if (user_data)
{
- char* curret_value = NULL;
+ if (user_data->calibration_complete)
+ {
+ char *curret_value = NULL;
#ifdef CONFIG_IDF_TARGET_ESP32
- int sensor_data = hall_sensor_read();
+ int sensor_data = hall_sensor_read();
#else
- int sensor_data = 0;
+ int sensor_data = 0;
#endif
- TRACE_D(" Hall door value ; %d", sensor_data);
+ TRACE_D(" Hall door value ; %d", sensor_data);
- curret_value = ((fabs(user_data->Custom_stable_val - sensor_data) > 35) ? "dw_is_closed" : "dw_is_opened");
+ curret_value = ((fabs(user_data->Custom_stable_val - sensor_data) > 35) ? "dw_is_closed" : "dw_is_opened");
- if (curret_value != user_data->hall_state) // calls update only if there is change in state
- {
- user_data->hall_state = curret_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ if (curret_value != user_data->hall_state) // calls update only if there is change in state
+ {
+ user_data->hall_state = curret_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
+ ret = 1;
}
- ret = 1;
}
}
return ret;
}
-static void __hall_calibration_task(void* params) // calibrate task
+static void __hall_calibration_task(void *params) // calibrate task
{
- l_ezlopi_item_t* item = (l_ezlopi_item_t*)params;
+ l_ezlopi_item_t *item = (l_ezlopi_item_t *)params;
if (item)
{
- s_hall_data_t* user_data = (s_hall_data_t*)item->user_arg;
-
- float sensor_data = (float)hall_sensor_read();
- for (uint8_t i = 0; i < 10; i++)
+ s_hall_data_t *user_data = (s_hall_data_t *)item->user_arg;
+ if (user_data)
{
- sensor_data = (sensor_data * .8f) + (.2f * (float)hall_sensor_read());
- vTaskDelay(500);
+
+ float sensor_data = (float)hall_sensor_read();
+ for (uint8_t i = 0; i < 10; i++)
+ {
+ sensor_data = (sensor_data * .8f) + (.2f * (float)hall_sensor_read());
+ vTaskDelay(500);
+ }
+ user_data->Custom_stable_val = (int)sensor_data;
+ TRACE_W("Calibration Complete...... Stable_hall is : [%d]", user_data->Custom_stable_val);
+ user_data->calibration_complete = true;
}
- user_data->Custom_stable_val = (int)sensor_data;
- TRACE_W("Calibration Complete...... Stable_hall is : [%d]", user_data->Custom_stable_val);
- user_data->calibration_complete = true;
}
vTaskDelete(NULL);
}
diff --git a/ezlopi-sensors-devices/sensor-0019-digitalIn-PIR/sensor_0019_digitalIn_PIR.c b/ezlopi-sensors-devices/sensor-0019-digitalIn-PIR/sensor_0019_digitalIn_PIR.c
index 8be843951..0237468db 100644
--- a/ezlopi-sensors-devices/sensor-0019-digitalIn-PIR/sensor_0019_digitalIn_PIR.c
+++ b/ezlopi-sensors-devices/sensor-0019-digitalIn-PIR/sensor_0019_digitalIn_PIR.c
@@ -92,27 +92,23 @@ static int sensor_pir_init_v3(l_ezlopi_item_t *item)
.intr_type = item->interface.gpio.gpio_in.interrupt,
};
- ret = gpio_config(&io_conf);
- if (ESP_OK == ret)
+ if (ESP_OK == gpio_config(&io_conf))
{
- TRACE_S("PIR sensor initialize successfully.");
+ TRACE_I("PIR sensor initialize successfully.");
item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
gpio_isr_service_register_v3(item, sensor_pir_value_updated_from_device_v3, 200);
+ ret = 1;
}
else
{
TRACE_E("Error initializing PIR sensor, error: %s", esp_err_to_name(ret));
+ ret = -1;
}
- ret = 1;
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -182,7 +178,7 @@ static void sensor_pir_setup_item_properties_v3(l_ezlopi_item_t *item, cJSON *cj
item->interface.gpio.gpio_in.enable = true;
item->interface.gpio.gpio_in.mode = GPIO_MODE_INPUT;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "logic_inv", item->interface.gpio.gpio_in.invert);
CJSON_GET_VALUE_INT(cj_device, "pull_up", tmp_var);
item->interface.gpio.gpio_in.pull = tmp_var ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY;
diff --git a/ezlopi-sensors-devices/sensor-0020-other-2axis-joystick/sensor_0020_other_2axis_joystick.c b/ezlopi-sensors-devices/sensor-0020-other-2axis-joystick/sensor_0020_other_2axis_joystick.c
index 17645366b..8c6820ae8 100644
--- a/ezlopi-sensors-devices/sensor-0020-other-2axis-joystick/sensor_0020_other_2axis_joystick.c
+++ b/ezlopi-sensors-devices/sensor-0020-other-2axis-joystick/sensor_0020_other_2axis_joystick.c
@@ -25,13 +25,13 @@ typedef struct s_joystick_data
uint32_t adc_y;
} s_joystick_data_t;
-static int __prepare(void *arg);
-static int __init(l_ezlopi_item_t *item);
-static int __get_value_cjson(l_ezlopi_item_t *item, void *arg);
-static int __notify(l_ezlopi_item_t *item);
-static void __joystick_intr_callback(void *arg);
+static int __prepare(void* arg);
+static int __init(l_ezlopi_item_t* item);
+static int __get_value_cjson(l_ezlopi_item_t* item, void* arg);
+static int __notify(l_ezlopi_item_t* item);
+static void __joystick_intr_callback(void* arg);
-int sensor_0020_other_2axis_joystick(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0020_other_2axis_joystick(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
@@ -69,9 +69,9 @@ int sensor_0020_other_2axis_joystick(e_ezlopi_actions_t action, l_ezlopi_item_t
return ret;
}
-static void __setup_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __setup_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
ASSIGN_DEVICE_NAME_V2(device, device_name);
@@ -81,14 +81,14 @@ static void __setup_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj
device->cloud_properties.device_type = dev_type_device;
}
-static void __setup_item_cloud_properties(l_ezlopi_item_t *item, s_joystick_data_t *user_data)
+static void __setup_item_cloud_properties(l_ezlopi_item_t* item, s_joystick_data_t* user_data)
{
if (item)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = true;
item->cloud_properties.show = true;
- item->user_arg = (void *)user_data;
+ item->user_arg = (void*)user_data;
if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X] == item->cloud_properties.item_id)
{
@@ -96,13 +96,13 @@ static void __setup_item_cloud_properties(l_ezlopi_item_t *item, s_joystick_data
item->cloud_properties.value_type = value_type_electric_potential;
item->cloud_properties.scale = scales_milli_volt;
}
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
+ else if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
{
item->cloud_properties.item_name = ezlopi_item_name_voltage;
item->cloud_properties.value_type = value_type_electric_potential;
item->cloud_properties.scale = scales_milli_volt;
}
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH] == item->cloud_properties.item_id)
+ else if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH] == item->cloud_properties.item_id)
{
item->cloud_properties.item_name = ezlopi_item_name_switch;
item->cloud_properties.value_type = value_type_bool;
@@ -111,27 +111,27 @@ static void __setup_item_cloud_properties(l_ezlopi_item_t *item, s_joystick_data
}
}
-static void __setup_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __setup_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
if (item)
{
- s_joystick_data_t *user_data = (s_joystick_data_t *)item->user_arg;
+ s_joystick_data_t* user_data = (s_joystick_data_t*)item->user_arg;
if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X] == item->cloud_properties.item_id)
{
item->interface_type = EZLOPI_DEVICE_INTERFACE_ANALOG_INPUT;
- CJSON_GET_VALUE_INT(cj_device, "gpio1", item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, "gpio1", item->interface.adc.gpio_num);
item->interface.adc.resln_bit = 3;
}
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
+ else if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
{
item->interface_type = EZLOPI_DEVICE_INTERFACE_ANALOG_INPUT;
- CJSON_GET_VALUE_INT(cj_device, "gpio2", item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, "gpio2", item->interface.adc.gpio_num);
item->interface.adc.resln_bit = 3;
}
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH] == item->cloud_properties.item_id)
+ else if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH] == item->cloud_properties.item_id)
{
item->interface_type = EZLOPI_DEVICE_INTERFACE_DIGITAL_INPUT;
- CJSON_GET_VALUE_INT(cj_device, "gpio3", item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, "gpio3", item->interface.gpio.gpio_in.gpio_num);
item->interface.gpio.gpio_in.enable = true;
item->interface.gpio.gpio_in.interrupt = GPIO_INTR_ANYEDGE;
item->interface.gpio.gpio_in.pull = GPIO_PULLUP_ONLY;
@@ -139,16 +139,16 @@ static void __setup_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_d
}
}
-static int __prepare(void *arg)
+static int __prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *dev_prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* dev_prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (dev_prep_arg && (dev_prep_arg->cjson_device))
{
- cJSON *cj_device = dev_prep_arg->cjson_device;
+ cJSON* cj_device = dev_prep_arg->cjson_device;
if (cj_device)
{
- s_joystick_data_t *user_data = (s_joystick_data_t *)malloc(sizeof(s_joystick_data_t));
+ s_joystick_data_t* user_data = (s_joystick_data_t*)malloc(sizeof(s_joystick_data_t));
if (user_data)
{
memset(user_data, 0, sizeof(s_joystick_data_t));
@@ -157,14 +157,14 @@ static int __prepare(void *arg)
user_data->sensor_0020_joystick_item_ids[i] = ezlopi_cloud_generate_item_id();
}
- l_ezlopi_device_t *joystick_x_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* joystick_x_device = ezlopi_device_add_device(cj_device);
if (joystick_x_device)
{
joystick_x_device->cloud_properties.category = category_level_sensor;
joystick_x_device->cloud_properties.subcategory = subcategory_electricity;
__setup_device_cloud_properties(joystick_x_device, cj_device);
- l_ezlopi_item_t *joystick_x_item = ezlopi_device_add_item_to_device(joystick_x_device, sensor_0020_other_2axis_joystick);
+ l_ezlopi_item_t* joystick_x_item = ezlopi_device_add_item_to_device(joystick_x_device, sensor_0020_other_2axis_joystick);
if (joystick_x_item)
{
joystick_x_item->cloud_properties.item_id = user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X];
@@ -178,14 +178,14 @@ static int __prepare(void *arg)
ret = -1;
}
}
- l_ezlopi_device_t *joystick_y_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* joystick_y_device = ezlopi_device_add_device(cj_device);
if (joystick_y_device)
{
joystick_y_device->cloud_properties.category = category_level_sensor;
joystick_y_device->cloud_properties.subcategory = subcategory_electricity;
__setup_device_cloud_properties(joystick_y_device, cj_device);
- l_ezlopi_item_t *joystick_y_item = ezlopi_device_add_item_to_device(joystick_y_device, sensor_0020_other_2axis_joystick);
+ l_ezlopi_item_t* joystick_y_item = ezlopi_device_add_item_to_device(joystick_y_device, sensor_0020_other_2axis_joystick);
if (joystick_y_item)
{
joystick_y_item->cloud_properties.item_id = user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y];
@@ -199,14 +199,14 @@ static int __prepare(void *arg)
ret = -1;
}
}
- l_ezlopi_device_t *joystick_sw_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* joystick_sw_device = ezlopi_device_add_device(cj_device);
if (joystick_sw_device)
{
joystick_sw_device->cloud_properties.category = category_switch;
joystick_sw_device->cloud_properties.subcategory = subcategory_in_wall;
__setup_device_cloud_properties(joystick_sw_device, cj_device);
- l_ezlopi_item_t *joystick_sw_item = ezlopi_device_add_item_to_device(joystick_sw_device, sensor_0020_other_2axis_joystick);
+ l_ezlopi_item_t* joystick_sw_item = ezlopi_device_add_item_to_device(joystick_sw_device, sensor_0020_other_2axis_joystick);
if (joystick_sw_item)
{
joystick_sw_item->cloud_properties.item_id = user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH];
@@ -220,6 +220,10 @@ static int __prepare(void *arg)
ret = -1;
}
}
+ if (NULL == joystick_x_device && NULL == joystick_y_device && NULL == joystick_sw_device)
+ {
+ free(user_data);
+ }
}
}
}
@@ -227,97 +231,121 @@ static int __prepare(void *arg)
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- s_joystick_data_t *user_data = (s_joystick_data_t *)item->user_arg;
- if ((item->cloud_properties.item_id == user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X]) || (item->cloud_properties.item_id == user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y]))
+ s_joystick_data_t* user_data = (s_joystick_data_t*)item->user_arg;
+ if (user_data)
{
- if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ if ((item->cloud_properties.item_id == user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X]) ||
+ (item->cloud_properties.item_id == user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y]))
{
- TRACE_E("adc GPIO_NUM is %d", item->interface.adc.gpio_num);
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ {
+ TRACE_E("adc GPIO_NUM is %d", item->interface.adc.gpio_num);
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- }
- if (item->cloud_properties.item_id == user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH])
- {
- if (item->interface.gpio.gpio_in.enable)
+ else if (item->cloud_properties.item_id == user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH] &&
+ (item->interface.gpio.gpio_in.enable))
{
- TRACE_I("SW_GPIO_NUM is %d", item->interface.gpio.gpio_in.gpio_num);
-
- const gpio_config_t io_conf = {
- .pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
- .mode = GPIO_MODE_INPUT,
- .pull_up_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLUP_ONLY) ||
- (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLUP_ENABLE
- : GPIO_PULLUP_DISABLE,
- .pull_down_en = GPIO_PULLDOWN_DISABLE,
- .intr_type = item->interface.gpio.gpio_in.interrupt,
- };
-
- ret = gpio_config(&io_conf);
- if (ret)
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
{
- ret = 0;
- TRACE_E("Error initializing joystick switch");
+ TRACE_I("SW_GPIO_NUM is %d", item->interface.gpio.gpio_in.gpio_num);
+
+ const gpio_config_t io_conf = {
+ .pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
+ .mode = GPIO_MODE_INPUT,
+ .pull_up_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLUP_ONLY) ||
+ (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLUP_ENABLE
+ : GPIO_PULLUP_DISABLE,
+ .pull_down_en = GPIO_PULLDOWN_DISABLE,
+ .intr_type = item->interface.gpio.gpio_in.interrupt,
+ };
+
+ if (ESP_OK == gpio_config(&io_conf))
+ {
+ TRACE_I("Joystick switch initialize successfully.");
+ item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
+ // TRACE_D("Value is %d", (int)item->interface.gpio.gpio_in.value);
+ gpio_isr_service_register_v3(item, __joystick_intr_callback, 200);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Error initializing joystick switch");
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
else
{
- TRACE_S("Joystick switch initialize successfully.");
- item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
- TRACE_I("Value is %d", item->interface.gpio.gpio_in.value);
- gpio_isr_service_register_v3(item, __joystick_intr_callback, 200);
- ret = 1;
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
}
}
return ret;
}
-static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
+static int __get_value_cjson(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- cJSON *cj_result = (cJSON *)arg;
+ cJSON* cj_result = (cJSON*)arg;
if (cj_result && item)
{
- s_joystick_data_t *user_data = (s_joystick_data_t *)item->user_arg;
+ s_joystick_data_t* user_data = (s_joystick_data_t*)item->user_arg;
if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X] == item->cloud_properties.item_id)
{
- char *valueFormatted = ezlopi_valueformatter_uint32(user_data->adc_x);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
cJSON_AddNumberToObject(cj_result, "value", user_data->adc_x);
cJSON_AddStringToObject(cj_result, "scale", "milli_volt");
- free(valueFormatted);
+ char* valueFormatted = ezlopi_valueformatter_uint32(user_data->adc_x);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
+ else if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
{
- char *valueFormatted = ezlopi_valueformatter_uint32(user_data->adc_y);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
cJSON_AddNumberToObject(cj_result, "value", user_data->adc_y);
cJSON_AddStringToObject(cj_result, "scale", "milli_volt");
- free(valueFormatted);
+ char* valueFormatted = ezlopi_valueformatter_uint32(user_data->adc_y);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH] == item->cloud_properties.item_id)
+ else if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH] == item->cloud_properties.item_id)
{
cJSON_AddBoolToObject(cj_result, "value", ((0 == item->interface.gpio.gpio_in.value) ? true : false));
- const char *valueFormatted = ezlopi_valueformatter_bool((0 == item->interface.gpio.gpio_in.value) ? true : false);
+ const char* valueFormatted = ezlopi_valueformatter_bool((0 == item->interface.gpio.gpio_in.value) ? true : false);
cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
}
ret = 1;
@@ -325,34 +353,37 @@ static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __notify(l_ezlopi_item_t *item)
+static int __notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
if (ezlopi_item_name_switch != item->cloud_properties.item_name)
{
- s_joystick_data_t *user_data = (s_joystick_data_t *)item->user_arg;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
-
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X] == item->cloud_properties.item_id)
+ s_joystick_data_t* user_data = (s_joystick_data_t*)item->user_arg;
+ if (user_data)
{
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
- if (fabs(user_data->adc_x - ezlopi_analog_data.voltage) > 100)
+ s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+
+ if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X] == item->cloud_properties.item_id)
{
- user_data->adc_x = ezlopi_analog_data.voltage;
- // TRACE_S("X-axis value is %d and voltage is %d", ezlopi_analog_data.value, ezlopi_analog_data.voltage);
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X]);
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
+ if (fabs(user_data->adc_x - ezlopi_analog_data.voltage) > 100)
+ {
+ user_data->adc_x = ezlopi_analog_data.voltage;
+ // TRACE_S("X-axis value is %d and voltage is %d", ezlopi_analog_data.value, ezlopi_analog_data.voltage);
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_X]);
+ }
}
- }
- if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
- {
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
- if (fabs(user_data->adc_y - ezlopi_analog_data.voltage) > 100)
+ else if (user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y] == item->cloud_properties.item_id)
{
- user_data->adc_y = ezlopi_analog_data.voltage;
- // TRACE_S("Y-axis value is %d and voltage is %d", ezlopi_analog_data.value, ezlopi_analog_data.voltage);
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y]);
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
+ if (fabs(user_data->adc_y - ezlopi_analog_data.voltage) > 100)
+ {
+ user_data->adc_y = ezlopi_analog_data.voltage;
+ // TRACE_S("Y-axis value is %d and voltage is %d", ezlopi_analog_data.value, ezlopi_analog_data.voltage);
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_Y]);
+ }
}
}
}
@@ -361,14 +392,17 @@ static int __notify(l_ezlopi_item_t *item)
return ret;
}
-static void __joystick_intr_callback(void *arg)
+static void __joystick_intr_callback(void* arg)
{
- l_ezlopi_item_t *item = (l_ezlopi_item_t *)arg;
+ l_ezlopi_item_t* item = (l_ezlopi_item_t*)arg;
if (item)
{
- s_joystick_data_t *user_data = (s_joystick_data_t *)item->user_arg;
- item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
- item->interface.gpio.gpio_in.value = (false == item->interface.gpio.gpio_in.invert) ? (item->interface.gpio.gpio_in.value) : (!item->interface.gpio.gpio_in.value);
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH]);
+ s_joystick_data_t* user_data = (s_joystick_data_t*)item->user_arg;
+ if (user_data)
+ {
+ item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
+ item->interface.gpio.gpio_in.value = (false == item->interface.gpio.gpio_in.invert) ? (item->interface.gpio.gpio_in.value) : (!item->interface.gpio.gpio_in.value);
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_0020_joystick_item_ids[JOYSTICK_ITEM_ID_SWITCH]);
+ }
}
}
diff --git a/ezlopi-sensors-devices/sensor-0021-UART-MB1013/sensor_0021_UART_MB1013.c b/ezlopi-sensors-devices/sensor-0021-UART-MB1013/sensor_0021_UART_MB1013.c
index 637f9da69..11f252b88 100644
--- a/ezlopi-sensors-devices/sensor-0021-UART-MB1013/sensor_0021_UART_MB1013.c
+++ b/ezlopi-sensors-devices/sensor-0021-UART-MB1013/sensor_0021_UART_MB1013.c
@@ -65,30 +65,35 @@ int sensor_0021_UART_MB1013(e_ezlopi_actions_t action, l_ezlopi_item_t *item, vo
static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- char valueFormatted[20];
- if (item && arg && item->user_arg)
+ if (item && arg)
{
s_mb1013_args_t *mb1013_args = item->user_arg;
-
- cJSON *cj_result = (cJSON *)arg;
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, mb1013_args->current_value);
- snprintf(valueFormatted, 20, "%.2f", mb1013_args->current_value);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- ret = 1;
+ if (mb1013_args)
+ {
+ cJSON *cj_result = (cJSON *)arg;
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, mb1013_args->current_value);
+ char *valueFormatted = ezlopi_valueformatter_float(mb1013_args->current_value);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ ret = 1;
+ }
}
return ret;
}
static void __uart_data_upcall(uint8_t *buffer, uint32_t output_len, s_ezlopi_uart_object_handle_t uart_object_handle)
{
- if (buffer && output_len)
+ if (buffer && output_len && uart_object_handle)
{
- if (uart_object_handle)
+ l_ezlopi_item_t *item = (l_ezlopi_item_t *)uart_object_handle->arg;
+ if (item)
{
- l_ezlopi_item_t *item = (l_ezlopi_item_t *)uart_object_handle->arg;
- if (item && item->user_arg)
+ s_mb1013_args_t *s_mb1013_args = (s_mb1013_args_t *)item->user_arg;
+ if (s_mb1013_args)
{
- s_mb1013_args_t *s_mb1013_args = (s_mb1013_args_t *)item->user_arg;
int idx = 0;
TRACE_D("BUFFER-DATA-LEN: %d", output_len);
while (idx < output_len)
@@ -97,7 +102,7 @@ static void __uart_data_upcall(uint8_t *buffer, uint32_t output_len, s_ezlopi_ua
if ('R' == buffer[idx] && '\r' == buffer[idx + 5])
{
s_mb1013_args->current_value = atoi((const char *)&buffer[idx + 1]) / 10.0;
- TRACE_I("range: %f", s_mb1013_args->current_value);
+ TRACE_D("range: %f", s_mb1013_args->current_value);
break;
}
idx++;
@@ -112,21 +117,28 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.uart.tx) && GPIO_IS_VALID_GPIO(item->interface.uart.rx))
- {
- s_ezlopi_uart_object_handle_t ezlopi_uart_object_handle = ezlopi_uart_init(item->interface.uart.baudrate, item->interface.uart.tx, item->interface.uart.rx, __uart_data_upcall, item);
- item->interface.uart.channel = ezlopi_uart_get_channel(ezlopi_uart_object_handle);
- ret = 1;
- }
- if (0 == ret)
+ s_mb1013_args_t *mb1013_args = (s_mb1013_args_t *)item->user_arg;
+ if (mb1013_args)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.uart.tx) && GPIO_IS_VALID_GPIO(item->interface.uart.rx))
{
- free(item->user_arg);
+ s_ezlopi_uart_object_handle_t ezlopi_uart_object_handle = ezlopi_uart_init(item->interface.uart.baudrate, item->interface.uart.tx, item->interface.uart.rx, __uart_data_upcall, item);
+ item->interface.uart.channel = ezlopi_uart_get_channel(ezlopi_uart_object_handle);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
@@ -212,10 +224,13 @@ static int __notify(l_ezlopi_item_t *item)
if (item && item->user_arg)
{
s_mb1013_args_t *mb1013_args = (s_mb1013_args_t *)item->user_arg;
- if (abs(mb1013_args->current_value - mb1013_args->previous_value) > 0.2) // accuracy of 0.5cm (i.e. 5mm)
+ if (mb1013_args)
{
- ezlopi_device_value_updated_from_device_v3(item);
- mb1013_args->previous_value = mb1013_args->current_value;
+ if (abs(mb1013_args->current_value - mb1013_args->previous_value) > 0.2) // accuracy of 0.5cm (i.e. 5mm)
+ {
+ ezlopi_device_value_updated_from_device_v3(item);
+ mb1013_args->previous_value = mb1013_args->current_value;
+ }
}
}
diff --git a/ezlopi-sensors-devices/sensor-0023-digitalIn-touch-switch-TTP223B/sensor_0023_digitalIn_touch_switch_TTP223B.c b/ezlopi-sensors-devices/sensor-0023-digitalIn-touch-switch-TTP223B/sensor_0023_digitalIn_touch_switch_TTP223B.c
index 09ff06f3c..1778909be 100644
--- a/ezlopi-sensors-devices/sensor-0023-digitalIn-touch-switch-TTP223B/sensor_0023_digitalIn_touch_switch_TTP223B.c
+++ b/ezlopi-sensors-devices/sensor-0023-digitalIn-touch-switch-TTP223B/sensor_0023_digitalIn_touch_switch_TTP223B.c
@@ -59,13 +59,15 @@ int sensor_0023_digitalIn_touch_switch_TTP223B(e_ezlopi_actions_t action, l_ezlo
static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
-
- cJSON *param = (cJSON *)arg;
- if (param)
+ if (item)
{
- cJSON_AddBoolToObject(param, ezlopi_value_str, item->interface.gpio.gpio_in.value);
- const char *valueFormatted = ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? true : false);
- cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, valueFormatted);
+ cJSON *param = (cJSON *)arg;
+ if (param)
+ {
+ cJSON_AddBoolToObject(param, ezlopi_value_str, item->interface.gpio.gpio_in.value);
+ const char *valueFormatted = ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? true : false);
+ cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, valueFormatted);
+ }
}
return ret;
@@ -76,6 +78,7 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
+
if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
{
const gpio_config_t touch_switch_config = {
@@ -86,18 +89,21 @@ static int __init(l_ezlopi_item_t *item)
.intr_type = GPIO_INTR_POSEDGE,
};
- ESP_ERROR_CHECK(gpio_config(&touch_switch_config));
- gpio_isr_service_register_v3(item, touch_switch_callback, 200);
- ret = 1;
+ if (0 == gpio_config(&touch_switch_config)) // ESP_OK
+ {
+ gpio_isr_service_register_v3(item, touch_switch_callback, 200);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
@@ -163,7 +169,7 @@ static void __prepare_touch_switch_properties(l_ezlopi_item_t *item, cJSON *cj_d
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, ezlopi_ip_inv_str, item->interface.gpio.gpio_in.invert);
int val_ip = 0;
CJSON_GET_VALUE_INT(cj_device, ezlopi_val_ip_str, val_ip);
diff --git a/ezlopi-sensors-devices/sensor-0024-other-HCSR04/sensor_0024_other_HCSR04.c b/ezlopi-sensors-devices/sensor-0024-other-HCSR04/sensor_0024_other_HCSR04.c
index 93c65d6f1..8665a87a1 100644
--- a/ezlopi-sensors-devices/sensor-0024-other-HCSR04/sensor_0024_other_HCSR04.c
+++ b/ezlopi-sensors-devices/sensor-0024-other-HCSR04/sensor_0024_other_HCSR04.c
@@ -77,17 +77,21 @@ int sensor_0024_other_HCSR04_v3(e_ezlopi_actions_t action, l_ezlopi_item_t *item
static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
-
- s_ultrasonic_sensor_t *ultrasonic_sensor = (s_ultrasonic_sensor_t *)item->user_arg;
- cJSON *cj_param = (cJSON *)arg;
- char valueFormatted[20];
- if (cj_param && ultrasonic_sensor)
+ if (item)
{
- snprintf(valueFormatted, 20, "%d cm", ultrasonic_sensor->distance);
- cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_param, ezlopi_value_str, ultrasonic_sensor->distance);
+ cJSON *cj_param = (cJSON *)arg;
+ s_ultrasonic_sensor_t *ultrasonic_sensor = (s_ultrasonic_sensor_t *)item->user_arg;
+ if (cj_param && ultrasonic_sensor)
+ {
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, ultrasonic_sensor->distance);
+ char *valueFormatted = ezlopi_valueformatter_float(ultrasonic_sensor->distance);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
-
return ret;
}
@@ -109,56 +113,59 @@ static int __init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ s_ultrasonic_sensor_t *ultrasonic_HCSR04_sensor = (s_ultrasonic_sensor_t *)item->user_arg;
+ if (ultrasonic_HCSR04_sensor)
{
- const gpio_config_t io_conf = {
- .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
- .mode = GPIO_MODE_OUTPUT,
- .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLUP_ENABLE
- : GPIO_PULLUP_DISABLE,
- .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
- (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLDOWN_ENABLE
- : GPIO_PULLDOWN_DISABLE,
- .intr_type = GPIO_INTR_DISABLE,
- };
-
- gpio_config(&io_conf);
- ret = 1;
- }
-
- if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
- {
- const gpio_config_t io_conf = {
- .pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
- .mode = GPIO_MODE_INPUT,
- .pull_up_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLUP_ONLY) ||
- (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLUP_ENABLE
- : GPIO_PULLUP_DISABLE,
- .pull_down_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLDOWN_ONLY) ||
- (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
- ? GPIO_PULLDOWN_ENABLE
- : GPIO_PULLDOWN_DISABLE,
- .intr_type = (GPIO_PULLUP_ONLY == item->interface.gpio.gpio_in.pull)
- ? GPIO_INTR_POSEDGE
- : GPIO_INTR_NEGEDGE,
- };
-
- gpio_config(&io_conf);
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_OUTPUT_GPIO(item->interface.gpio.gpio_out.gpio_num))
+ {
+ const gpio_config_t io_conf = {
+ .pin_bit_mask = (1ULL << item->interface.gpio.gpio_out.gpio_num),
+ .mode = GPIO_MODE_OUTPUT,
+ .pull_up_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLUP_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLUP_ENABLE
+ : GPIO_PULLUP_DISABLE,
+ .pull_down_en = ((item->interface.gpio.gpio_out.pull == GPIO_PULLDOWN_ONLY) ||
+ (item->interface.gpio.gpio_out.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLDOWN_ENABLE
+ : GPIO_PULLDOWN_DISABLE,
+ .intr_type = GPIO_INTR_DISABLE,
+ };
+
+ ret = (0 == gpio_config(&io_conf)) ? 1 : -1;
+ }
+ else if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ {
+ const gpio_config_t io_conf = {
+ .pin_bit_mask = (1ULL << item->interface.gpio.gpio_in.gpio_num),
+ .mode = GPIO_MODE_INPUT,
+ .pull_up_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLUP_ONLY) ||
+ (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLUP_ENABLE
+ : GPIO_PULLUP_DISABLE,
+ .pull_down_en = ((item->interface.gpio.gpio_in.pull == GPIO_PULLDOWN_ONLY) ||
+ (item->interface.gpio.gpio_in.pull == GPIO_PULLUP_PULLDOWN))
+ ? GPIO_PULLDOWN_ENABLE
+ : GPIO_PULLDOWN_DISABLE,
+ .intr_type = (GPIO_PULLUP_ONLY == item->interface.gpio.gpio_in.pull)
+ ? GPIO_INTR_POSEDGE
+ : GPIO_INTR_NEGEDGE,
+ };
+
+ ret = (0 == gpio_config(&io_conf)) ? 1 : -1;
+ }
+ if (1 != ret)
{
- free(item->user_arg);
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
@@ -188,8 +195,8 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
item->cloud_properties.scale = scales_centi_meter;
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_out.gpio_num);
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio2_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_out.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio2_str, item->interface.gpio.gpio_in.gpio_num);
item->interface.gpio.gpio_out.enable = true;
item->interface.gpio.gpio_out.interrupt = GPIO_INTR_DISABLE;
diff --git a/ezlopi-sensors-devices/sensor-0025-digitalIn-LDR/sensor_0025_digitalIn_LDR.c b/ezlopi-sensors-devices/sensor-0025-digitalIn-LDR/sensor_0025_digitalIn_LDR.c
index 771e5b2e7..5e71bf414 100644
--- a/ezlopi-sensors-devices/sensor-0025-digitalIn-LDR/sensor_0025_digitalIn_LDR.c
+++ b/ezlopi-sensors-devices/sensor-0025-digitalIn-LDR/sensor_0025_digitalIn_LDR.c
@@ -85,19 +85,19 @@ static int __init(l_ezlopi_item_t *item)
if (ESP_OK == gpio_config(&io_conf))
{
item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
+ gpio_isr_service_register_v3(item, __value_updated_from_interrupt, 200);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
}
-
- gpio_isr_service_register_v3(item, __value_updated_from_interrupt, 200);
- ret = 1;
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -154,7 +154,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "logic_inv", item->interface.gpio.gpio_in.invert);
CJSON_GET_VALUE_INT(cj_device, ezlopi_val_ip_str, item->interface.gpio.gpio_in.value);
item->interface.gpio.gpio_in.enable = true;
diff --git a/ezlopi-sensors-devices/sensor-0026-ADC-LDR/sensor_0026_ADC_LDR.c b/ezlopi-sensors-devices/sensor-0026-ADC-LDR/sensor_0026_ADC_LDR.c
index 67a690cde..78ae78508 100644
--- a/ezlopi-sensors-devices/sensor-0026-ADC-LDR/sensor_0026_ADC_LDR.c
+++ b/ezlopi-sensors-devices/sensor-0026-ADC-LDR/sensor_0026_ADC_LDR.c
@@ -137,17 +137,15 @@ static int __init(l_ezlopi_item_t *item)
{
if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
{
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -172,8 +170,8 @@ static int _get_item_list(l_ezlopi_item_t *item, void *arg)
}
cJSON_AddItemToObject(cj_result, ezlopi_enum_str, json_array_enum);
}
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, ((char *)item->user_arg) ? item->user_arg : light_alarm_states[0]);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, ((char *)item->user_arg) ? item->user_arg : light_alarm_states[0]);
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, ((char *)item->user_arg) ? item->user_arg : "no_light");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, ((char *)item->user_arg) ? item->user_arg : "no_light");
ret = 1;
}
@@ -186,8 +184,8 @@ static int __get_value_cjson(l_ezlopi_item_t *item, void *arg)
cJSON *cj_result = (cJSON *)arg;
if (cj_result && item)
{
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, ((char *)item->user_arg) ? item->user_arg : light_alarm_states[0]);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, ((char *)item->user_arg) ? item->user_arg : light_alarm_states[0]);
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, ((char *)item->user_arg) ? item->user_arg : "no_light");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, ((char *)item->user_arg) ? item->user_arg : "no_light");
ret = 1;
}
return ret;
@@ -204,11 +202,11 @@ static int __notify(l_ezlopi_item_t *item)
char *curr_ldr_state = NULL;
if (((float)(4096 - ezlopi_analog_data.value) / 4096.0f) > 0.5f) // pot_val : [100% - 30%]
{
- curr_ldr_state = (char *)light_alarm_states[0]; // no light
+ curr_ldr_state = "no_light"; // no light
}
else
{
- curr_ldr_state = (char *)light_alarm_states[1]; // light detected
+ curr_ldr_state = "light_detected"; // light detected
}
if (curr_ldr_state != (char *)item->user_arg)
{
diff --git a/ezlopi-sensors-devices/sensor-0027-ADC-waterLeak/sensor_0027_ADC_waterLeak.c b/ezlopi-sensors-devices/sensor-0027-ADC-waterLeak/sensor_0027_ADC_waterLeak.c
index f68385030..4247ad99c 100644
--- a/ezlopi-sensors-devices/sensor-0027-ADC-waterLeak/sensor_0027_ADC_waterLeak.c
+++ b/ezlopi-sensors-devices/sensor-0027-ADC-waterLeak/sensor_0027_ADC_waterLeak.c
@@ -13,7 +13,6 @@
#include "sensor_0027_ADC_waterLeak.h"
-
const char *water_leak_alarm_states[] = {
"no_water_leak",
"water_leak_detected",
@@ -94,7 +93,7 @@ static void prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_devic
static void prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device)
{
item->interface_type = EZLOPI_DEVICE_INTERFACE_ANALOG_INPUT;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.adc.gpio_num);
item->interface.adc.resln_bit = 3;
}
@@ -214,17 +213,15 @@ static int __init(l_ezlopi_item_t *item)
{
if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
{
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
diff --git a/ezlopi-sensors-devices/sensor-0028-other-GY61/sensor_0028_other_GY61.c b/ezlopi-sensors-devices/sensor-0028-other-GY61/sensor_0028_other_GY61.c
index 8ec9438b7..f55493461 100644
--- a/ezlopi-sensors-devices/sensor-0028-other-GY61/sensor_0028_other_GY61.c
+++ b/ezlopi-sensors-devices/sensor-0028-other-GY61/sensor_0028_other_GY61.c
@@ -1,6 +1,5 @@
#include
#include "ezlopi_util_trace.h"
-
#include "ezlopi_core_timer.h"
#include "ezlopi_core_cloud.h"
@@ -30,14 +29,14 @@ typedef struct s_gy61_data
#define esp32S3_convert_mV_to_G(temp_vol) (((6.0f / 3000.0f) * (temp_vol - 100)) - 3.0f)
#endif
-static int __0028_prepare(void *arg);
-static int __0028_init(l_ezlopi_item_t *item);
-static int __0028_get_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __0028_notify(l_ezlopi_item_t *item);
+static int __0028_prepare(void* arg);
+static int __0028_init(l_ezlopi_item_t* item);
+static int __0028_get_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __0028_notify(l_ezlopi_item_t* item);
-static float __update_gy61_axis_value(l_ezlopi_item_t *item);
+static float __update_gy61_axis_value(l_ezlopi_item_t* item);
//--------------------------------------------------------------------------------------------------------
-int sensor_0028_other_GY61(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0028_other_GY61(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -71,9 +70,9 @@ int sensor_0028_other_GY61(e_ezlopi_actions_t action, l_ezlopi_item_t *item, voi
return ret;
}
//-------------------------------------------------------------------------------------------------------------------------
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
- char *dev_name = NULL;
+ char* dev_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", dev_name);
ASSIGN_DEVICE_NAME_V2(device, dev_name);
device->cloud_properties.device_id = ezlopi_cloud_generate_device_id();
@@ -83,7 +82,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.info = NULL;
device->cloud_properties.device_type = dev_type_sensor;
}
-static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_data)
+static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, void* user_data)
{
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.has_getter = true;
@@ -95,7 +94,7 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_da
item->user_arg = user_data;
}
-static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
if (item && cj_device)
{
@@ -103,54 +102,54 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj
item->interface.adc.resln_bit = 3;
if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
{
- CJSON_GET_VALUE_INT(cj_device, "gpio1", item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.adc.gpio_num);
TRACE_S("Accel X-axis gpio1: %d ", item->interface.adc.gpio_num);
}
else if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
{
- CJSON_GET_VALUE_INT(cj_device, "gpio2", item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio2_str, item->interface.adc.gpio_num);
TRACE_S("Accel Y-axis gpio2: %d ", item->interface.adc.gpio_num);
}
else if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
{
- CJSON_GET_VALUE_INT(cj_device, "gpio3", item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio3_str, item->interface.adc.gpio_num);
TRACE_S("Accel Z-axis gpio3: %d ", item->interface.adc.gpio_num);
}
}
}
//-------------------------------------------------------------------------------------------------------------------------
-static int __0028_prepare(void *arg)
+static int __0028_prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* device_prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
- cJSON *cj_device = device_prep_arg->cjson_device;
+ cJSON* cj_device = device_prep_arg->cjson_device;
- s_gy61_data_t *gy61_value = (s_gy61_data_t *)malloc(sizeof(s_gy61_data_t));
+ s_gy61_data_t* gy61_value = (s_gy61_data_t*)malloc(sizeof(s_gy61_data_t));
if (NULL != gy61_value)
{
memset(gy61_value, 0, sizeof(s_gy61_data_t));
- l_ezlopi_device_t *gy61_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* gy61_device = ezlopi_device_add_device(cj_device);
if (gy61_device)
{
__prepare_device_cloud_properties(gy61_device, cj_device);
- l_ezlopi_item_t *gy61_item_x = ezlopi_device_add_item_to_device(gy61_device, sensor_0028_other_GY61);
+ l_ezlopi_item_t* gy61_item_x = ezlopi_device_add_item_to_device(gy61_device, sensor_0028_other_GY61);
if (gy61_item_x)
{
gy61_item_x->cloud_properties.item_name = ezlopi_item_name_acceleration_x_axis;
__prepare_item_cloud_properties(gy61_item_x, gy61_value);
__prepare_item_interface_properties(gy61_item_x, cj_device);
}
- l_ezlopi_item_t *gy61_item_y = ezlopi_device_add_item_to_device(gy61_device, sensor_0028_other_GY61);
+ l_ezlopi_item_t* gy61_item_y = ezlopi_device_add_item_to_device(gy61_device, sensor_0028_other_GY61);
if (gy61_item_y)
{
gy61_item_y->cloud_properties.item_name = ezlopi_item_name_acceleration_y_axis;
__prepare_item_cloud_properties(gy61_item_y, gy61_value);
__prepare_item_interface_properties(gy61_item_y, cj_device);
}
- l_ezlopi_item_t *gy61_item_z = ezlopi_device_add_item_to_device(gy61_device, sensor_0028_other_GY61);
+ l_ezlopi_item_t* gy61_item_z = ezlopi_device_add_item_to_device(gy61_device, sensor_0028_other_GY61);
if (gy61_item_z)
{
gy61_item_z->cloud_properties.item_name = ezlopi_item_name_acceleration_z_axis;
@@ -176,61 +175,86 @@ static int __0028_prepare(void *arg)
return ret;
}
-static int __0028_init(l_ezlopi_item_t *item)
+static int __0028_init(l_ezlopi_item_t* item)
{
int ret = 0;
- if (NULL != item)
+ if (item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
- {
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
- }
- if (0 == ret)
+ s_gy61_data_t *user_data = (s_gy61_data_t *)item->user_arg;
+ if (user_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ {
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
-static int __0028_get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __0028_get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
if (item && arg)
{
- cJSON *cj_result = (cJSON *)arg;
+ cJSON* cj_result = (cJSON*)arg;
if (cj_result)
{
- s_gy61_data_t *user_data = ((s_gy61_data_t *)item->user_arg);
+ s_gy61_data_t* user_data = ((s_gy61_data_t*)item->user_arg);
if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
{
- char *valueFormatted = ezlopi_valueformatter_float(user_data->x_data);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
cJSON_AddNumberToObject(cj_result, "value", (user_data->x_data));
- // TRACE_S("x-axis-G : %.2f", user_data->x_data);
- free(valueFormatted);
+ // TRACE_I("x-axis-G : %.2f", user_data->x_data);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->x_data);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
{
- char *valueFormatted = ezlopi_valueformatter_float(user_data->y_data);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
cJSON_AddNumberToObject(cj_result, "value", (user_data->y_data));
- // TRACE_S("y-axis-G : %.2f", user_data->y_data);
- free(valueFormatted);
+ // TRACE_I("y-axis-G : %.2f", user_data->y_data);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->y_data);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
{
- char *valueFormatted = ezlopi_valueformatter_float(user_data->z_data);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
cJSON_AddNumberToObject(cj_result, "value", (user_data->z_data));
- // TRACE_S("z-axis-G : %.2f", user_data->z_data);
- free(valueFormatted);
+ // TRACE_I("z-axis-G : %.2f", user_data->z_data);
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->z_data);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
ret = 1;
}
@@ -238,52 +262,55 @@ static int __0028_get_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __0028_notify(l_ezlopi_item_t *item)
+static int __0028_notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
s_gy61_data_t *user_data = (s_gy61_data_t *)item->user_arg;
- float new_value = 0;
- if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
+ if (user_data)
{
- new_value = __update_gy61_axis_value(item);
-
- if (fabs((user_data->x_data) - new_value) > 0.5)
+ float new_value = 0;
+ if (ezlopi_item_name_acceleration_x_axis == item->cloud_properties.item_name)
{
- user_data->x_data = new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ new_value = __update_gy61_axis_value(item);
+
+ if (fabs((user_data->x_data) - new_value) > 0.5)
+ {
+ user_data->x_data = new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
- {
- new_value = __update_gy61_axis_value(item);
- if (fabs((user_data->y_data) - new_value) > 0.5)
+ if (ezlopi_item_name_acceleration_y_axis == item->cloud_properties.item_name)
{
- user_data->y_data = new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ new_value = __update_gy61_axis_value(item);
+ if (fabs((user_data->y_data) - new_value) > 0.5)
+ {
+ user_data->y_data = new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
- {
- new_value = __update_gy61_axis_value(item);
- if (fabs((user_data->z_data) - new_value) > 0.5)
+ if (ezlopi_item_name_acceleration_z_axis == item->cloud_properties.item_name)
{
- user_data->z_data = new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ new_value = __update_gy61_axis_value(item);
+ if (fabs((user_data->z_data) - new_value) > 0.5)
+ {
+ user_data->z_data = new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
+ ret = 1;
}
- ret = 1;
}
return ret;
}
-static float __update_gy61_axis_value(l_ezlopi_item_t *item)
+static float __update_gy61_axis_value(l_ezlopi_item_t* item)
{
float G_data = 0;
if (item)
{
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
int temp_vol = ezlopi_analog_data.voltage;
#if (CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3)
diff --git a/ezlopi-sensors-devices/sensor-0029-I2C-GXHTC3/sensor_0029_I2C_GXHTC3.c b/ezlopi-sensors-devices/sensor-0029-I2C-GXHTC3/sensor_0029_I2C_GXHTC3.c
index 803e9dec5..709370998 100644
--- a/ezlopi-sensors-devices/sensor-0029-I2C-GXHTC3/sensor_0029_I2C_GXHTC3.c
+++ b/ezlopi-sensors-devices/sensor-0029-I2C-GXHTC3/sensor_0029_I2C_GXHTC3.c
@@ -39,40 +39,28 @@ static int gxhtc3_sensor_init(l_ezlopi_item_t *item)
gxhtce_val->gxhtc3 = GXHTC3_init(item->interface.i2c_master.channel, item->interface.i2c_master.address);
if (gxhtce_val->gxhtc3)
{
+ ret = 1;
if (gxhtce_val->gxhtc3->id.status)
{
TRACE_E("GXHTC3 Chip ID: 0x%x", gxhtce_val->gxhtc3->id.id);
}
else
{
- ret = -1;
TRACE_E("GXHTC3 Chip ID not ready!");
+ ret = -1;
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
}
}
- else
- {
- ret = 1;
- }
}
else
{
- ret = 1;
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
}
- // if (-1 == ret)
- // {
- // ret = -1;
- // if (item->user_arg)
- // {
- // free(item->user_arg);
- // item->user_arg = NULL;
- // }
- // }
- }
- else
- {
- ret = 1;
}
return ret;
@@ -90,7 +78,7 @@ static int gxhtc3_sensor_init(l_ezlopi_item_t *item)
// char *valueFormatted = ezlopi_valueformatter_float(value_ptr->temperature);
// if (valueFormatted)
// {
-// cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
+// cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
// free(valueFormatted);
// }
// cJSON_AddStringToObject(cj_result, ezlopi_scale_str, scales_celsius);
@@ -151,7 +139,7 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
char *valueFormatted = ezlopi_valueformatter_float(value_ptr->temperature);
if (valueFormatted)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
free(valueFormatted);
}
cJSON_AddStringToObject(cj_result, ezlopi_scale_str, scales_celsius);
@@ -162,7 +150,7 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
char *valueFormatted = ezlopi_valueformatter_float(value_ptr->humidity);
if (valueFormatted)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueformatted_str, valueFormatted);
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
free(valueFormatted);
}
cJSON_AddStringToObject(cj_result, ezlopi_scale_str, scales_percent);
@@ -293,7 +281,7 @@ static int __prepare(void *arg)
if (value_ptr)
{
memset(value_ptr, 0, sizeof(s_gxhtc3_value_t));
-
+
l_ezlopi_device_t *device_temp = ezlopi_device_add_device(prep_arg->cjson_device);
if (device_temp)
{
@@ -309,7 +297,7 @@ static int __prepare(void *arg)
else
{
ezlopi_device_free_device(device_temp);
- free(value_ptr);
+ free(value_ptr); // set to NULL?
ret = -1;
}
}
@@ -323,7 +311,7 @@ static int __prepare(void *arg)
item_humdity->cloud_properties.device_id = device_hum->cloud_properties.device_id;
__prepare_humidity_item_properties(item_humdity, prep_arg->cjson_device);
value_ptr->humidity = 65536.0f;
- item_humdity->user_arg = (void *)value_ptr;
+ item_humdity->user_arg = (void *)value_ptr; // affected if 'value_pts' is already freed?
}
else
{
diff --git a/ezlopi-sensors-devices/sensor-0030-oneWire-DS18B20/sensor_0030_oneWire_DS18B20.c b/ezlopi-sensors-devices/sensor-0030-oneWire-DS18B20/sensor_0030_oneWire_DS18B20.c
index f179228d0..a011e6b75 100644
--- a/ezlopi-sensors-devices/sensor-0030-oneWire-DS18B20/sensor_0030_oneWire_DS18B20.c
+++ b/ezlopi-sensors-devices/sensor-0030-oneWire-DS18B20/sensor_0030_oneWire_DS18B20.c
@@ -13,20 +13,20 @@
#include "ds18b20_onewire.h"
#include "sensor_0030_oneWire_DS18B20.h"
-static int __prepare(void* arg);
-static int __init(l_ezlopi_item_t* item);
-static int __notify(l_ezlopi_item_t* item);
-static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __prepare(void *arg);
+static int __init(l_ezlopi_item_t *item);
+static int __notify(l_ezlopi_item_t *item);
+static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
-static esp_err_t ds18b20_write_data(uint8_t* data, uint32_t gpio_pin);
-static esp_err_t ds18b20_read_data(uint8_t* data, uint32_t gpio_pin);
+static esp_err_t ds18b20_write_data(uint8_t *data, uint32_t gpio_pin);
+static esp_err_t ds18b20_read_data(uint8_t *data, uint32_t gpio_pin);
static bool ds18b20_reset_line(uint32_t gpio_pin);
static esp_err_t ds18b20_write_to_scratchpad(uint8_t th_val, uint8_t tl_val, uint8_t resolution, uint8_t gpio_pin);
static bool ds18b20_recognize_device(uint32_t gpio_pin);
-static esp_err_t ds18b20_get_temperature_data(double* temperature_data, uint32_t gpio_pin);
-static uint8_t ds18b20_calculate_crc(const uint8_t* data, uint8_t len);
+static esp_err_t ds18b20_get_temperature_data(double *temperature_data, uint32_t gpio_pin);
+static uint8_t ds18b20_calculate_crc(const uint8_t *data, uint8_t len);
-int sensor_0030_oneWire_DS18B20(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
+int sensor_0030_oneWire_DS18B20(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
{
int ret = 0;
switch (action)
@@ -60,10 +60,10 @@ int sensor_0030_oneWire_DS18B20(e_ezlopi_actions_t action, l_ezlopi_item_t* item
return ret;
}
-static int __notify(l_ezlopi_item_t* item)
+static int __notify(l_ezlopi_item_t *item)
{
int ret = 0;
- double* temperature_prev_value = (double*)item->user_arg;
+ double *temperature_prev_value = (double *)item->user_arg;
double temperature_current_value = 0.00;
esp_err_t error = ds18b20_get_temperature_data(&temperature_current_value, item->interface.onewire_master.onewire_pin);
if (ESP_OK == error)
@@ -79,16 +79,16 @@ static int __notify(l_ezlopi_item_t* item)
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
+static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
if (item && arg)
{
- cJSON* cj_result = (cJSON*)arg;
- double* temperatue_value = (double*)item->user_arg;
+ cJSON *cj_result = (cJSON *)arg;
+ double *temperatue_value = (double *)item->user_arg;
cJSON_AddNumberToObject(cj_result, ezlopi_value_str, *temperatue_value);
- char* valueFormatted = ezlopi_valueformatter_double(*temperatue_value);
+ char *valueFormatted = ezlopi_valueformatter_double(*temperatue_value);
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
free(valueFormatted);
cJSON_AddStringToObject(cj_result, ezlopi_scale_str, scales_celsius);
@@ -96,47 +96,42 @@ static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
return ret;
}
-static int __init(l_ezlopi_item_t* item)
+static int __init(l_ezlopi_item_t *item)
{
int ret = -1;
- if (item)
+ if ((item) && (item->interface.onewire_master.enable))
{
- if (item->interface.onewire_master.enable)
+ if (GPIO_IS_VALID_GPIO(item->interface.onewire_master.onewire_pin) &&
+ ds18b20_reset_line(item->interface.onewire_master.onewire_pin))
{
- if (ds18b20_reset_line(item->interface.onewire_master.onewire_pin))
+ if (ds18b20_recognize_device(item->interface.onewire_master.onewire_pin))
{
- if (ds18b20_recognize_device(item->interface.onewire_master.onewire_pin))
- {
- double* temperature_prev_value = (double*)item->user_arg;
- TRACE_S("Providing initial settings to DS18B20");
- ds18b20_write_to_scratchpad(DS18B20_TH_HIGHER_THRESHOLD, DS18B20_TL_LOWER_THRESHOLD, 12, item->interface.onewire_master.onewire_pin);
- ds18b20_get_temperature_data(temperature_prev_value, item->interface.onewire_master.onewire_pin);
- ret = 1;
- }
- else
- {
- ret = -1;
- }
+ double *temperature_prev_value = (double *)item->user_arg;
+ TRACE_D("Providing initial settings to DS18B20");
+ ds18b20_write_to_scratchpad(DS18B20_TH_HIGHER_THRESHOLD, DS18B20_TL_LOWER_THRESHOLD, 12, item->interface.onewire_master.onewire_pin);
+ ds18b20_get_temperature_data(temperature_prev_value, item->interface.onewire_master.onewire_pin);
+ ret = 1;
}
else
{
ret = -1;
- }
-
- if (-1 == ret)
- {
if (item->user_arg)
{
- free(item->user_arg);
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
}
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
-static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -150,7 +145,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON*
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
+static void __prepare_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.show = true;
@@ -163,32 +158,32 @@ static void __prepare_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
item->interface_type = EZLOPI_DEVICE_INTERFACE_ONEWIRE_MASTER;
item->interface.onewire_master.enable = true;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.onewire_master.onewire_pin);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.onewire_master.onewire_pin);
}
-static int __prepare(void* arg)
+static int __prepare(void *arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
+ s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (prep_arg && prep_arg->cjson_device)
{
- l_ezlopi_device_t* device = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t *device = ezlopi_device_add_device(prep_arg->cjson_device);
if (device)
{
__prepare_device_cloud_properties(device, prep_arg->cjson_device);
- l_ezlopi_item_t* item_temperature = ezlopi_device_add_item_to_device(device, sensor_0030_oneWire_DS18B20);
+ l_ezlopi_item_t *item_temperature = ezlopi_device_add_item_to_device(device, sensor_0030_oneWire_DS18B20);
if (item_temperature)
{
item_temperature->cloud_properties.device_id = device->cloud_properties.device_id;
__prepare_item_properties(item_temperature, prep_arg->cjson_device);
- double* temperature_value = (double*)malloc(sizeof(double));
+ double *temperature_value = (double *)malloc(sizeof(double));
if (temperature_value)
{
memset(temperature_value, 0, sizeof(double));
*temperature_value = 65536.0f;
- item_temperature->user_arg = (void*)temperature_value;
+ item_temperature->user_arg = (void *)temperature_value;
}
ret = 1;
}
@@ -203,14 +198,14 @@ static int __prepare(void* arg)
return ret;
}
-static esp_err_t ds18b20_write_data(uint8_t* data, uint32_t gpio_pin)
+static esp_err_t ds18b20_write_data(uint8_t *data, uint32_t gpio_pin)
{
esp_err_t error = ESP_OK;
error = one_wire_write_byte_to_line(data, gpio_pin);
return error;
}
-static esp_err_t ds18b20_read_data(uint8_t* data, uint32_t gpio_pin)
+static esp_err_t ds18b20_read_data(uint8_t *data, uint32_t gpio_pin)
{
esp_err_t error = ESP_OK;
error = one_wire_read_byte_from_line(data, gpio_pin);
@@ -283,7 +278,7 @@ static bool ds18b20_recognize_device(uint32_t gpio_pin)
return (data_from_ds18b20 == DS18B20_FAMILY_CODE) ? true : false;
}
-static esp_err_t ds18b20_get_temperature_data(double* temperature_data, uint32_t gpio_pin)
+static esp_err_t ds18b20_get_temperature_data(double *temperature_data, uint32_t gpio_pin)
{
esp_err_t error = ESP_OK;
uint8_t ds18b20_skip_rom = DS18B20_ROM_COMMAND_SKIP_ROM;
@@ -351,7 +346,7 @@ static esp_err_t ds18b20_get_temperature_data(double* temperature_data, uint32_t
return error;
}
-static uint8_t ds18b20_calculate_crc(const uint8_t* data, uint8_t len)
+static uint8_t ds18b20_calculate_crc(const uint8_t *data, uint8_t len)
{
uint8_t crc = 0;
uint8_t length = len;
diff --git a/ezlopi-sensors-devices/sensor-0031-other-JSNSR04T/sensor_0031_other_JSNSR04T.c b/ezlopi-sensors-devices/sensor-0031-other-JSNSR04T/sensor_0031_other_JSNSR04T.c
index bd2586bf1..0144bb0f0 100644
--- a/ezlopi-sensors-devices/sensor-0031-other-JSNSR04T/sensor_0031_other_JSNSR04T.c
+++ b/ezlopi-sensors-devices/sensor-0031-other-JSNSR04T/sensor_0031_other_JSNSR04T.c
@@ -12,12 +12,12 @@
#include "jsn_sr04t.h"
#include "sensor_0031_other_JSNSR04T.h"
-static int __prepare(void *arg);
-static int __init(l_ezlopi_item_t *item);
-static int __notify(l_ezlopi_item_t *item);
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
+static int __prepare(void* arg);
+static int __init(l_ezlopi_item_t* item);
+static int __notify(l_ezlopi_item_t* item);
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
-int sensor_0031_other_JSNSR04T(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0031_other_JSNSR04T(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -51,19 +51,18 @@ int sensor_0031_other_JSNSR04T(e_ezlopi_actions_t action, l_ezlopi_item_t *item,
return ret;
}
-static int __notify(l_ezlopi_item_t *item)
+static int __notify(l_ezlopi_item_t* item)
{
return ezlopi_device_value_updated_from_device_v3(item);
}
-static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
-
if (item && arg)
{
- cJSON *cj_result = (cJSON *)arg;
- jsn_sr04t_config_t *tmp_config = (jsn_sr04t_config_t *)item->user_arg;
+ cJSON* cj_result = (cJSON*)arg;
+ jsn_sr04t_config_t* tmp_config = (jsn_sr04t_config_t*)item->user_arg;
if (tmp_config)
{
jsn_sr04t_data_t jsn_sr04t_data;
@@ -76,8 +75,11 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON_AddNumberToObject(cj_result, ezlopi_value_str, distance);
char *valueFormatted = ezlopi_valueformatter_float(distance);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
cJSON_AddStringToObject(cj_result, ezlopi_scale_str, scales_meter);
ret = 1;
}
@@ -91,13 +93,12 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
-
if (item)
{
- jsn_sr04t_config_t *jsn_sr04t_config = malloc(sizeof(jsn_sr04t_config_t));
+ jsn_sr04t_config_t* jsn_sr04t_config = malloc(sizeof(jsn_sr04t_config_t));
if (jsn_sr04t_config)
{
jsn_sr04t_config_t tmp_config = (jsn_sr04t_config_t)JSN_SR04T_CONFIG_DEFAULT();
@@ -106,7 +107,7 @@ static int __init(l_ezlopi_item_t *item)
tmp_config.rmt_channel = 4;
memcpy(jsn_sr04t_config, &tmp_config, sizeof(jsn_sr04t_config_t));
- item->user_arg = (void *)jsn_sr04t_config;
+ item->user_arg = (void*)jsn_sr04t_config;
if (ESP_OK == init_JSN_SR04T(jsn_sr04t_config))
{
@@ -118,15 +119,21 @@ static int __init(l_ezlopi_item_t *item)
ret = -1;
item->user_arg = NULL;
free(jsn_sr04t_config);
+ ezlopi_device_free_device_by_item(item);
TRACE_E("JSN_SR04T not initializeed");
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -140,7 +147,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
@@ -152,11 +159,11 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
}
-static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
item->interface_type = EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio_out_str, item->interface.gpio.gpio_out.gpio_num);
item->interface.gpio.gpio_out.enable = true;
item->interface.gpio.gpio_out.interrupt = GPIO_INTR_DISABLE;
item->interface.gpio.gpio_out.invert = EZLOPI_GPIO_LOGIC_NONINVERTED;
@@ -164,7 +171,7 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj
item->interface.gpio.gpio_out.pull = GPIO_PULLDOWN_ONLY;
item->interface.gpio.gpio_out.value = 0;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_in_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio_in_str, item->interface.gpio.gpio_in.gpio_num);
item->interface.gpio.gpio_in.enable = true;
item->interface.gpio.gpio_in.interrupt = GPIO_INTR_DISABLE;
item->interface.gpio.gpio_in.invert = EZLOPI_GPIO_LOGIC_NONINVERTED;
@@ -173,18 +180,18 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj
item->interface.gpio.gpio_in.value = 0;
}
-static int __prepare(void *arg)
+static int __prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg && prep_arg->cjson_device)
{
- l_ezlopi_device_t *device = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t* device = ezlopi_device_add_device(prep_arg->cjson_device);
if (device)
{
__prepare_device_cloud_properties(device, prep_arg->cjson_device);
- l_ezlopi_item_t *item_temperature = ezlopi_device_add_item_to_device(device, sensor_0031_other_JSNSR04T);
+ l_ezlopi_item_t* item_temperature = ezlopi_device_add_item_to_device(device, sensor_0031_other_JSNSR04T);
if (item_temperature)
{
__prepare_item_cloud_properties(item_temperature, prep_arg->cjson_device);
diff --git a/ezlopi-sensors-devices/sensor-0032-ADC-soilMoisture/sensor_0032_ADC_soilMoisture.c b/ezlopi-sensors-devices/sensor-0032-ADC-soilMoisture/sensor_0032_ADC_soilMoisture.c
index a0228b42b..d7fb70fda 100644
--- a/ezlopi-sensors-devices/sensor-0032-ADC-soilMoisture/sensor_0032_ADC_soilMoisture.c
+++ b/ezlopi-sensors-devices/sensor-0032-ADC-soilMoisture/sensor_0032_ADC_soilMoisture.c
@@ -80,12 +80,18 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
cJSON *cj_result = (cJSON *)arg;
s_ezlopi_analog_data_t *soil_moisture_data = (s_ezlopi_analog_data_t *)item->user_arg;
- double percent_data = ((4095 - soil_moisture_data->value) / 4095.0) * 100;
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, percent_data);
- char *valueFormatted = ezlopi_valueformatter_double(percent_data);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
- ret = 1;
+ if (soil_moisture_data)
+ {
+ double percent_data = ((4095 - soil_moisture_data->value) / 4095.0) * 100;
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, percent_data);
+ char *valueFormatted = ezlopi_valueformatter_double(percent_data);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ ret = 1;
+ }
}
return ret;
}
@@ -97,17 +103,15 @@ static int __init(l_ezlopi_item_t *item)
{
if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
{
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -146,7 +150,7 @@ static void __prepare_item_properties(l_ezlopi_item_t *item, cJSON *cj_device, v
item->interface_type = EZLOPI_DEVICE_INTERFACE_ANALOG_INPUT;
item->interface.adc.resln_bit = 3;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.adc.gpio_num);
item->user_arg = user_arg;
}
diff --git a/ezlopi-sensors-devices/sensor-0033-ADC-turbidity/sensor_0033_ADC_turbidity.c b/ezlopi-sensors-devices/sensor-0033-ADC-turbidity/sensor_0033_ADC_turbidity.c
index 99621243c..3a6d63521 100644
--- a/ezlopi-sensors-devices/sensor-0033-ADC-turbidity/sensor_0033_ADC_turbidity.c
+++ b/ezlopi-sensors-devices/sensor-0033-ADC-turbidity/sensor_0033_ADC_turbidity.c
@@ -13,19 +13,19 @@
#include "sensor_0033_ADC_turbidity.h"
-static int __prepare(void* arg);
-static int __init(l_ezlopi_item_t* item);
-static int __notify(l_ezlopi_item_t* item);
-static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
-static int __get_item_list(l_ezlopi_item_t* item, void* arg);
+static int __prepare(void *arg);
+static int __init(l_ezlopi_item_t *item);
+static int __notify(l_ezlopi_item_t *item);
+static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
+static int __get_item_list(l_ezlopi_item_t *item, void *arg);
-static const char* water_filter_replacement_alarm_states[] = {
+static const char *water_filter_replacement_alarm_states[] = {
"water_filter_ok",
"replace_water_filter",
"unknown",
};
-int sensor_0033_ADC_turbidity(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
+int sensor_0033_ADC_turbidity(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
{
int ret = 0;
switch (action)
@@ -63,18 +63,18 @@ int sensor_0033_ADC_turbidity(e_ezlopi_actions_t action, l_ezlopi_item_t* item,
return ret;
}
-static int __get_item_list(l_ezlopi_item_t* item, void* arg)
+static int __get_item_list(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
- cJSON* cjson_propertise = (cJSON*)arg;
+ cJSON *cjson_propertise = (cJSON *)arg;
if (cjson_propertise)
{
- cJSON* json_array_enum = cJSON_CreateArray();
+ cJSON *json_array_enum = cJSON_CreateArray();
if (NULL != json_array_enum)
{
for (uint8_t i = 0; i < TURBIDITY__MAX; i++)
{
- cJSON* json_value = cJSON_CreateString(water_filter_replacement_alarm_states[i]);
+ cJSON *json_value = cJSON_CreateString(water_filter_replacement_alarm_states[i]);
if (NULL != json_value)
{
cJSON_AddItemToArray(json_array_enum, json_value);
@@ -83,11 +83,11 @@ static int __get_item_list(l_ezlopi_item_t* item, void* arg)
cJSON_AddItemToObject(cjson_propertise, ezlopi_enum_str, json_array_enum);
}
- s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
TRACE_I("Value is: %d, voltage is: %d", ezlopi_analog_data.value, ezlopi_analog_data.voltage);
- const char* ezlopi_water_present_turbidity_state = NULL;
+ const char *ezlopi_water_present_turbidity_state = NULL;
if (1000 > ezlopi_analog_data.voltage)
{
ezlopi_water_present_turbidity_state = "replace_water_filter";
@@ -112,15 +112,15 @@ static int __get_item_list(l_ezlopi_item_t* item, void* arg)
return ret;
}
-static int __notify(l_ezlopi_item_t* item)
+static int __notify(l_ezlopi_item_t *item)
{
int ret = 0;
- const char* tmp_sensor_state = NULL;
- char* turbidity_sensor_state = (char*)item->user_arg;
+ const char *tmp_sensor_state = NULL;
+ char *turbidity_sensor_state = (char *)item->user_arg;
if (turbidity_sensor_state)
{
- s_ezlopi_analog_data_t tmp_analog_data = { .value = 0, .voltage = 0 };
+ s_ezlopi_analog_data_t tmp_analog_data = {.value = 0, .voltage = 0};
ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &tmp_analog_data);
if (1000 > tmp_analog_data.voltage)
{
@@ -140,13 +140,13 @@ static int __notify(l_ezlopi_item_t* item)
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
+static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
if (item && arg)
{
- cJSON* cj_result = (cJSON*)arg;
- char* turbidity_sensor_state = (char*)item->user_arg;
+ cJSON *cj_result = (cJSON *)arg;
+ char *turbidity_sensor_state = (char *)item->user_arg;
if (turbidity_sensor_state)
{
cJSON_AddStringToObject(cj_result, ezlopi_value_str, turbidity_sensor_state);
@@ -157,30 +157,28 @@ static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
return ret;
}
-static int __init(l_ezlopi_item_t* item)
+static int __init(l_ezlopi_item_t *item)
{
int ret = 0;
if (item)
{
if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
{
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -194,7 +192,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON*
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
+static void __prepare_item_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_arg)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -206,31 +204,31 @@ static void __prepare_item_properties(l_ezlopi_item_t* item, cJSON* cj_device, v
item->interface_type = EZLOPI_DEVICE_INTERFACE_ANALOG_INPUT;
item->interface.adc.resln_bit = 3;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.adc.gpio_num);
item->user_arg = user_arg;
}
-static int __prepare(void* arg)
+static int __prepare(void *arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
+ s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (prep_arg && prep_arg->cjson_device)
{
- l_ezlopi_device_t* device = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t *device = ezlopi_device_add_device(prep_arg->cjson_device);
if (device)
{
__prepare_device_cloud_properties(device, prep_arg->cjson_device);
- l_ezlopi_item_t* item_turbidity = ezlopi_device_add_item_to_device(device, sensor_0033_ADC_turbidity);
+ l_ezlopi_item_t *item_turbidity = ezlopi_device_add_item_to_device(device, sensor_0033_ADC_turbidity);
if (item_turbidity)
{
item_turbidity->cloud_properties.device_id = device->cloud_properties.device_id;
- char* turbidity_sensor_states = (char*)malloc(40 * sizeof(char));
+ char *turbidity_sensor_states = (char *)malloc(40 * sizeof(char));
if (turbidity_sensor_states)
{
memset(turbidity_sensor_states, 0, sizeof(s_ezlopi_analog_data_t));
- __prepare_item_properties(item_turbidity, prep_arg->cjson_device, (void*)turbidity_sensor_states);
+ __prepare_item_properties(item_turbidity, prep_arg->cjson_device, (void *)turbidity_sensor_states);
ret = 1;
}
}
diff --git a/ezlopi-sensors-devices/sensor-0034-digitalIn-proximity/sensor_0034_digitalIn_proximity.c b/ezlopi-sensors-devices/sensor-0034-digitalIn-proximity/sensor_0034_digitalIn_proximity.c
index fa8f69fc4..5c45f7528 100644
--- a/ezlopi-sensors-devices/sensor-0034-digitalIn-proximity/sensor_0034_digitalIn_proximity.c
+++ b/ezlopi-sensors-devices/sensor-0034-digitalIn-proximity/sensor_0034_digitalIn_proximity.c
@@ -13,12 +13,12 @@
#include "sensor_0034_digitalIn_proximity.h"
-static int proximity_sensor_prepare(void* args);
-static int proximity_sensor_init(l_ezlopi_item_t* item);
-static void proximity_sensor_value_updated_from_device(void* arg);
-static int proximity_sensor_get_value_cjson(l_ezlopi_item_t* item, void* args);
+static int proximity_sensor_prepare(void *args);
+static int proximity_sensor_init(l_ezlopi_item_t *item);
+static void proximity_sensor_value_updated_from_device(void *arg);
+static int proximity_sensor_get_value_cjson(l_ezlopi_item_t *item, void *args);
-int sensor_0034_digitalIn_proximity(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* args, void* user_arg)
+int sensor_0034_digitalIn_proximity(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *args, void *user_arg)
{
int ret = 0;
@@ -50,7 +50,7 @@ int sensor_0034_digitalIn_proximity(e_ezlopi_actions_t action, l_ezlopi_item_t*
return ret;
}
-static void proximity_sensor_setup_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
+static void proximity_sensor_setup_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
{
if (device && cj_device)
{
@@ -67,7 +67,7 @@ static void proximity_sensor_setup_device_cloud_properties(l_ezlopi_device_t* de
}
}
-static void proximity_sensor_setup_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
+static void proximity_sensor_setup_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
{
if (item && cj_device)
{
@@ -83,7 +83,7 @@ static void proximity_sensor_setup_item_properties(l_ezlopi_item_t* item, cJSON*
item->interface.gpio.gpio_in.enable = true;
item->interface.gpio.gpio_in.mode = GPIO_MODE_INPUT;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "logic_inv", item->interface.gpio.gpio_in.invert);
// CJSON_GET_VALUE_INT(cj_device, "pull_up", tmp_var);
item->interface.gpio.gpio_in.pull = GPIO_PULLUP_ONLY; // tmp_var ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY;
@@ -91,18 +91,18 @@ static void proximity_sensor_setup_item_properties(l_ezlopi_item_t* item, cJSON*
}
}
-static int proximity_sensor_prepare(void* args)
+static int proximity_sensor_prepare(void *args)
{
int ret = 0;
- s_ezlopi_prep_arg_t* device_prep_arg = (s_ezlopi_prep_arg_t*)args;
+ s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)args;
if ((NULL != device_prep_arg) && (NULL != device_prep_arg->cjson_device))
{
- l_ezlopi_device_t* device = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t *device = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (device)
{
proximity_sensor_setup_device_cloud_properties(device, device_prep_arg->cjson_device);
- l_ezlopi_item_t* item = ezlopi_device_add_item_to_device(device, sensor_0034_digitalIn_proximity);
+ l_ezlopi_item_t *item = ezlopi_device_add_item_to_device(device, sensor_0034_digitalIn_proximity);
if (item)
{
item->cloud_properties.device_id = device->cloud_properties.device_id;
@@ -120,7 +120,7 @@ static int proximity_sensor_prepare(void* args)
return ret;
}
-static int proximity_sensor_init(l_ezlopi_item_t* item)
+static int proximity_sensor_init(l_ezlopi_item_t *item)
{
int ret = 0;
if (item)
@@ -135,8 +135,7 @@ static int proximity_sensor_init(l_ezlopi_item_t* item)
.intr_type = item->interface.gpio.gpio_in.interrupt,
};
- ret = gpio_config(&io_conf);
- if (ESP_OK == ret)
+ if (ESP_OK == gpio_config(&io_conf))
{
gpio_isr_service_register_v3(item, proximity_sensor_value_updated_from_device, 200);
item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
@@ -145,36 +144,35 @@ static int proximity_sensor_init(l_ezlopi_item_t* item)
}
else
{
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
TRACE_E("Error initializing Proximity sensor");
}
}
- if (0 == ret)
+ else
{
+
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static void proximity_sensor_value_updated_from_device(void* arg)
+static void proximity_sensor_value_updated_from_device(void *arg)
{
- l_ezlopi_item_t* item = (l_ezlopi_item_t*)arg;
+ l_ezlopi_item_t *item = (l_ezlopi_item_t *)arg;
if (item)
{
ezlopi_device_value_updated_from_device_v3(item);
}
}
-static int proximity_sensor_get_value_cjson(l_ezlopi_item_t* item, void* args)
+static int proximity_sensor_get_value_cjson(l_ezlopi_item_t *item, void *args)
{
int ret = 0;
- cJSON* cj_result = (cJSON*)args;
+ cJSON *cj_result = (cJSON *)args;
if (cj_result)
{
item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
@@ -183,7 +181,7 @@ static int proximity_sensor_get_value_cjson(l_ezlopi_item_t* item, void* args)
item->interface.gpio.gpio_in.value = item->interface.gpio.gpio_in.value ? false : true;
}
cJSON_AddBoolToObject(cj_result, ezlopi_value_str, item->interface.gpio.gpio_in.value);
- const char* valueFormatted = ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? false : true);
+ const char *valueFormatted = ezlopi_valueformatter_bool(item->interface.gpio.gpio_in.value ? false : true);
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
ret = 1;
// TRACE_D("value: %d", item->interface.gpio.gpio_in.value);
diff --git a/ezlopi-sensors-devices/sensor-0035-digitalIn-touch-sensor-TPP223B/sensor_0035_digitalIn_touch_sensor_TPP223B.c b/ezlopi-sensors-devices/sensor-0035-digitalIn-touch-sensor-TPP223B/sensor_0035_digitalIn_touch_sensor_TPP223B.c
index de1c4de36..9a8646fd5 100644
--- a/ezlopi-sensors-devices/sensor-0035-digitalIn-touch-sensor-TPP223B/sensor_0035_digitalIn_touch_sensor_TPP223B.c
+++ b/ezlopi-sensors-devices/sensor-0035-digitalIn-touch-sensor-TPP223B/sensor_0035_digitalIn_touch_sensor_TPP223B.c
@@ -81,21 +81,23 @@ static int __init(l_ezlopi_item_t *item)
.intr_type = item->interface.gpio.gpio_in.interrupt,
};
- ESP_ERROR_CHECK(gpio_config(&touch_switch_config));
-
- int gpio_level = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
- item->interface.gpio.gpio_in.value = (false == item->interface.gpio.gpio_in.invert) ? gpio_level : !gpio_level;
- gpio_isr_service_register_v3(item, __touch_switch_callback, 200);
- ret = 1;
+ if (0 == gpio_config(&touch_switch_config))
+ {
+ int gpio_level = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
+ item->interface.gpio.gpio_in.value = (false == item->interface.gpio.gpio_in.invert) ? gpio_level : !gpio_level;
+ gpio_isr_service_register_v3(item, __touch_switch_callback, 200);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
@@ -164,7 +166,7 @@ static void __prepare_touch_sensor_properties(l_ezlopi_item_t *item, cJSON *cj_d
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, ezlopi_ip_inv_str, item->interface.gpio.gpio_in.invert);
CJSON_GET_VALUE_INT(cj_device, ezlopi_val_ip_str, item->interface.gpio.gpio_in.value);
diff --git a/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/CMakeLists.txt b/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/CMakeLists.txt
index 01331166f..5602dad19 100644
--- a/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/CMakeLists.txt
+++ b/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/CMakeLists.txt
@@ -7,6 +7,7 @@ set(EZLOPI_CORE_COMPONENTS
ezlopi-core-actions
ezlopi-core-devices
ezlopi-core-timer
+ ezlopi-core-valueformatter
)
set(EZLOPI_CLOUD_COMPONENTS
ezlopi-cloud-constants
diff --git a/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/pms_dev_items_prepare.c b/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/pms_dev_items_prepare.c
index c2ba11a1c..f7e822fbf 100644
--- a/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/pms_dev_items_prepare.c
+++ b/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/pms_dev_items_prepare.c
@@ -12,14 +12,14 @@
#include "sensor_0037_pms5003_sensor.h"
// Device 0
-static int __prepare_particulate_matter_particles_0_dot_3_um_device_and_items(cJSON *cj_properties, uint32_t *parent_id, void *user_arg)
+static int __prepare_particulate_matter_particles_0_dot_3_um_device_and_items(cJSON* cj_properties, uint32_t* parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *particles_0_dot_3_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* particles_0_dot_3_um_device = ezlopi_device_add_device(cj_properties);
if (particles_0_dot_3_um_device)
{
- char *dev_name = "Dust Particles 0.3 um";
+ char* dev_name = "Dust Particles 0.3 um";
ASSIGN_DEVICE_NAME_V2(particles_0_dot_3_um_device, dev_name);
particles_0_dot_3_um_device->cloud_properties.category = category_level_sensor;
particles_0_dot_3_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -28,7 +28,7 @@ static int __prepare_particulate_matter_particles_0_dot_3_um_device_and_items(cJ
particles_0_dot_3_um_device->cloud_properties.parent_device_id = particles_0_dot_3_um_device->cloud_properties.device_id;
*parent_id = particles_0_dot_3_um_device->cloud_properties.parent_device_id;
- l_ezlopi_item_t *particles_0_dot_3_um_item = ezlopi_device_add_item_to_device(particles_0_dot_3_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* particles_0_dot_3_um_item = ezlopi_device_add_item_to_device(particles_0_dot_3_um_device, sensor_pms5003_v3);
if (particles_0_dot_3_um_item)
{
particles_0_dot_3_um_item->cloud_properties.has_getter = true;
@@ -41,8 +41,8 @@ static int __prepare_particulate_matter_particles_0_dot_3_um_device_and_items(cJ
particles_0_dot_3_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
particles_0_dot_3_um_item->interface.uart.enable = true;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", particles_0_dot_3_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", particles_0_dot_3_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, particles_0_dot_3_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, particles_0_dot_3_um_item->interface.uart.rx);
particles_0_dot_3_um_item->interface.uart.baudrate = 9600;
particles_0_dot_3_um_item->user_arg = user_arg;
@@ -61,14 +61,14 @@ static int __prepare_particulate_matter_particles_0_dot_3_um_device_and_items(cJ
}
// Device 1
-static int __prepare_particulate_matter_particles_0_dot_5_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_particles_0_dot_5_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *particles_0_dot_5_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* particles_0_dot_5_um_device = ezlopi_device_add_device(cj_properties);
if (particles_0_dot_5_um_device)
{
- char *dev_name = "Dust Particles 0.5 um";
+ char* dev_name = "Dust Particles 0.5 um";
ASSIGN_DEVICE_NAME_V2(particles_0_dot_5_um_device, dev_name);
particles_0_dot_5_um_device->cloud_properties.category = category_level_sensor;
particles_0_dot_5_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -76,7 +76,7 @@ static int __prepare_particulate_matter_particles_0_dot_5_um_device_and_items(cJ
particles_0_dot_5_um_device->cloud_properties.device_type = dev_type_sensor;
particles_0_dot_5_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *particles_0_dot_5_um_item = ezlopi_device_add_item_to_device(particles_0_dot_5_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* particles_0_dot_5_um_item = ezlopi_device_add_item_to_device(particles_0_dot_5_um_device, sensor_pms5003_v3);
if (particles_0_dot_5_um_item)
{
particles_0_dot_5_um_item->cloud_properties.has_getter = true;
@@ -89,8 +89,8 @@ static int __prepare_particulate_matter_particles_0_dot_5_um_device_and_items(cJ
particles_0_dot_5_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
particles_0_dot_5_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", particles_0_dot_5_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", particles_0_dot_5_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, particles_0_dot_5_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, particles_0_dot_5_um_item->interface.uart.rx);
particles_0_dot_5_um_item->interface.uart.baudrate = 9600;
particles_0_dot_5_um_item->user_arg = user_arg;
@@ -109,14 +109,14 @@ static int __prepare_particulate_matter_particles_0_dot_5_um_device_and_items(cJ
}
// Device 2
-static int __prepare_particulate_matter_particles_1_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_particles_1_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *particles_1_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* particles_1_um_device = ezlopi_device_add_device(cj_properties);
if (particles_1_um_device)
{
- char *dev_name = "Dust Particles 1 um";
+ char* dev_name = "Dust Particles 1 um";
ASSIGN_DEVICE_NAME_V2(particles_1_um_device, dev_name);
particles_1_um_device->cloud_properties.category = category_level_sensor;
particles_1_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -124,7 +124,7 @@ static int __prepare_particulate_matter_particles_1_um_device_and_items(cJSON *c
particles_1_um_device->cloud_properties.device_type = dev_type_sensor;
particles_1_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *particles_1_um_item = ezlopi_device_add_item_to_device(particles_1_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* particles_1_um_item = ezlopi_device_add_item_to_device(particles_1_um_device, sensor_pms5003_v3);
if (particles_1_um_item)
{
particles_1_um_item->cloud_properties.has_getter = true;
@@ -137,8 +137,8 @@ static int __prepare_particulate_matter_particles_1_um_device_and_items(cJSON *c
particles_1_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
particles_1_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", particles_1_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", particles_1_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, particles_1_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, particles_1_um_item->interface.uart.rx);
particles_1_um_item->interface.uart.baudrate = 9600;
particles_1_um_item->user_arg = user_arg;
@@ -157,14 +157,14 @@ static int __prepare_particulate_matter_particles_1_um_device_and_items(cJSON *c
}
// Device 3
-static int __prepare_particulate_matter_particles_2_dot_5_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_particles_2_dot_5_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *particles_2_dot_5_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* particles_2_dot_5_um_device = ezlopi_device_add_device(cj_properties);
if (particles_2_dot_5_um_device)
{
- char *dev_name = "Dust Particles 2.5 um";
+ char* dev_name = "Dust Particles 2.5 um";
ASSIGN_DEVICE_NAME_V2(particles_2_dot_5_um_device, dev_name);
particles_2_dot_5_um_device->cloud_properties.category = category_level_sensor;
particles_2_dot_5_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -172,7 +172,7 @@ static int __prepare_particulate_matter_particles_2_dot_5_um_device_and_items(cJ
particles_2_dot_5_um_device->cloud_properties.device_type = dev_type_sensor;
particles_2_dot_5_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *particles_2_dot_5_um_item = ezlopi_device_add_item_to_device(particles_2_dot_5_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* particles_2_dot_5_um_item = ezlopi_device_add_item_to_device(particles_2_dot_5_um_device, sensor_pms5003_v3);
if (particles_2_dot_5_um_item)
{
particles_2_dot_5_um_item->cloud_properties.has_getter = true;
@@ -185,8 +185,8 @@ static int __prepare_particulate_matter_particles_2_dot_5_um_device_and_items(cJ
particles_2_dot_5_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
particles_2_dot_5_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", particles_2_dot_5_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", particles_2_dot_5_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, particles_2_dot_5_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, particles_2_dot_5_um_item->interface.uart.rx);
particles_2_dot_5_um_item->interface.uart.baudrate = 9600;
particles_2_dot_5_um_item->user_arg = user_arg;
@@ -205,14 +205,14 @@ static int __prepare_particulate_matter_particles_2_dot_5_um_device_and_items(cJ
}
// Device 4
-static int __prepare_particulate_matter_particles_5_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_particles_5_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *particles_5_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* particles_5_um_device = ezlopi_device_add_device(cj_properties);
if (particles_5_um_device)
{
- char *dev_name = "Dust Particles 5 um";
+ char* dev_name = "Dust Particles 5 um";
ASSIGN_DEVICE_NAME_V2(particles_5_um_device, dev_name);
particles_5_um_device->cloud_properties.category = category_level_sensor;
particles_5_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -220,7 +220,7 @@ static int __prepare_particulate_matter_particles_5_um_device_and_items(cJSON *c
particles_5_um_device->cloud_properties.device_type = dev_type_sensor;
particles_5_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *particles_5_um_item = ezlopi_device_add_item_to_device(particles_5_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* particles_5_um_item = ezlopi_device_add_item_to_device(particles_5_um_device, sensor_pms5003_v3);
if (particles_5_um_item)
{
particles_5_um_item->cloud_properties.has_getter = true;
@@ -233,8 +233,8 @@ static int __prepare_particulate_matter_particles_5_um_device_and_items(cJSON *c
particles_5_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
particles_5_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", particles_5_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", particles_5_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, particles_5_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, particles_5_um_item->interface.uart.rx);
particles_5_um_item->interface.uart.baudrate = 9600;
particles_5_um_item->user_arg = user_arg;
@@ -253,14 +253,14 @@ static int __prepare_particulate_matter_particles_5_um_device_and_items(cJSON *c
}
// Device 5
-static int __prepare_particulate_matter_particles_10_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_particles_10_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *particles_10_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* particles_10_um_device = ezlopi_device_add_device(cj_properties);
if (particles_10_um_device)
{
- char *dev_name = "Dust Particles 10 um";
+ char* dev_name = "Dust Particles 10 um";
ASSIGN_DEVICE_NAME_V2(particles_10_um_device, dev_name);
particles_10_um_device->cloud_properties.category = category_level_sensor;
particles_10_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -268,7 +268,7 @@ static int __prepare_particulate_matter_particles_10_um_device_and_items(cJSON *
particles_10_um_device->cloud_properties.device_type = dev_type_sensor;
particles_10_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *particles_10_um_item = ezlopi_device_add_item_to_device(particles_10_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* particles_10_um_item = ezlopi_device_add_item_to_device(particles_10_um_device, sensor_pms5003_v3);
if (particles_10_um_item)
{
particles_10_um_item->cloud_properties.has_getter = true;
@@ -281,8 +281,8 @@ static int __prepare_particulate_matter_particles_10_um_device_and_items(cJSON *
particles_10_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
particles_10_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", particles_10_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", particles_10_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, particles_10_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, particles_10_um_item->interface.uart.rx);
particles_10_um_item->interface.uart.baudrate = 9600;
particles_10_um_item->user_arg = user_arg;
@@ -301,14 +301,14 @@ static int __prepare_particulate_matter_particles_10_um_device_and_items(cJSON *
}
// Device 6
-static int __prepare_particulate_matter_standard_particles_1_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_standard_particles_1_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *standard_particles_1_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* standard_particles_1_um_device = ezlopi_device_add_device(cj_properties);
if (standard_particles_1_um_device)
{
- char *dev_name = "Dust Particles PM 1 um";
+ char* dev_name = "Dust Particles PM 1 um";
ASSIGN_DEVICE_NAME_V2(standard_particles_1_um_device, dev_name);
standard_particles_1_um_device->cloud_properties.category = category_level_sensor;
standard_particles_1_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -316,7 +316,7 @@ static int __prepare_particulate_matter_standard_particles_1_um_device_and_items
standard_particles_1_um_device->cloud_properties.device_type = dev_type_sensor;
standard_particles_1_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *standard_particles_1_um_item = ezlopi_device_add_item_to_device(standard_particles_1_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* standard_particles_1_um_item = ezlopi_device_add_item_to_device(standard_particles_1_um_device, sensor_pms5003_v3);
if (standard_particles_1_um_item)
{
standard_particles_1_um_item->cloud_properties.has_getter = true;
@@ -329,8 +329,8 @@ static int __prepare_particulate_matter_standard_particles_1_um_device_and_items
standard_particles_1_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
standard_particles_1_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", standard_particles_1_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", standard_particles_1_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, standard_particles_1_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, standard_particles_1_um_item->interface.uart.rx);
standard_particles_1_um_item->interface.uart.baudrate = 9600;
standard_particles_1_um_item->user_arg = user_arg;
@@ -349,14 +349,14 @@ static int __prepare_particulate_matter_standard_particles_1_um_device_and_items
}
// Device 7
-static int __prepare_particulate_matter_standard_particles_2_dot_5_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_standard_particles_2_dot_5_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *standard_particles_2_dot_5_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* standard_particles_2_dot_5_um_device = ezlopi_device_add_device(cj_properties);
if (standard_particles_2_dot_5_um_device)
{
- char *dev_name = "Dust Particles PM 2.5 um";
+ char* dev_name = "Dust Particles PM 2.5 um";
ASSIGN_DEVICE_NAME_V2(standard_particles_2_dot_5_um_device, dev_name);
standard_particles_2_dot_5_um_device->cloud_properties.category = category_level_sensor;
standard_particles_2_dot_5_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -364,7 +364,7 @@ static int __prepare_particulate_matter_standard_particles_2_dot_5_um_device_and
standard_particles_2_dot_5_um_device->cloud_properties.device_type = dev_type_sensor;
standard_particles_2_dot_5_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *standard_particles_2_dot_5_um_item = ezlopi_device_add_item_to_device(standard_particles_2_dot_5_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* standard_particles_2_dot_5_um_item = ezlopi_device_add_item_to_device(standard_particles_2_dot_5_um_device, sensor_pms5003_v3);
if (standard_particles_2_dot_5_um_item)
{
standard_particles_2_dot_5_um_item->cloud_properties.has_getter = true;
@@ -377,8 +377,8 @@ static int __prepare_particulate_matter_standard_particles_2_dot_5_um_device_and
standard_particles_2_dot_5_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
standard_particles_2_dot_5_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", standard_particles_2_dot_5_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", standard_particles_2_dot_5_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, standard_particles_2_dot_5_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, standard_particles_2_dot_5_um_item->interface.uart.rx);
standard_particles_2_dot_5_um_item->interface.uart.baudrate = 9600;
standard_particles_2_dot_5_um_item->user_arg = user_arg;
@@ -397,14 +397,14 @@ static int __prepare_particulate_matter_standard_particles_2_dot_5_um_device_and
}
// Device 8
-static int __prepare_particulate_matter_standard_particles_10_um_device_and_items(cJSON *cj_properties, uint32_t parent_id, void *user_arg)
+static int __prepare_particulate_matter_standard_particles_10_um_device_and_items(cJSON* cj_properties, uint32_t parent_id, void* user_arg)
{
int ret = 0;
- l_ezlopi_device_t *standard_particles_10_um_device = ezlopi_device_add_device(cj_properties);
+ l_ezlopi_device_t* standard_particles_10_um_device = ezlopi_device_add_device(cj_properties);
if (standard_particles_10_um_device)
{
- char *dev_name = "Dust Particles PM 10 um";
+ char* dev_name = "Dust Particles PM 10 um";
ASSIGN_DEVICE_NAME_V2(standard_particles_10_um_device, dev_name);
standard_particles_10_um_device->cloud_properties.category = category_level_sensor;
standard_particles_10_um_device->cloud_properties.subcategory = subcategory_particulate_matter;
@@ -412,7 +412,7 @@ static int __prepare_particulate_matter_standard_particles_10_um_device_and_item
standard_particles_10_um_device->cloud_properties.device_type = dev_type_sensor;
standard_particles_10_um_device->cloud_properties.parent_device_id = parent_id;
- l_ezlopi_item_t *standard_particles_10_um_item = ezlopi_device_add_item_to_device(standard_particles_10_um_device, sensor_pms5003_v3);
+ l_ezlopi_item_t* standard_particles_10_um_item = ezlopi_device_add_item_to_device(standard_particles_10_um_device, sensor_pms5003_v3);
if (standard_particles_10_um_item)
{
standard_particles_10_um_item->cloud_properties.has_getter = true;
@@ -425,8 +425,8 @@ static int __prepare_particulate_matter_standard_particles_10_um_device_and_item
standard_particles_10_um_item->interface_type = EZLOPI_DEVICE_INTERFACE_UART;
standard_particles_10_um_item->interface.uart.enable = false;
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", standard_particles_10_um_item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", standard_particles_10_um_item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, standard_particles_10_um_item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, standard_particles_10_um_item->interface.uart.rx);
standard_particles_10_um_item->interface.uart.baudrate = 9600;
standard_particles_10_um_item->user_arg = user_arg;
@@ -444,15 +444,15 @@ static int __prepare_particulate_matter_standard_particles_10_um_device_and_item
return ret;
}
-static int pms5003_set_pms_object_details(cJSON *cj_properties, s_pms5003_sensor_object *pms_object)
+static int pms5003_set_pms_object_details(cJSON* cj_properties, s_pms5003_sensor_object* pms_object)
{
int ret = 0;
assert(pms_object != NULL);
- CJSON_GET_VALUE_INT(cj_properties, "gpio1", pms_object->pms_tx_pin);
- CJSON_GET_VALUE_INT(cj_properties, "gpio2", pms_object->pms_rx_pin);
- CJSON_GET_VALUE_INT(cj_properties, "gpio3", pms_object->pms_set_pin);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio1_str, pms_object->pms_tx_pin);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio2_str, pms_object->pms_rx_pin);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio3_str, pms_object->pms_set_pin);
CJSON_GET_VALUE_INT(cj_properties, "gpio4", pms_object->pms_reset_pin);
pms_object->pms_baud_rate = 9600;
@@ -468,23 +468,23 @@ static int pms5003_set_pms_object_details(cJSON *cj_properties, s_pms5003_sensor
return ret;
}
-int pms5003_sensor_preapre_devices_and_items(cJSON *cj_properties, uint32_t *parent_id)
+int pms5003_sensor_preapre_devices_and_items(cJSON* cj_properties, uint32_t* parent_id)
{
int ret = 0;
- s_pms5003_sensor_object *pms_object = (s_pms5003_sensor_object *)malloc(sizeof(s_pms5003_sensor_object));
+ s_pms5003_sensor_object* pms_object = (s_pms5003_sensor_object*)malloc(sizeof(s_pms5003_sensor_object));
if (pms_object)
{
pms5003_set_pms_object_details(cj_properties, pms_object);
- ESP_ERROR_CHECK(__prepare_particulate_matter_particles_0_dot_3_um_device_and_items(cj_properties, parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_particles_0_dot_5_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_particles_1_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_particles_2_dot_5_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_particles_5_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_particles_10_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_standard_particles_1_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_standard_particles_2_dot_5_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
- ESP_ERROR_CHECK(__prepare_particulate_matter_standard_particles_10_um_device_and_items(cj_properties, *parent_id, (void *)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_particles_0_dot_3_um_device_and_items(cj_properties, parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_particles_0_dot_5_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_particles_1_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_particles_2_dot_5_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_particles_5_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_particles_10_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_standard_particles_1_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_standard_particles_2_dot_5_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
+ ESP_ERROR_CHECK(__prepare_particulate_matter_standard_particles_10_um_device_and_items(cj_properties, *parent_id, (void*)pms_object));
ret = 0;
}
else
diff --git a/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/sensor_0037_pms5003_sensor.c b/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/sensor_0037_pms5003_sensor.c
index 7ca67a45d..9885477ac 100644
--- a/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/sensor_0037_pms5003_sensor.c
+++ b/ezlopi-sensors-devices/sensor-0037-pms5003-sensor/sensor_0037_pms5003_sensor.c
@@ -4,14 +4,14 @@
#include "cJSON.h"
#include "ezlopi_util_trace.h"
-#include "ezlopi_core_timer.h"
+#include "ezlopi_core_timer.h"
#include "ezlopi_core_devices_list.h"
#include "ezlopi_core_device_value_updated.h"
-#include "ezlopi_cloud_constants.h"
-
#include "ezlopi_core_cloud.h"
+#include "ezlopi_core_valueformatter.h"
+#include "ezlopi_cloud_constants.h"
#include "pms5003.h"
#include "sensor_0037_pms5003_sensor.h"
@@ -91,63 +91,98 @@ static int __cjson_get_value(l_ezlopi_item_t *item, void *arg)
cJSON *cj_param = (cJSON *)arg;
s_pms5003_sensor_object *pms_object = (s_pms5003_sensor_object *)item->user_arg;
- char valueFormatted[20];
if (cj_param && pms_object)
{
if (ezlopi_item_name_particulate_matter_1 == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.pm10_standard);
- TRACE_S("Dust particle 1 : %s", valueFormatted);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.pm10_standard);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.pm10_standard);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.pm10_standard);
+ if (valueFormatted)
+ {
+ TRACE_I("Dust particle 1 : %s", valueFormatted);
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particulate_matter_2_dot_5 == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.pm25_standard);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.pm25_standard);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.pm25_standard);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.pm25_standard);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particulate_matter_10 == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.pm100_standard);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.pm100_standard);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.pm100_standard);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.pm100_standard);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particles_0_dot_3_um == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.particles_03um);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.particles_03um);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.particles_03um);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.particles_03um);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particles_0_dot_5_um == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.particles_05um);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.particles_05um);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.particles_05um);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.particles_05um);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particles_1_um == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.particles_10um);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.particles_10um);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.particles_10um);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.particles_10um);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particles_2_dot_5_um == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.particles_25um);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.particles_25um);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.particles_25um);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.particles_25um);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particles_5_um == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.particles_50um);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.particles_50um);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.particles_50um);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.particles_50um);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
if (ezlopi_item_name_particles_10_um == item->cloud_properties.item_name)
{
- snprintf(valueFormatted, 20, "%d", pms_object->pms_data.particles_100um);
- cJSON_AddStringToObject(cj_param, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_param, "value", pms_object->pms_data.particles_100um);
+ cJSON_AddNumberToObject(cj_param, ezlopi_value_str, pms_object->pms_data.particles_100um);
+ char *valueFormatted = ezlopi_valueformatter_uint32(pms_object->pms_data.particles_100um);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_param, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
}
@@ -160,20 +195,18 @@ static int __init(l_ezlopi_item_t *item)
if (item)
{
s_pms5003_sensor_object *pms_object = (s_pms5003_sensor_object *)item->user_arg;
-
- if (item->interface.uart.enable && pms_object)
+ if (pms_object)
{
- pms_init(pms_object);
+ if (item->interface.uart.enable)
+ {
+ pms_init(pms_object);
+ }
ret = 1;
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
diff --git a/ezlopi-sensors-devices/sensor-0040-other-TCS230/sensor_0040_other_TCS230.c b/ezlopi-sensors-devices/sensor-0040-other-TCS230/sensor_0040_other_TCS230.c
index 32e4e584b..f8a8350d1 100644
--- a/ezlopi-sensors-devices/sensor-0040-other-TCS230/sensor_0040_other_TCS230.c
+++ b/ezlopi-sensors-devices/sensor-0040-other-TCS230/sensor_0040_other_TCS230.c
@@ -17,16 +17,16 @@
#include "sensor_0040_other_TCS230.h"
-static int __0040_prepare(void *arg);
-static int __0040_init(l_ezlopi_item_t *item);
-static int __0040_get_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __0040_notify(l_ezlopi_item_t *item);
+static int __0040_prepare(void* arg);
+static int __0040_init(l_ezlopi_item_t* item);
+static int __0040_get_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __0040_notify(l_ezlopi_item_t* item);
static void __tcs230_setup_gpio(gpio_num_t s0_pin, gpio_num_t s1_pin, gpio_num_t s2_pin, gpio_num_t s3_pin, gpio_num_t gpio_output_en, gpio_num_t gpio_pulse_output);
-static void __tcs230_calibration_task(void *params);
+static void __tcs230_calibration_task(void* params);
//------------------------------------------------------------------------------------------------------
-int sensor_0040_other_TCS230(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0040_other_TCS230(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -53,11 +53,11 @@ int sensor_0040_other_TCS230(e_ezlopi_actions_t action, l_ezlopi_item_t *item, v
//------------------------------------------------------------------------------------------------------
static void __tcs230_setup_gpio(gpio_num_t s0_pin,
- gpio_num_t s1_pin,
- gpio_num_t s2_pin,
- gpio_num_t s3_pin,
- gpio_num_t gpio_output_en,
- gpio_num_t gpio_pulse_output)
+ gpio_num_t s1_pin,
+ gpio_num_t s2_pin,
+ gpio_num_t s3_pin,
+ gpio_num_t gpio_output_en,
+ gpio_num_t gpio_pulse_output)
{
esp_err_t ret = ESP_FAIL;
// Configure GPIO ouput pins (S0, S1, S2, S3 & Freq_scale) for TCS230.
@@ -88,9 +88,9 @@ static void __tcs230_setup_gpio(gpio_num_t s0_pin,
}
//------------------------------------------------------------------------------------------------------
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
ASSIGN_DEVICE_NAME_V2(device, device_name);
device->cloud_properties.device_id = ezlopi_cloud_generate_device_id();
@@ -100,7 +100,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.info = NULL;
device->cloud_properties.device_type = dev_type_sensor;
}
-static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_data)
+static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, void* user_data)
{
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.has_getter = true;
@@ -112,36 +112,36 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, void *user_da
item->user_arg = user_data;
}
-static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_item_interface_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
if (item && cj_device)
{
- s_TCS230_data_t *user_data = (s_TCS230_data_t *)item->user_arg;
+ s_TCS230_data_t* user_data = (s_TCS230_data_t*)item->user_arg;
item->interface_type = EZLOPI_DEVICE_INTERFACE_MAX;
- CJSON_GET_VALUE_INT(cj_device, "gpio1", user_data->TCS230_pin.gpio_s0); // gpio_s0
- CJSON_GET_VALUE_INT(cj_device, "gpio2", user_data->TCS230_pin.gpio_s1); // gpio_s1
- CJSON_GET_VALUE_INT(cj_device, "gpio3", user_data->TCS230_pin.gpio_s2); // gpio_s2
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, user_data->TCS230_pin.gpio_s0); // gpio_s0
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio2_str, user_data->TCS230_pin.gpio_s1); // gpio_s1
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio3_str, user_data->TCS230_pin.gpio_s2); // gpio_s2
CJSON_GET_VALUE_INT(cj_device, "gpio4", user_data->TCS230_pin.gpio_s3); // gpio_s3
CJSON_GET_VALUE_INT(cj_device, "gpio5", user_data->TCS230_pin.gpio_output_en); // gpio_output_en
CJSON_GET_VALUE_INT(cj_device, "gpio6", user_data->TCS230_pin.gpio_pulse_output); // gpio_pulse_output
}
}
//------------------------------------------------------------------------------------------------------
-static int __0040_prepare(void *arg)
+static int __0040_prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* device_prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
- cJSON *cj_device = device_prep_arg->cjson_device;
- s_TCS230_data_t *user_data = (s_TCS230_data_t *)malloc(sizeof(s_TCS230_data_t));
+ cJSON* cj_device = device_prep_arg->cjson_device;
+ s_TCS230_data_t* user_data = (s_TCS230_data_t*)malloc(sizeof(s_TCS230_data_t));
if (user_data)
{
- l_ezlopi_device_t *tcs230_device = ezlopi_device_add_device(cj_device);
+ l_ezlopi_device_t* tcs230_device = ezlopi_device_add_device(cj_device);
if (tcs230_device)
{
__prepare_device_cloud_properties(tcs230_device, cj_device);
- l_ezlopi_item_t *tcs230_item = ezlopi_device_add_item_to_device(tcs230_device, sensor_0040_other_TCS230);
+ l_ezlopi_item_t* tcs230_item = ezlopi_device_add_item_to_device(tcs230_device, sensor_0040_other_TCS230);
if (tcs230_item)
{
__prepare_item_cloud_properties(tcs230_item, user_data);
@@ -165,91 +165,106 @@ static int __0040_prepare(void *arg)
return ret;
}
-static int __0040_init(l_ezlopi_item_t *item)
+static int __0040_init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
s_TCS230_data_t *user_data = (s_TCS230_data_t *)item->user_arg;
- if (GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s0) &&
- GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s1) &&
- GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s2) &&
- GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s3) &&
- GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_output_en) &&
- GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_pulse_output))
+ if (user_data)
{
- __tcs230_setup_gpio(user_data->TCS230_pin.gpio_s0,
- user_data->TCS230_pin.gpio_s1,
- user_data->TCS230_pin.gpio_s2,
- user_data->TCS230_pin.gpio_s3,
- user_data->TCS230_pin.gpio_output_en,
- user_data->TCS230_pin.gpio_pulse_output);
- TRACE_W("Entering Calibration Phase for 30 seconds.....");
+ if (GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s0) &&
+ GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s1) &&
+ GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s2) &&
+ GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_s3) &&
+ GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_output_en) &&
+ GPIO_IS_VALID_GPIO(user_data->TCS230_pin.gpio_pulse_output))
+ {
+ __tcs230_setup_gpio(user_data->TCS230_pin.gpio_s0,
+ user_data->TCS230_pin.gpio_s1,
+ user_data->TCS230_pin.gpio_s2,
+ user_data->TCS230_pin.gpio_s3,
+ user_data->TCS230_pin.gpio_output_en,
+ user_data->TCS230_pin.gpio_pulse_output);
+ TRACE_W("Entering Calibration Phase for 30 seconds.....");
- // configure Freq_scale at 20%
- tcs230_set_frequency_scaling(item, COLOR_SENSOR_FREQ_SCALING_20_PERCENT);
+ // configure Freq_scale at 20%
+ tcs230_set_frequency_scaling(item, COLOR_SENSOR_FREQ_SCALING_20_PERCENT);
- // activate a task to calibrate data
- xTaskCreate(__tcs230_calibration_task, "TCS230_Calibration_Task", 2 * 2048, item, 1, NULL);
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ // activate a task to calibrate data
+ xTaskCreate(__tcs230_calibration_task, "TCS230_Calibration_Task", 2 * 2048, item, 1, NULL);
+ ret = 1;
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
-static int __0040_get_cjson_value(l_ezlopi_item_t *item, void *args)
+static int __0040_get_cjson_value(l_ezlopi_item_t* item, void* args)
{
int ret = 0;
- cJSON *cj_result = (cJSON *)args;
+ cJSON* cj_result = (cJSON*)args;
if (cj_result && item)
{
s_TCS230_data_t *user_data = (s_TCS230_data_t *)item->user_arg;
- if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
+ if (user_data)
{
- cJSON *color_values = cJSON_AddObjectToObject(cj_result, "value");
- cJSON_AddNumberToObject(color_values, "red", user_data->red_mapped);
- cJSON_AddNumberToObject(color_values, "green", user_data->green_mapped);
- cJSON_AddNumberToObject(color_values, "blue", user_data->blue_mapped);
- char *formatted_val = ezlopi_valueformatter_rgb(user_data->red_mapped, user_data->green_mapped, user_data->blue_mapped);
- cJSON_AddStringToObject(cj_result, "valueFormatted", formatted_val);
- free(formatted_val);
+ if (ezlopi_item_name_rgbcolor == item->cloud_properties.item_name)
+ {
+ cJSON *color_values = cJSON_AddObjectToObject(cj_result, ezlopi_value_str);
+ cJSON_AddNumberToObject(color_values, "red", user_data->red_mapped);
+ cJSON_AddNumberToObject(color_values, "green", user_data->green_mapped);
+ cJSON_AddNumberToObject(color_values, "blue", user_data->blue_mapped);
+ char *valueFormatted = ezlopi_valueformatter_rgb(user_data->red_mapped, user_data->green_mapped, user_data->blue_mapped);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ ret = 1;
}
- ret = 1;
}
return ret;
}
-static int __0040_notify(l_ezlopi_item_t *item)
+static int __0040_notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
s_TCS230_data_t *user_data = (s_TCS230_data_t *)item->user_arg;
- uint32_t red = user_data->red_mapped;
- uint32_t green = user_data->green_mapped;
- uint32_t blue = user_data->blue_mapped;
- bool valid_status = get_tcs230_sensor_value(item); // Informs and updates if valid data
- if (valid_status)
+ if (user_data)
{
- if (fabs(red - user_data->red_mapped) > 10 ||
- fabs(green - user_data->green_mapped) > 10 ||
- fabs(blue - user_data->blue_mapped) > 10)
+ uint32_t red = user_data->red_mapped;
+ uint32_t green = user_data->green_mapped;
+ uint32_t blue = user_data->blue_mapped;
+ bool valid_status = get_tcs230_sensor_value(item); // Informs and updates if valid data
+ if (valid_status)
{
- TRACE_S("---------------------------------------");
- TRACE_S("Red : %d", user_data->red_mapped);
- TRACE_S("Green :%d", user_data->green_mapped);
- TRACE_S("Blue : %d", user_data->blue_mapped);
- TRACE_S("---------------------------------------");
- ezlopi_device_value_updated_from_device_v3(item);
+ if (fabs(red - user_data->red_mapped) > 10 ||
+ fabs(green - user_data->green_mapped) > 10 ||
+ fabs(blue - user_data->blue_mapped) > 10)
+ {
+ TRACE_S("---------------------------------------");
+ TRACE_S("Red : %d", user_data->red_mapped);
+ TRACE_S("Green :%d", user_data->green_mapped);
+ TRACE_S("Blue : %d", user_data->blue_mapped);
+ TRACE_S("---------------------------------------");
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
}
@@ -257,76 +272,79 @@ static int __0040_notify(l_ezlopi_item_t *item)
}
//------------------------------------------------------------------------------
-static void __tcs230_calibration_task(void *params) // calibration task
+static void __tcs230_calibration_task(void* params) // calibration task
{
vTaskDelay(4000 / portTICK_PERIOD_MS); // 4sec
- l_ezlopi_item_t *item = (l_ezlopi_item_t *)params;
+ l_ezlopi_item_t* item = (l_ezlopi_item_t*)params;
if (item)
{ // extracting the 'user_args' from "item"
s_TCS230_data_t *user_data = (s_TCS230_data_t *)item->user_arg;
+ if (user_data)
+ {
#if 0
- //--------------------------------------------------
- // calculate red min-max periods for each colour
- TRACE_E("Please, place the red paper in front of colour sensor..... Starting Calibration for RED in ....");
- for (uint8_t j = 5; j > 0; j--)
- {
- TRACE_E("....................................................... {%d} ", j);
- vTaskDelay(1000 / portTICK_PERIOD_MS); // 4sec
- }
- // choose RED filter
- tcs230_set_filter_color(item, COLOR_SENSOR_COLOR_RED);
- calculate_max_min_color_values(user_data->TCS230_pin.gpio_output_en,
- user_data->TCS230_pin.gpio_pulse_output,
- &user_data->calib_data.least_red_timeP,
- &user_data->calib_data.most_red_timeP);
+ //--------------------------------------------------
+ // calculate red min-max periods for each colour
+ TRACE_E("Please, place the red paper in front of colour sensor..... Starting Calibration for RED in ....");
+ for (uint8_t j = 5; j > 0; j--)
+ {
+ TRACE_E("....................................................... {%d} ", j);
+ vTaskDelay(1000 / portTICK_PERIOD_MS); // 4sec
+ }
+ // choose RED filter
+ tcs230_set_filter_color(item, COLOR_SENSOR_COLOR_RED);
+ calculate_max_min_color_values(user_data->TCS230_pin.gpio_output_en,
+ user_data->TCS230_pin.gpio_pulse_output,
+ &user_data->calib_data.least_red_timeP,
+ &user_data->calib_data.most_red_timeP);
- //--------------------------------------------------
- // calculate green min-max periods for each colour
- TRACE_S("Please, place the green paper in front of colour sensor..... Starting Calibration for GREEN in ....");
- for (uint8_t j = 5; j > 0; j--)
- {
- TRACE_S("....................................................... {%d} ", j);
- vTaskDelay(1000 / portTICK_PERIOD_MS); // 4sec
- }
- // choose GREEN filter
- tcs230_set_filter_color(item, COLOR_SENSOR_COLOR_GREEN);
- calculate_max_min_color_values(user_data->TCS230_pin.gpio_output_en,
- user_data->TCS230_pin.gpio_pulse_output,
- &user_data->calib_data.least_green_timeP,
- &user_data->calib_data.most_green_timeP);
+ //--------------------------------------------------
+ // calculate green min-max periods for each colour
+ TRACE_S("Please, place the green paper in front of colour sensor..... Starting Calibration for GREEN in ....");
+ for (uint8_t j = 5; j > 0; j--)
+ {
+ TRACE_S("....................................................... {%d} ", j);
+ vTaskDelay(1000 / portTICK_PERIOD_MS); // 4sec
+ }
+ // choose GREEN filter
+ tcs230_set_filter_color(item, COLOR_SENSOR_COLOR_GREEN);
+ calculate_max_min_color_values(user_data->TCS230_pin.gpio_output_en,
+ user_data->TCS230_pin.gpio_pulse_output,
+ &user_data->calib_data.least_green_timeP,
+ &user_data->calib_data.most_green_timeP);
- //--------------------------------------------------
- // calculate blue min-max periods for each colour
- TRACE_I("Please, place the blue paper in front of colour sensor..... Starting Calibration for BLUE in ....");
- for (uint8_t j = 5; j > 0; j--)
- {
- TRACE_I("....................................................... {%d} ", j);
- vTaskDelay(1000 / portTICK_PERIOD_MS); // 4sec
- }
- // choose BLUE filter
- tcs230_set_filter_color(item, COLOR_SENSOR_COLOR_BLUE);
- calculate_max_min_color_values(user_data->TCS230_pin.gpio_output_en,
- user_data->TCS230_pin.gpio_pulse_output,
- &user_data->calib_data.least_blue_timeP,
- &user_data->calib_data.most_blue_timeP);
+ //--------------------------------------------------
+ // calculate blue min-max periods for each colour
+ TRACE_I("Please, place the blue paper in front of colour sensor..... Starting Calibration for BLUE in ....");
+ for (uint8_t j = 5; j > 0; j--)
+ {
+ TRACE_I("....................................................... {%d} ", j);
+ vTaskDelay(1000 / portTICK_PERIOD_MS); // 4sec
+ }
+ // choose BLUE filter
+ tcs230_set_filter_color(item, COLOR_SENSOR_COLOR_BLUE);
+ calculate_max_min_color_values(user_data->TCS230_pin.gpio_output_en,
+ user_data->TCS230_pin.gpio_pulse_output,
+ &user_data->calib_data.least_blue_timeP,
+ &user_data->calib_data.most_blue_timeP);
- //--------------------------------------------------
- // show (LOW,HIGH) -> (max,min)
+ //--------------------------------------------------
+ // show (LOW,HIGH) -> (max,min)
#endif
- user_data->calib_data.least_red_timeP = 120; /*Defaults*/
- user_data->calib_data.most_red_timeP = 48;
- user_data->calib_data.least_green_timeP = 109;
- user_data->calib_data.most_green_timeP = 86;
- user_data->calib_data.least_blue_timeP = 120;
- user_data->calib_data.most_blue_timeP = 78;
+ user_data->calib_data.least_red_timeP = 120; /*Defaults*/
+ user_data->calib_data.most_red_timeP = 48;
+ user_data->calib_data.least_green_timeP = 109;
+ user_data->calib_data.most_green_timeP = 86;
+ user_data->calib_data.least_blue_timeP = 120;
+ user_data->calib_data.most_blue_timeP = 78;
- TRACE_I("red(Least,Most) => red(%d,%d)", user_data->calib_data.least_red_timeP, user_data->calib_data.most_red_timeP);
- TRACE_I("green(Least,Most) => green(%d,%d)", user_data->calib_data.least_green_timeP, user_data->calib_data.most_green_timeP);
- TRACE_I("blue(Least,Most) => blue(%d,%d)", user_data->calib_data.least_blue_timeP, user_data->calib_data.most_blue_timeP);
- //--------------------------------------------------
- // set the calib flag
- user_data->calibration_complete = true;
+ TRACE_I("red(Least,Most) => red(%d,%d)", user_data->calib_data.least_red_timeP, user_data->calib_data.most_red_timeP);
+ TRACE_I("green(Least,Most) => green(%d,%d)", user_data->calib_data.least_green_timeP, user_data->calib_data.most_green_timeP);
+ TRACE_I("blue(Least,Most) => blue(%d,%d)", user_data->calib_data.least_blue_timeP, user_data->calib_data.most_blue_timeP);
+ //--------------------------------------------------
+ // set the calib flag
+ user_data->calibration_complete = true;
+ }
}
vTaskDelete(NULL);
}
diff --git a/ezlopi-sensors-devices/sensor-0041-ADC-FC28-soilMoisture/sensor_0041_ADC_FC28_soilMoisture.c b/ezlopi-sensors-devices/sensor-0041-ADC-FC28-soilMoisture/sensor_0041_ADC_FC28_soilMoisture.c
index eae0df460..4f1aa59f3 100644
--- a/ezlopi-sensors-devices/sensor-0041-ADC-FC28-soilMoisture/sensor_0041_ADC_FC28_soilMoisture.c
+++ b/ezlopi-sensors-devices/sensor-0041-ADC-FC28-soilMoisture/sensor_0041_ADC_FC28_soilMoisture.c
@@ -141,19 +141,33 @@ static int __0041_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ s_fc28_data_t *user_data = (s_fc28_data_t *)item->user_arg;
+ if (user_data)
{
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ {
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -168,12 +182,18 @@ static int __0041_get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (cj_result)
{
s_fc28_data_t *user_data = (s_fc28_data_t *)item->user_arg;
- char *valueFormatted = ezlopi_valueformatter_uint32(user_data->hum_val);
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_result, "value", (user_data->hum_val));
- // TRACE_S("soil moisture : %d", user_data->hum_val);
- free(valueFormatted);
- ret = 1;
+ if (user_data)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (user_data->hum_val));
+ char *valueFormatted = ezlopi_valueformatter_uint32(user_data->hum_val);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ // TRACE_S("soil moisture : %d", user_data->hum_val);
+ free(valueFormatted);
+ }
+ ret = 1;
+ }
}
}
return ret;
@@ -185,17 +205,20 @@ static int __0041_notify(l_ezlopi_item_t *item)
if (item)
{
s_fc28_data_t *user_data = (s_fc28_data_t *)item->user_arg;
- s_ezlopi_analog_data_t ezlopi_adc_data = {.value = 0, .voltage = 0};
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_adc_data);
- uint32_t new_hum = ((4095.0f - (ezlopi_adc_data.value)) / 4095.0f) * 100;
- TRACE_S("[%dmv] soil moisture : %d", ezlopi_adc_data.voltage, new_hum);
-
- if (fabs((user_data->hum_val) - new_hum) > 0.5) // percent
+ if (user_data)
{
- user_data->hum_val = new_hum;
- ezlopi_device_value_updated_from_device_v3(item);
+ s_ezlopi_analog_data_t ezlopi_adc_data = {.value = 0, .voltage = 0};
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_adc_data);
+ uint32_t new_hum = ((4095.0f - (ezlopi_adc_data.value)) / 4095.0f) * 100;
+ TRACE_S("[%dmv] soil moisture : %d", ezlopi_adc_data.voltage, new_hum);
+
+ if (fabs((user_data->hum_val) - new_hum) > 0.5) // percent
+ {
+ user_data->hum_val = new_hum;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
+ ret = 1;
}
- ret = 1;
}
return ret;
}
diff --git a/ezlopi-sensors-devices/sensor-0042-ADC-shunt-voltmeter/sensor_0042_ADC_shunt_voltmeter.c b/ezlopi-sensors-devices/sensor-0042-ADC-shunt-voltmeter/sensor_0042_ADC_shunt_voltmeter.c
index f5a345b2d..d7d7ed4e5 100644
--- a/ezlopi-sensors-devices/sensor-0042-ADC-shunt-voltmeter/sensor_0042_ADC_shunt_voltmeter.c
+++ b/ezlopi-sensors-devices/sensor-0042-ADC-shunt-voltmeter/sensor_0042_ADC_shunt_voltmeter.c
@@ -82,8 +82,8 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.value_type = value_type_electric_potential;
item->cloud_properties.scale = scales_volt;
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, "gpio", item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.adc.gpio_num);
item->interface.adc.resln_bit = 3; // ADC 12_bit
// passing the custom data_structure
@@ -134,21 +134,37 @@ static int __0042_init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
- {
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
- }
- if (0 == ret)
+ s_voltmeter_t *user_data = (s_voltmeter_t *)item->user_arg;
+ if (user_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ {
+ // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -162,16 +178,22 @@ static int __0042_get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (cj_result)
{
s_voltmeter_t *user_data = (s_voltmeter_t *)item->user_arg;
+ if (user_data)
+ {
#if VOLTAGE_DIVIDER_EN
- char *valueFormatted = ezlopi_valueformatter_float((user_data->volt) * 9.52f);
- cJSON_AddNumberToObject(cj_result, "value", (user_data->volt) * 9.52f);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (user_data->volt) * 9.52f);
+ char *valueFormatted = ezlopi_valueformatter_float((user_data->volt) * 9.52f);
#else
- char *valueFormatted = ezlopi_valueformatter_float((user_data->volt) * 4.2f);
- cJSON_AddNumberToObject(cj_result, "value", (user_data->volt) * 4.2f);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (user_data->volt) * 4.2f);
+ char *valueFormatted = ezlopi_valueformatter_float((user_data->volt) * 4.2f);
#endif
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- free(valueFormatted);
- ret = 1;
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ ret = 1;
+ }
}
}
return ret;
@@ -183,16 +205,19 @@ static int __0042_notify(l_ezlopi_item_t *item)
if (item)
{
s_voltmeter_t *user_data = (s_voltmeter_t *)item->user_arg;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
- float Vout = (ezlopi_analog_data.voltage) / 1000.0f; // millivolt -> voltage
-
- if (fabs(Vout - (user_data->volt)) > 0.5)
+ if (user_data)
{
- user_data->volt = Vout;
- ezlopi_device_value_updated_from_device_v3(item);
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
+ float Vout = (ezlopi_analog_data.voltage) / 1000.0f; // millivolt -> voltage
+
+ if (fabs(Vout - (user_data->volt)) > 0.5)
+ {
+ user_data->volt = Vout;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
+ ret = 1;
}
- ret = 1;
}
return ret;
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0043-ADC-GYML8511-UV-intensity/sensor_0043_ADC_GYML8511_UV_intensity.c b/ezlopi-sensors-devices/sensor-0043-ADC-GYML8511-UV-intensity/sensor_0043_ADC_GYML8511_UV_intensity.c
index 8911a1f06..a73fefa4e 100644
--- a/ezlopi-sensors-devices/sensor-0043-ADC-GYML8511-UV-intensity/sensor_0043_ADC_GYML8511_UV_intensity.c
+++ b/ezlopi-sensors-devices/sensor-0043-ADC-GYML8511-UV-intensity/sensor_0043_ADC_GYML8511_UV_intensity.c
@@ -142,20 +142,36 @@ static int __0043_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
- {
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
- }
- if (0 == ret)
+ s_gyml8511_data_t *user_data = (s_gyml8511_data_t *)item->user_arg;
+ if (user_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ {
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -169,14 +185,16 @@ static int __0043_get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (cj_result)
{
s_gyml8511_data_t *user_data = (s_gyml8511_data_t *)item->user_arg;
+ if (user_data)
+ {
+ char *valueFormatted = ezlopi_valueformatter_float((user_data->uv_data) / 10); // [mW/cm^2] -> [W/m^2]
+ cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
+ cJSON_AddNumberToObject(cj_result, "value", (user_data->uv_data) / 10); // [mW/cm^2] -> [W/m^2]
+ // TRACE_I("UV_intensity : %.2f", user_data->uv_data);
+ free(valueFormatted);
- char *valueFormatted = ezlopi_valueformatter_float((user_data->uv_data) / 10); // [mW/cm^2] -> [W/m^2]
- cJSON_AddStringToObject(cj_result, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_result, "value", (user_data->uv_data) / 10); // [mW/cm^2] -> [W/m^2]
- // TRACE_S("UV_intensity : %.2f", user_data->uv_data);
- free(valueFormatted);
-
- ret = 1;
+ ret = 1;
+ }
}
}
return ret;
@@ -188,16 +206,19 @@ static int __0043_notify(l_ezlopi_item_t *item)
if (item)
{
s_gyml8511_data_t *user_data = (s_gyml8511_data_t *)item->user_arg;
- s_ezlopi_analog_data_t adc_data = {.value = 0, .voltage = 0};
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &adc_data);
- float new_uvIntensity = mapfloat(((float)(adc_data.voltage) / 1000), 0.97, 2.7, 0.0, 15.0);
- TRACE_S("%dmv -> intensity: %.2f", adc_data.voltage, new_uvIntensity);
- if (fabs((user_data->uv_data) - new_uvIntensity) > 0.01)
+ if (user_data)
{
- user_data->uv_data = new_uvIntensity;
- ezlopi_device_value_updated_from_device_v3(item);
+ s_ezlopi_analog_data_t adc_data = {.value = 0, .voltage = 0};
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &adc_data);
+ float new_uvIntensity = mapfloat(((float)(adc_data.voltage) / 1000), 0.97, 2.7, 0.0, 15.0);
+ TRACE_S("%dmv -> intensity: %.2f", adc_data.voltage, new_uvIntensity);
+ if (fabs((user_data->uv_data) - new_uvIntensity) > 0.01)
+ {
+ user_data->uv_data = new_uvIntensity;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
+ ret = 1;
}
- ret = 1;
}
return ret;
}
diff --git a/ezlopi-sensors-devices/sensor-0044-I2C-TSL256-luminosity/sensor_0044_I2C_TSL256_luminosity.c b/ezlopi-sensors-devices/sensor-0044-I2C-TSL256-luminosity/sensor_0044_I2C_TSL256_luminosity.c
index dccc79530..6eaabdbaa 100644
--- a/ezlopi-sensors-devices/sensor-0044-I2C-TSL256-luminosity/sensor_0044_I2C_TSL256_luminosity.c
+++ b/ezlopi-sensors-devices/sensor-0044-I2C-TSL256-luminosity/sensor_0044_I2C_TSL256_luminosity.c
@@ -63,11 +63,8 @@ static int __notify(l_ezlopi_item_t *item)
// Allow only significant changes in values to be posted
double new_value = (double)tsl2561_get_intensity_value(&item->interface.i2c_master);
TSL256_lum_t *TSL2561_lux_data = (TSL256_lum_t *)item->user_arg;
- if (fabs((double)(TSL2561_lux_data->lux_val) - new_value) > 0.0001)
+ if (TSL2561_lux_data)
{
- // Allow only significant changes in values to be posted
- double new_value = (double)tsl2561_get_intensity_value(&item->interface.i2c_master);
- TSL256_lum_t *TSL2561_lux_data = (TSL256_lum_t *)item->user_arg;
if (fabs((double)(TSL2561_lux_data->lux_val) - new_value) > 0.0001)
{
ezlopi_device_value_updated_from_device_v3(item);
@@ -85,15 +82,18 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (cjson_properties)
{
TSL256_lum_t *illuminance_value = ((TSL256_lum_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_int((int)(illuminance_value->lux_val));
- if (valueFormatted)
+ if (illuminance_value)
{
- cJSON_AddStringToObject(cjson_properties, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ char *valueFormatted = ezlopi_valueformatter_int((int)(illuminance_value->lux_val));
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cjson_properties, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ cJSON_AddNumberToObject(cjson_properties, ezlopi_value_str, (int)illuminance_value->lux_val);
+ cJSON_AddStringToObject(cjson_properties, ezlopi_scale_str, item->cloud_properties.scale);
+ ret = 1;
}
- cJSON_AddNumberToObject(cjson_properties, "values", (int)illuminance_value->lux_val);
- cJSON_AddStringToObject(cjson_properties, "scales", item->cloud_properties.scale);
- ret = 1;
}
return ret;
}
@@ -102,25 +102,35 @@ static int __init(l_ezlopi_item_t *item)
{
int ret = 0;
- if (item->interface.i2c_master.enable)
+ if (item)
{
- ezlopi_i2c_master_init(&item->interface.i2c_master);
- TRACE_I("I2C channel is %d", item->interface.i2c_master.channel);
- if (Check_PARTID(&item->interface.i2c_master))
+ TSL256_lum_t *TSL2561_lux_data = (TSL256_lum_t *)item->user_arg;
+ if (TSL2561_lux_data)
{
- TRACE_I("TSL561 initialization finished.........");
- sensor_0044_tsl2561_configure_device(&item->interface.i2c_master);
- ret = 1;
+ if (item->interface.i2c_master.enable)
+ {
+ ezlopi_i2c_master_init(&item->interface.i2c_master);
+ TRACE_I("I2C channel is %d", item->interface.i2c_master.channel);
+ if (Check_PARTID(&item->interface.i2c_master))
+ {
+ TRACE_I("TSL561 initialization finished.........");
+ sensor_0044_tsl2561_configure_device(&item->interface.i2c_master);
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ TRACE_E("TSL561 not found!....... Please Restart!! or Check your I2C connection...");
+ }
+ }
}
else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
- TRACE_E("TSL561 not found!....... Please Restart!! or Check your I2C connection...");
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -173,7 +183,7 @@ static int __prepare(void *arg)
if (prep_arg && prep_arg->cjson_device)
{
TSL256_lum_t *TSL2561_lux_data = (TSL256_lum_t *)malloc(sizeof(TSL256_lum_t));
- if (NULL != TSL2561_lux_data)
+ if (TSL2561_lux_data)
{
memset(TSL2561_lux_data, 0, sizeof(TSL256_lum_t));
l_ezlopi_device_t *tsl256_device = ezlopi_device_add_device(prep_arg->cjson_device);
diff --git a/ezlopi-sensors-devices/sensor-0046-ADC-ACS712-05B-currentmeter/sensor_0046_ADC_ACS712_05B_currentmeter.c b/ezlopi-sensors-devices/sensor-0046-ADC-ACS712-05B-currentmeter/sensor_0046_ADC_ACS712_05B_currentmeter.c
index 7cb6d682a..e5942fba9 100644
--- a/ezlopi-sensors-devices/sensor-0046-ADC-ACS712-05B-currentmeter/sensor_0046_ADC_ACS712_05B_currentmeter.c
+++ b/ezlopi-sensors-devices/sensor-0046-ADC-ACS712-05B-currentmeter/sensor_0046_ADC_ACS712_05B_currentmeter.c
@@ -22,13 +22,13 @@ typedef struct s_currentmeter
float amp_value;
} s_currentmeter_t;
-static int __0046_prepare(void *arg);
-static int __0046_init(l_ezlopi_item_t *item);
-static int __0046_get_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __0046_notify(l_ezlopi_item_t *item);
-static void __calculate_current_value(l_ezlopi_item_t *item);
+static int __0046_prepare(void* arg);
+static int __0046_init(l_ezlopi_item_t* item);
+static int __0046_get_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __0046_notify(l_ezlopi_item_t* item);
+static void __calculate_current_value(l_ezlopi_item_t* item);
-int sensor_0046_ADC_ACS712_05B_currentmeter(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0046_ADC_ACS712_05B_currentmeter(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -62,9 +62,9 @@ int sensor_0046_ADC_ACS712_05B_currentmeter(e_ezlopi_actions_t action, l_ezlopi_
return ret;
}
-static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
- char *device_name = NULL;
+ char* device_name = NULL;
CJSON_GET_VALUE_STRING(cj_device, "dev_name", device_name);
ASSIGN_DEVICE_NAME_V2(device, device_name);
device->cloud_properties.device_id = ezlopi_cloud_generate_device_id();
@@ -74,7 +74,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.info = NULL;
device->cloud_properties.device_type = dev_type_sensor;
}
-static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data)
+static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data)
{
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.has_getter = true;
@@ -84,8 +84,8 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.value_type = value_type_electric_current;
item->cloud_properties.scale = scales_ampere;
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, "gpio", item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.adc.gpio_num);
item->interface.adc.resln_bit = 3; // ADC 12_bit
// passing the custom data_structure
@@ -93,21 +93,21 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
}
//----------------------------------------------------
-static int __0046_prepare(void *arg)
+static int __0046_prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* device_prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
s_currentmeter_t *user_data = (s_currentmeter_t *)malloc(sizeof(s_currentmeter_t));
- if (NULL != user_data)
+ if (user_data)
{
memset(user_data, 0, sizeof(s_currentmeter_t));
- l_ezlopi_device_t *currentmeter_device = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t* currentmeter_device = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (currentmeter_device)
{
__prepare_device_cloud_properties(currentmeter_device, device_prep_arg->cjson_device);
- l_ezlopi_item_t *currentmeter_item = ezlopi_device_add_item_to_device(currentmeter_device, sensor_0046_ADC_ACS712_05B_currentmeter);
+ l_ezlopi_item_t* currentmeter_item = ezlopi_device_add_item_to_device(currentmeter_device, sensor_0046_ADC_ACS712_05B_currentmeter);
if (currentmeter_item)
{
__prepare_item_cloud_properties(currentmeter_item, device_prep_arg->cjson_device, user_data);
@@ -130,108 +130,139 @@ static int __0046_prepare(void *arg)
return ret;
}
-static int __0046_init(l_ezlopi_item_t *item)
+static int __0046_init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
- {
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
- }
- if (0 == ret)
+ s_currentmeter_t *user_data = (s_currentmeter_t *)item->user_arg;
+ if (user_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ {
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
{
+ ret = -1;
free(item->user_arg);
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
-static int __0046_get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __0046_get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
- cJSON *cjson_properties = (cJSON *)arg;
- if (cjson_properties && item)
+ if (item)
{
- s_currentmeter_t *user_data = (s_currentmeter_t *)item->user_arg;
- char *valueFormatted = ezlopi_valueformatter_float(user_data->amp_value);
- cJSON_AddStringToObject(cjson_properties, "valueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cjson_properties, "value", user_data->amp_value); // Irms [A]
- free(valueFormatted);
- ret = 1;
+ cJSON *cjson_properties = (cJSON *)arg;
+ if (cjson_properties && item)
+ {
+ s_currentmeter_t *user_data = (s_currentmeter_t *)item->user_arg;
+ if (user_data)
+ {
+ cJSON_AddNumberToObject(cjson_properties, ezlopi_value_str, user_data->amp_value); // Irms [A]
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->amp_value);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cjson_properties, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ ret = 1;
+ }
+ }
}
return ret;
}
-static int __0046_notify(l_ezlopi_item_t *item)
+static int __0046_notify(l_ezlopi_item_t* item)
{
// During this calculation the system is polled for 20mS
int ret = 0;
if (item)
{
s_currentmeter_t *user_data = (s_currentmeter_t *)item->user_arg;
- float prev_amp = user_data->amp_value;
- __calculate_current_value(item); // update amp
- if (fabs(user_data->amp_value - prev_amp) > 0.5)
+ if (user_data)
{
- ezlopi_device_value_updated_from_device_v3(item);
+ float prev_amp = user_data->amp_value;
+ __calculate_current_value(item); // update amp
+ if (fabs(user_data->amp_value - prev_amp) > 0.5)
+ {
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
return ret;
}
//--------------------------------------------------------------------------------------------------------------------------------------
-static void __calculate_current_value(l_ezlopi_item_t *item)
+static void __calculate_current_value(l_ezlopi_item_t* item)
{
if (NULL != item)
{
s_currentmeter_t *user_data = (s_currentmeter_t *)item->user_arg;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
-
- uint32_t period_dur = (1000000 / DEFAULT_AC_FREQUENCY); // 20000uS
- int Vnow = 0;
- uint32_t Vsum = 0;
- uint32_t measurements_count = 0;
-
- // starting 't' instant
- uint32_t t_start = (uint32_t)esp_timer_get_time();
- uint32_t Volt = 0;
- int diff = 0;
- PORT_ENTER_CRITICAL();
- while (((uint32_t)esp_timer_get_time() - t_start) < period_dur) // loops within 1-complete cycle
+ if (user_data)
{
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
- Volt = 2 * (ezlopi_analog_data.voltage); // since the input is half the original value after voltage division
- diff = ((ASC712TELC_05B_zero_point_mV - Volt) > 0 ? (ASC712TELC_05B_zero_point_mV - Volt) : (Volt - ASC712TELC_05B_zero_point_mV));
- // getting the voltage value at this instant
- if (diff > 150 && diff < 1500) // the reading voltage less than 00mV is noise
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+
+ uint32_t period_dur = (1000000 / DEFAULT_AC_FREQUENCY); // 20000uS
+ int Vnow = 0;
+ uint32_t Vsum = 0;
+ uint32_t measurements_count = 0;
+
+ // starting 't' instant
+ uint32_t t_start = (uint32_t)esp_timer_get_time();
+ uint32_t Volt = 0;
+ int diff = 0;
+ PORT_ENTER_CRITICAL();
+ while (((uint32_t)esp_timer_get_time() - t_start) < period_dur) // loops within 1-complete cycle
{
- Vnow = Volt - ASC712TELC_05B_zero_point_mV; // ()at zero offset => full-scale/2
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
+ Volt = 2 * (ezlopi_analog_data.voltage); // since the input is half the original value after voltage division
+ diff = ((ASC712TELC_05B_zero_point_mV - Volt) > 0 ? (ASC712TELC_05B_zero_point_mV - Volt) : (Volt - ASC712TELC_05B_zero_point_mV));
+ // getting the voltage value at this instant
+ if (diff > 150 && diff < 1500) // the reading voltage less than 00mV is noise
+ {
+ Vnow = Volt - ASC712TELC_05B_zero_point_mV; // ()at zero offset => full-scale/2
+ }
+ else
+ {
+ Vnow = 0;
+ }
+ Vsum += (Vnow * Vnow); // sumof(I^2 + I^2 + .....)
+ measurements_count++;
}
- else
+ PORT_EXIT_CRITICAL();
+
+ // If applied for DC; 'AC_Irms' calculation give same value as 'DC-value'
+ if (0 == measurements_count)
{
- Vnow = 0;
+ measurements_count = 1; // <-- avoid dividing by zero
}
- Vsum += (Vnow * Vnow); // sumof(I^2 + I^2 + .....)
- measurements_count++;
- }
- PORT_EXIT_CRITICAL();
- // If applied for DC; 'AC_Irms' calculation give same value as 'DC-value'
- if (0 == measurements_count)
- {
- measurements_count = 1; // <-- avoid dividing by zero
- }
-
- user_data->amp_value = ((float)sqrt(Vsum / measurements_count)) / 185.0f; // -> I[rms] Ampere
- if ((user_data->amp_value) < 0.4)
- {
- user_data->amp_value = 0;
+ user_data->amp_value = ((float)sqrt(Vsum / measurements_count)) / 185.0f; // -> I[rms] Ampere
+ if ((user_data->amp_value) < 0.4)
+ {
+ user_data->amp_value = 0;
+ }
}
}
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0047-other-HX711-loadcell/sensor_0047_other_HX711_loadcell.c b/ezlopi-sensors-devices/sensor-0047-other-HX711-loadcell/sensor_0047_other_HX711_loadcell.c
index 89acff5cc..a36be35b2 100644
--- a/ezlopi-sensors-devices/sensor-0047-other-HX711-loadcell/sensor_0047_other_HX711_loadcell.c
+++ b/ezlopi-sensors-devices/sensor-0047-other-HX711-loadcell/sensor_0047_other_HX711_loadcell.c
@@ -69,14 +69,9 @@ int sensor_0047_other_HX711_loadcell(e_ezlopi_actions_t action, l_ezlopi_item_t
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- if (item)
- {
- s_hx711_data_t *user_data = (s_hx711_data_t *)item->user_arg;
- if (true == user_data->HX711_initialized)
- {
- __0047_notify(item);
- }
- }
+
+ __0047_notify(item);
+
break;
}
default:
@@ -112,9 +107,9 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type); // _max = 10
CJSON_GET_VALUE_INT(cj_device, "gpio1", user_data->HX711_SCK_pin);
- TRACE_S("hx711_SCL_PIN: %d ", user_data->HX711_SCK_pin);
+ TRACE_I("hx711_SCL_PIN: %d ", user_data->HX711_SCK_pin);
CJSON_GET_VALUE_INT(cj_device, "gpio2", user_data->HX711_DT_pin);
- TRACE_S("hx711_DT_PIN: %d ", user_data->HX711_DT_pin);
+ TRACE_I("hx711_DT_PIN: %d ", user_data->HX711_DT_pin);
}
static int __0047_prepare(void *arg)
@@ -161,43 +156,57 @@ static int __0047_init(l_ezlopi_item_t *item)
if (item)
{
s_hx711_data_t *user_data = (s_hx711_data_t *)item->user_arg;
- if (user_data && GPIO_IS_VALID_GPIO(user_data->HX711_SCK_pin) && (GPIO_IS_VALID_GPIO(user_data->HX711_DT_pin)))
+ if (user_data)
{
- // Configure 'CLOCK_PIN' -> GPIO output pins for HX711.
- gpio_config_t output_conf;
- output_conf.pin_bit_mask = (1ULL << (user_data->HX711_SCK_pin));
- output_conf.intr_type = GPIO_INTR_DISABLE;
- output_conf.mode = GPIO_MODE_OUTPUT;
- output_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
- output_conf.pull_up_en = GPIO_PULLUP_DISABLE;
- ret |= gpio_config(&output_conf);
-
- // Configure 'DATA_PIN' -> GPIO input pins for HX711.
- gpio_config_t input_conf;
- input_conf.pin_bit_mask = (1ULL << (user_data->HX711_DT_pin));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
- input_conf.pull_up_en = GPIO_PULLUP_DISABLE;
- ret |= gpio_config(&input_conf);
-
- // then initiate calibration task
- if (false == (user_data->HX711_initialized))
+ if (GPIO_IS_VALID_GPIO(user_data->HX711_SCK_pin) && (GPIO_IS_VALID_GPIO(user_data->HX711_DT_pin)))
{
- __hx711_power_reset(item);
- xTaskCreate(__Calculate_hx711_tare_wt, "Calculate the Tare weight", 2 * 2048, item, 1, NULL);
+ // Configure 'CLOCK_PIN' -> GPIO output pins for HX711.
+ gpio_config_t output_conf;
+ output_conf.pin_bit_mask = (1ULL << (user_data->HX711_SCK_pin));
+ output_conf.intr_type = GPIO_INTR_DISABLE;
+ output_conf.mode = GPIO_MODE_OUTPUT;
+ output_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
+ output_conf.pull_up_en = GPIO_PULLUP_DISABLE;
+
+ ret = (0 == gpio_config(&output_conf)) ? 1 : -1;
+
+ // Configure 'DATA_PIN' -> GPIO input pins for HX711.
+ gpio_config_t input_conf;
+ input_conf.pin_bit_mask = (1ULL << (user_data->HX711_DT_pin));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_DISABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+
+ // then initiate calibration task
+ if ((1 == ret) && (false == (user_data->HX711_initialized)))
+ {
+ __hx711_power_reset(item);
+ xTaskCreate(__Calculate_hx711_tare_wt, "Calculate the Tare weight", 2 * 2048, item, 1, NULL);
+ ret = 1;
+ }
+
+ if (-1 == ret)
+ {
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -212,10 +221,13 @@ static int __0047_get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (cj_result)
{
s_hx711_data_t *user_data = (s_hx711_data_t *)item->user_arg;
- char *valueFormatted = ezlopi_valueformatter_float(user_data->weight);
- cJSON_AddStringToObject(cj_result, "ValueFormatted", valueFormatted);
- cJSON_AddNumberToObject(cj_result, "value", user_data->weight);
- free(valueFormatted);
+ if (user_data)
+ {
+ char *valueFormatted = ezlopi_valueformatter_float(user_data->weight);
+ cJSON_AddStringToObject(cj_result, "ValueFormatted", valueFormatted);
+ cJSON_AddNumberToObject(cj_result, "value", user_data->weight);
+ free(valueFormatted);
+ }
}
ret = 1;
}
@@ -228,20 +240,23 @@ static int __0047_notify(l_ezlopi_item_t *item)
if (item)
{
s_hx711_data_t *user_data = (s_hx711_data_t *)item->user_arg;
- float Mass = __hx711_avg_reading(item, 10); /// 1000.0f; // to avoid spikes
- float weight_in_kg = ((Mass - (user_data->HX711_tare_wt)) / 100.0f) / 1000.0f;
-
- if (fabs(weight_in_kg - (user_data->weight)) > 0.05)
+ if ((user_data) && (true == user_data->HX711_initialized))
{
- if (weight_in_kg < 0)
+ float Mass = __hx711_avg_reading(item, 10); /// 1000.0f; // to avoid spikes
+ float weight_in_kg = ((Mass - (user_data->HX711_tare_wt)) / 100.0f) / 1000.0f;
+
+ if (fabs(weight_in_kg - (user_data->weight)) > 0.05)
{
- weight_in_kg = 0;
+ if (weight_in_kg < 0)
+ {
+ weight_in_kg = 0;
+ }
+ user_data->weight = weight_in_kg;
+ // TRACE_I("Mass : %0.2f unit , _Offset : %0.2f unit , Actual_Mass : %0.2f kg ,", Mass, (user_data->HX711_tare_wt), weight_in_kg);
+ ezlopi_device_value_updated_from_device_v3(item);
}
- user_data->weight = weight_in_kg;
- // TRACE_S("Mass : %0.2f unit , _Offset : %0.2f unit , Actual_Mass : %0.2f kg ,", Mass, (user_data->HX711_tare_wt), weight_in_kg);
- ezlopi_device_value_updated_from_device_v3(item);
+ ret = 1;
}
- ret = 1;
}
return ret;
}
@@ -253,28 +268,30 @@ static void __Calculate_hx711_tare_wt(void *params)
if (item)
{
s_hx711_data_t *user_data = (s_hx711_data_t *)item->user_arg;
- // For Output settling time ; [10SPS] is 400ms
- // So, wait for 400ms after reset [as per datasheet]
- vTaskDelay(400 / portTICK_PERIOD_MS);
+ if (user_data)
+ { // For Output settling time ; [10SPS] is 400ms
+ // So, wait for 400ms after reset [as per datasheet]
+ vTaskDelay(400 / portTICK_PERIOD_MS);
- // ignore first few weight readings [150th ~ 180th]
- for (uint8_t i = 180; i > 0; i--)
- {
- RAW_tare = __hx711_rawdata(item, HX711_GAIN_64); // 100ms each read
- if (i > 150)
+ // ignore first few weight readings [150th ~ 180th]
+ for (uint8_t i = 180; i > 0; i--)
{
- (user_data->HX711_tare_wt) = (RAW_tare);
+ RAW_tare = __hx711_rawdata(item, HX711_GAIN_64); // 100ms each read
+ if (i > 150)
+ {
+ (user_data->HX711_tare_wt) = (RAW_tare);
+ }
+ else
+ {
+ (user_data->HX711_tare_wt) = 0.2f * (user_data->HX711_tare_wt) + 0.8f * (RAW_tare);
+ }
+ TRACE_I("Calibration_No : %d , Raw_data : %.2f", i, RAW_tare);
}
- else
+ TRACE_I("Calibration Stage ----------> Tare_Offset : %0.2f ", (user_data->HX711_tare_wt));
+ if ((user_data->HX711_tare_wt) > 3000)
{
- (user_data->HX711_tare_wt) = 0.2f * (user_data->HX711_tare_wt) + 0.8f * (RAW_tare);
+ user_data->HX711_initialized = true;
}
- TRACE_S("Calibration_No : %d , Raw_data : %.2f", i, RAW_tare);
- }
- TRACE_S("Calibration Stage ----------> Tare_Offset : %0.2f ", (user_data->HX711_tare_wt));
- if ((user_data->HX711_tare_wt) > 3000)
- {
- user_data->HX711_initialized = true;
}
}
vTaskDelete(NULL);
@@ -287,57 +304,61 @@ static float __hx711_rawdata(l_ezlopi_item_t *item, hx711_gain_t _gain)
if (item)
{
s_hx711_data_t *user_data = (s_hx711_data_t *)item->user_arg;
- vTaskDelay(8); // 80ms
- // first check if the data is ready [i.e. 'data_pin' = 1 ; when 'clk_pin' = 0]
- if (gpio_get_level(user_data->HX711_DT_pin))
+ if (user_data)
{
- // TRACE_E("Data_pin not ready..................");
- do
+ vTaskDelay(8); // 80ms
+ // first check if the data is ready [i.e. 'data_pin' = 1 ; when 'clk_pin' = 0]
+
+ if (gpio_get_level(user_data->HX711_DT_pin))
{
- vTaskDelay(2); // 20ms
- } while (gpio_get_level(user_data->HX711_DT_pin));
- }
+ // TRACE_E("Data_pin not ready..................");
+ do
+ {
+ vTaskDelay(2); // 20ms
+ } while (gpio_get_level(user_data->HX711_DT_pin));
+ }
- PORT_ENTER_CRITICAL();
- /* STEP 1*/
- // perform 24bits read
- for (uint8_t i = 0; i < 24; i++)
- {
- gpio_set_level(user_data->HX711_SCK_pin, 1);
- esp_rom_delay_us(1); // >= 0.2 us
- gpio_set_level(user_data->HX711_SCK_pin, 0);
- data = (data << 1); // shift the 'result' by 1 bit
- if (gpio_get_level(user_data->HX711_DT_pin)) // if data_pin is high
+ PORT_ENTER_CRITICAL();
+ /* STEP 1*/
+ // perform 24bits read
+ for (uint8_t i = 0; i < 24; i++)
{
- data |= (1 << 0); //[ 23~0 ]step
+ gpio_set_level(user_data->HX711_SCK_pin, 1);
+ esp_rom_delay_us(1); // >= 0.2 us
+ gpio_set_level(user_data->HX711_SCK_pin, 0);
+ data = (data << 1); // shift the 'result' by 1 bit
+ if (gpio_get_level(user_data->HX711_DT_pin)) // if data_pin is high
+ {
+ data |= (1 << 0); //[ 23~0 ]step
+ }
+ esp_rom_delay_us(1); // keep duty cycle ~50%
}
- esp_rom_delay_us(1); // keep duty cycle ~50%
- }
- /* STEP 2*/
- // Apply the gain pulses to complete serial communication
- for (uint8_t n = ((uint8_t)_gain); n > 0; n--)
- {
- gpio_set_level(user_data->HX711_SCK_pin, 1); // 'n' steps
- esp_rom_delay_us(1);
- gpio_set_level(user_data->HX711_SCK_pin, 0);
- esp_rom_delay_us(1);
- }
- PORT_EXIT_CRITICAL();
+ /* STEP 2*/
+ // Apply the gain pulses to complete serial communication
+ for (uint8_t n = ((uint8_t)_gain); n > 0; n--)
+ {
+ gpio_set_level(user_data->HX711_SCK_pin, 1); // 'n' steps
+ esp_rom_delay_us(1);
+ gpio_set_level(user_data->HX711_SCK_pin, 0);
+ esp_rom_delay_us(1);
+ }
+ PORT_EXIT_CRITICAL();
- //----ending the conversion---
- // Note : 'Data_pin' is pulled high starting during step: [24~27]
- if (!gpio_get_level(user_data->HX711_DT_pin))
- {
- TRACE_E("DATA_PIN is low........................... SYSTEM BUSY");
- }
+ //----ending the conversion---
+ // Note : 'Data_pin' is pulled high starting during step: [24~27]
+ if (!gpio_get_level(user_data->HX711_DT_pin))
+ {
+ TRACE_E("DATA_PIN is low........................... SYSTEM BUSY");
+ }
- // SIGN extend
- // 24th bit is the sign bit //
- data ^= 0x800000;
+ // SIGN extend
+ // 24th bit is the sign bit //
+ data ^= 0x800000;
- raw_data = (float)data;
+ raw_data = (float)data;
+ }
}
// TRACE_E("Raw_data -> %.2f ", raw_data);
return raw_data;
@@ -368,17 +389,20 @@ static void __hx711_power_reset(l_ezlopi_item_t *item)
if (item)
{
s_hx711_data_t *user_data = (s_hx711_data_t *)item->user_arg;
- PORT_ENTER_CRITICAL();
- // Pull the clock pin low to make sure this reset condition occurs
- gpio_set_level(user_data->HX711_SCK_pin, 0);
-
- // Pull the clock pin high
- gpio_set_level(user_data->HX711_SCK_pin, 1);
- esp_rom_delay_us(70);
-
- // Pull the clock pin low for NORMAL operation
- gpio_set_level(user_data->HX711_SCK_pin, 0);
- esp_rom_delay_us(10);
- PORT_EXIT_CRITICAL();
+ if (user_data)
+ {
+ PORT_ENTER_CRITICAL();
+ // Pull the clock pin low to make sure this reset condition occurs
+ gpio_set_level(user_data->HX711_SCK_pin, 0);
+
+ // Pull the clock pin high
+ gpio_set_level(user_data->HX711_SCK_pin, 1);
+ esp_rom_delay_us(70);
+
+ // Pull the clock pin low for NORMAL operation
+ gpio_set_level(user_data->HX711_SCK_pin, 0);
+ esp_rom_delay_us(10);
+ PORT_EXIT_CRITICAL();
+ }
}
}
diff --git a/ezlopi-sensors-devices/sensor-0048-other-MQ4-CH4-detector/sensor_0048_other_MQ4_CH4_detector.c b/ezlopi-sensors-devices/sensor-0048-other-MQ4-CH4-detector/sensor_0048_other_MQ4_CH4_detector.c
index 1975a94b7..9b1ee9e89 100644
--- a/ezlopi-sensors-devices/sensor-0048-other-MQ4-CH4-detector/sensor_0048_other_MQ4_CH4_detector.c
+++ b/ezlopi-sensors-devices/sensor-0048-other-MQ4-CH4-detector/sensor_0048_other_MQ4_CH4_detector.c
@@ -73,14 +73,7 @@ int sensor_0048_other_MQ4_CH4_detector(e_ezlopi_actions_t action, l_ezlopi_item_
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- if (item)
- {
- s_mq4_value_t *MQ4_value = (s_mq4_value_t *)item->user_arg;
- if (true == MQ4_value->Calibration_complete_CH4)
- {
- __0048_notify(item);
- }
- }
+ __0048_notify(item);
break;
}
default:
@@ -156,37 +149,63 @@ static int __0048_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name))
{
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ else if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name))
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
s_mq4_value_t *MQ4_value = (s_mq4_value_t *)item->user_arg;
- if (false == MQ4_value->Calibration_complete_CH4)
+ if (MQ4_value)
{
- xTaskCreate(__calibrate_MQ4_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ { // calibrate if not done
+ if (false == MQ4_value->Calibration_complete_CH4)
+ {
+ xTaskCreate(__calibrate_MQ4_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ else
{
- free(item->user_arg);
- item->user_arg = NULL;
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
}
}
}
@@ -218,7 +237,7 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ4-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
@@ -286,10 +305,16 @@ static int __0048_get_item(l_ezlopi_item_t *item, void *arg)
if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq4_value_t *MQ4_value = ((s_mq4_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ4_value->_CH4_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ4_value->_CH4_ppm);
- free(valueFormatted);
+ if (MQ4_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ4_value->_CH4_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ4_value->_CH4_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -313,10 +338,16 @@ static int __0048_get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq4_value_t *MQ4_value = ((s_mq4_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ4_value->_CH4_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (MQ4_value->_CH4_ppm));
- free(valueFormatted);
+ if (MQ4_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, (MQ4_value->_CH4_ppm));
+ char *valueFormatted = ezlopi_valueformatter_float(MQ4_value->_CH4_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -346,15 +377,18 @@ static int __0048_notify(l_ezlopi_item_t *item)
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- // extract the sensor_output_values
- double new_value = (double)__extract_MQ4_sensor_ppm(item);
s_mq4_value_t *MQ4_value = (s_mq4_value_t *)item->user_arg;
- if (fabs((double)(MQ4_value->_CH4_ppm) - new_value) > 0.0001)
+ if ((MQ4_value) && (true == MQ4_value->Calibration_complete_CH4))
{
- ezlopi_device_value_updated_from_device_v3(item);
- MQ4_value->_CH4_ppm = (float)new_value;
+ // extract the sensor_output_values
+ double new_value = (double)__extract_MQ4_sensor_ppm(item);
+ if (fabs((double)(MQ4_value->_CH4_ppm) - new_value) > 0.0001)
+ {
+ MQ4_value->_CH4_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
@@ -364,49 +398,52 @@ static int __0048_notify(l_ezlopi_item_t *item)
//------------------------------------------------------------------------------------------------------
static float __extract_MQ4_sensor_ppm(l_ezlopi_item_t *item)
{
- uint32_t mq4_adc_pin = item->interface.adc.gpio_num;
s_mq4_value_t *MQ4_value = (s_mq4_value_t *)item->user_arg;
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- // extract the mean_sensor_analog_output_voltage
- float analog_sensor_volt = 0;
- for (uint8_t x = 10; x > 0; x--)
- {
- ezlopi_adc_get_adc_data(mq4_adc_pin, &ezlopi_analog_data);
+ if (MQ4_value)
+ { // calculation process
+ uint32_t mq4_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ // extract the mean_sensor_analog_output_voltage
+ float analog_sensor_volt = 0;
+ for (uint8_t x = 10; x > 0; x--)
+ {
+ ezlopi_adc_get_adc_data(mq4_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
+ analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
#else
- analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
+ analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
#endif
- vTaskDelay(1);
- }
- analog_sensor_volt = analog_sensor_volt / 10.0f;
+ vTaskDelay(1);
+ }
+ analog_sensor_volt = analog_sensor_volt / 10.0f;
- //-----------------------------------------------------------------------------------
- // Stage_2 : [from 'sensor_0048_ADC_MQ4_methane_gas_detector.h']
+ //-----------------------------------------------------------------------------------
+ // Stage_2 : [from 'sensor_0048_ADC_MQ4_methane_gas_detector.h']
- // 1. Calculate 'Rs_gas' for the gas detected
- float Rs_gas = (((MQ4_VOLT_RESOLUTION_Vc * mq4_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq4_eqv_RL);
+ // 1. Calculate 'Rs_gas' for the gas detected
+ float Rs_gas = (((MQ4_VOLT_RESOLUTION_Vc * mq4_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq4_eqv_RL);
- // 1.1 Calculate @ 'ratio' during CH4 presence
- double _ratio = (Rs_gas / (((MQ4_value->MQ4_R0_constant) <= 0) ? (1.0f) : (MQ4_value->MQ4_R0_constant))); // avoid dividing by zero??
- if (_ratio <= 0)
- {
- _ratio = 0;
- }
- //-------------------------------------------------
+ // 1.1 Calculate @ 'ratio' during CH4 presence
+ double _ratio = (Rs_gas / (((MQ4_value->MQ4_R0_constant) <= 0) ? (1.0f) : (MQ4_value->MQ4_R0_constant))); // avoid dividing by zero??
+ if (_ratio <= 0)
+ {
+ _ratio = 0;
+ }
+ //-------------------------------------------------
- // 1.2 Calculate _CH4_ppm
- float _CH4_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq4) / m_slope_mq4); // ---> _CH4_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
- if (_CH4_ppm < 0)
- {
- _CH4_ppm = 0; // No negative values accepted or upper datasheet recomendation.
- }
- TRACE_E("_CH4_ppm [CH4] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _CH4_ppm, (float)_ratio, analog_sensor_volt);
+ // 1.2 Calculate _CH4_ppm
+ float _CH4_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq4) / m_slope_mq4); // ---> _CH4_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
+ if (_CH4_ppm < 0)
+ {
+ _CH4_ppm = 0; // No negative values accepted or upper datasheet recomendation.
+ }
+ TRACE_E("_CH4_ppm [CH4] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _CH4_ppm, (float)_ratio, analog_sensor_volt);
+ return _CH4_ppm;
- //-------------------------------------------------
- return _CH4_ppm;
+ //-------------------------------------------------
+ }
+ return 0;
}
static void __calibrate_MQ4_R0_resistance(void *params)
@@ -415,55 +452,57 @@ static void __calibrate_MQ4_R0_resistance(void *params)
if (NULL != item)
{
s_mq4_value_t *MQ4_value = (s_mq4_value_t *)item->user_arg;
-
- uint32_t mq4_adc_pin = item->interface.adc.gpio_num;
- //-------------------------------------------------
- // let the sensor to heat for 20seconds
- for (uint8_t j = 20; j > 0; j--)
+ if (MQ4_value)
{
- TRACE_E("Heating sensor.........time left: %d sec", j);
- vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
- }
- //-------------------------------------------------
- // extract the mean_sensor_analog_output_voltage
- float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- for (uint8_t i = 100; i > 0; i--)
- {
- if (i % 20 == 0)
+ uint32_t mq4_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ // let the sensor to heat for 20seconds
+ for (uint8_t j = 20; j > 0; j--)
{
- TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ TRACE_E("Heating sensor.........time left: %d sec", j);
+ vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
}
- // extract ADC values
- ezlopi_adc_get_adc_data(mq4_adc_pin, &ezlopi_analog_data);
+ //-------------------------------------------------
+ // extract the mean_sensor_analog_output_voltage
+ float _sensor_volt = 0;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ for (uint8_t i = 100; i > 0; i--)
+ {
+ if (i % 20 == 0)
+ {
+ TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ }
+ // extract ADC values
+ ezlopi_adc_get_adc_data(mq4_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
+ _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
#else
- _sensor_volt += (float)(ezlopi_analog_data->voltage);
+ _sensor_volt += (float)(ezlopi_analog_data->voltage);
#endif
- vTaskDelay(1); // 10ms
- }
- _sensor_volt = _sensor_volt / 100.0f;
+ vTaskDelay(1); // 10ms
+ }
+ _sensor_volt = _sensor_volt / 100.0f;
- //-------------------------------------------------
- // Calculate the 'Rs' of heater during clean air [calibration phase]
- // Range -> [2Kohm - 20Kohm]
- float RS_calib = 0; // Define variable for sensor resistance
- RS_calib = ((MQ4_VOLT_RESOLUTION_Vc * mq4_eqv_RL) / (_sensor_volt / 1000.0f)) - mq4_eqv_RL; // Calculate RS in fresh air
- TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
- if (RS_calib < 0)
- {
- RS_calib = 0; // No negative values accepted.
- }
- // Calculate the R0_air which is constant through-out
- MQ4_value->MQ4_R0_constant = (RS_calib / RatioMQ4CleanAir); // Calculate MQ4_R0_constant
- TRACE_E("CALIB_TASK -> 'MQ4_R0_constant' = %.2f", (MQ4_value->MQ4_R0_constant));
- if ((MQ4_value->MQ4_R0_constant) < 0)
- {
- (MQ4_value->MQ4_R0_constant) = 0; // No negative values accepted.
+ //-------------------------------------------------
+ // Calculate the 'Rs' of heater during clean air [calibration phase]
+ // Range -> [2Kohm - 20Kohm]
+ float RS_calib = 0; // Define variable for sensor resistance
+ RS_calib = ((MQ4_VOLT_RESOLUTION_Vc * mq4_eqv_RL) / (_sensor_volt / 1000.0f)) - mq4_eqv_RL; // Calculate RS in fresh air
+ TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
+ if (RS_calib < 0)
+ {
+ RS_calib = 0; // No negative values accepted.
+ }
+ // Calculate the R0_air which is constant through-out
+ MQ4_value->MQ4_R0_constant = (RS_calib / RatioMQ4CleanAir); // Calculate MQ4_R0_constant
+ TRACE_E("CALIB_TASK -> 'MQ4_R0_constant' = %.2f", (MQ4_value->MQ4_R0_constant));
+ if ((MQ4_value->MQ4_R0_constant) < 0)
+ {
+ (MQ4_value->MQ4_R0_constant) = 0; // No negative values accepted.
+ }
+ // Set calibration_complete_CH4 flag
+ MQ4_value->Calibration_complete_CH4 = true;
}
- // Set calibration_complete_CH4 flag
- MQ4_value->Calibration_complete_CH4 = true;
}
vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0049-other-MQ2-LPG-detector/sensor_0049_other_MQ2_LPG_detector.c b/ezlopi-sensors-devices/sensor-0049-other-MQ2-LPG-detector/sensor_0049_other_MQ2_LPG_detector.c
index f8e8f4701..7f171e79e 100644
--- a/ezlopi-sensors-devices/sensor-0049-other-MQ2-LPG-detector/sensor_0049_other_MQ2_LPG_detector.c
+++ b/ezlopi-sensors-devices/sensor-0049-other-MQ2-LPG-detector/sensor_0049_other_MQ2_LPG_detector.c
@@ -24,28 +24,28 @@ typedef struct s_mq2_value
bool Calibration_complete_LPG;
} s_mq2_value_t;
-const char* mq2_sensor_gas_alarm_token[] = {
+const char *mq2_sensor_gas_alarm_token[] = {
"no_gas",
"combustible_gas_detected",
"toxic_gas_detected",
"unknown",
};
//--------------------------------------------------------------------------------------------------------
-static int __0049_prepare(void* arg);
-static int __0049_init(l_ezlopi_item_t* item);
-static int __0049_get_item(l_ezlopi_item_t* item, void* arg);
-static int __0049_get_cjson_value(l_ezlopi_item_t* item, void* arg);
-static int __0049_notify(l_ezlopi_item_t* item);
-
-static void __calibrate_MQ2_R0_resistance(void* params);
-static float __extract_MQ2_sensor_ppm(l_ezlopi_item_t* item);
-static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device);
-static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
-static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
-static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data);
+static int __0049_prepare(void *arg);
+static int __0049_init(l_ezlopi_item_t *item);
+static int __0049_get_item(l_ezlopi_item_t *item, void *arg);
+static int __0049_get_cjson_value(l_ezlopi_item_t *item, void *arg);
+static int __0049_notify(l_ezlopi_item_t *item);
+
+static void __calibrate_MQ2_R0_resistance(void *params);
+static float __extract_MQ2_sensor_ppm(l_ezlopi_item_t *item);
+static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device);
+static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
+static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
+static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data);
//--------------------------------------------------------------------------------------------------------
-int sensor_0049_other_MQ2_LPG_detector(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
+int sensor_0049_other_MQ2_LPG_detector(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
{
int ret = 0;
switch (action)
@@ -74,16 +74,10 @@ int sensor_0049_other_MQ2_LPG_detector(e_ezlopi_actions_t action, l_ezlopi_item_
{
if (item)
{
- s_mq2_value_t* MQ2_value = (s_mq2_value_t*)item->user_arg;
- if (MQ2_value)
- {
- if (true == MQ2_value->Calibration_complete_LPG)
- {
- __0049_notify(item);
- }
- break;
- }
+ __0049_notify(item);
+
+ break;
}
}
default:
@@ -95,18 +89,18 @@ int sensor_0049_other_MQ2_LPG_detector(e_ezlopi_actions_t action, l_ezlopi_item_
}
//----------------------------------------------------
-static int __0049_prepare(void* arg)
+static int __0049_prepare(void *arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t* device_prep_arg = (s_ezlopi_prep_arg_t*)arg;
+ s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
//--------------------------- DIGI - DEVICE 1 --------------------------------------------
- l_ezlopi_device_t* MQ2_device_digi = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t *MQ2_device_digi = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (MQ2_device_digi)
{
__prepare_device_digi_cloud_properties(MQ2_device_digi, device_prep_arg->cjson_device);
- l_ezlopi_item_t* MQ2_item_digi = ezlopi_device_add_item_to_device(MQ2_device_digi, sensor_0049_other_MQ2_LPG_detector);
+ l_ezlopi_item_t *MQ2_item_digi = ezlopi_device_add_item_to_device(MQ2_device_digi, sensor_0049_other_MQ2_LPG_detector);
if (MQ2_item_digi)
{
MQ2_item_digi->cloud_properties.device_id = MQ2_device_digi->cloud_properties.device_id;
@@ -121,15 +115,15 @@ static int __0049_prepare(void* arg)
}
//---------------------------- ADC - DEVICE 2 -------------------------------------------
- s_mq2_value_t* MQ2_value = (s_mq2_value_t*)malloc(sizeof(s_mq2_value_t));
+ s_mq2_value_t *MQ2_value = (s_mq2_value_t *)malloc(sizeof(s_mq2_value_t));
if (NULL != MQ2_value)
{
memset(MQ2_value, 0, sizeof(s_mq2_value_t));
- l_ezlopi_device_t* MQ2_device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t *MQ2_device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (MQ2_device_adc)
{
__prepare_device_adc_cloud_properties(MQ2_device_adc, device_prep_arg->cjson_device);
- l_ezlopi_item_t* MQ2_item_adc = ezlopi_device_add_item_to_device(MQ2_device_adc, sensor_0049_other_MQ2_LPG_detector);
+ l_ezlopi_item_t *MQ2_item_adc = ezlopi_device_add_item_to_device(MQ2_device_adc, sensor_0049_other_MQ2_LPG_detector);
if (MQ2_item_adc)
{
MQ2_item_adc->cloud_properties.device_id = MQ2_device_adc->cloud_properties.device_id;
@@ -153,45 +147,76 @@ static int __0049_prepare(void* arg)
return ret;
}
-static int __0049_init(l_ezlopi_item_t* item)
+static int __0049_init(l_ezlopi_item_t *item)
{
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
- s_mq2_value_t* MQ2_value = (s_mq2_value_t*)item->user_arg;
+ s_mq2_value_t *MQ2_value = (s_mq2_value_t *)item->user_arg;
if (MQ2_value)
{
- if (false == MQ2_value->Calibration_complete_LPG)
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ { // calibrate if not done
+ if (false == MQ2_value->Calibration_complete_LPG)
+ {
+ xTaskCreate(__calibrate_MQ2_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
{
- xTaskCreate(__calibrate_MQ2_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
}
}
-
- ret = 1;
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
+ }
}
}
return ret;
}
//------------------------------------------------------------------------------------------------------
-static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -204,7 +229,7 @@ static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t* device, cJ
device->cloud_properties.info = NULL;
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device)
+static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -215,11 +240,11 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t* item, cJSON* c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ2-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
-static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
+static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -232,7 +257,7 @@ static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t* device, cJS
device->cloud_properties.info = NULL;
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data)
+static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -252,23 +277,23 @@ static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t* item, cJSON* cj
}
//------------------------------------------------------------------------------------------------------
-static int __0049_get_item(l_ezlopi_item_t* item, void* arg)
+static int __0049_get_item(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
if (item && arg)
{
- cJSON* cj_result = (cJSON*)arg;
+ cJSON *cj_result = (cJSON *)arg;
if (cj_result)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
//------------------- POSSIBLE JSON ENUM CONTENTS ----------------------------------
- cJSON* json_array_enum = cJSON_CreateArray();
+ cJSON *json_array_enum = cJSON_CreateArray();
if (NULL != json_array_enum)
{
for (uint8_t i = 0; i < MQ2_GAS_ALARM_MAX; i++)
{
- cJSON* json_value = cJSON_CreateString(mq2_sensor_gas_alarm_token[i]);
+ cJSON *json_value = cJSON_CreateString(mq2_sensor_gas_alarm_token[i]);
if (NULL != json_value)
{
cJSON_AddItemToArray(json_array_enum, json_value);
@@ -277,15 +302,15 @@ static int __0049_get_item(l_ezlopi_item_t* item, void* arg)
cJSON_AddItemToObject(cj_result, ezlopi_enum_str, json_array_enum);
}
//--------------------------------------------------------------------------------------
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char*)item->user_arg ? item->user_arg : "no_gas");
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char*)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- s_mq2_value_t* MQ2_value = ((s_mq2_value_t*)item->user_arg);
+ s_mq2_value_t *MQ2_value = ((s_mq2_value_t *)item->user_arg);
if (MQ2_value)
{
- char* valueFormatted = ezlopi_valueformatter_float(MQ2_value->_LPG_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ2_value->_LPG_ppm);
if (valueFormatted)
{
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
@@ -293,7 +318,6 @@ static int __0049_get_item(l_ezlopi_item_t* item, void* arg)
free(valueFormatted);
}
}
-
}
ret = 1;
}
@@ -301,30 +325,29 @@ static int __0049_get_item(l_ezlopi_item_t* item, void* arg)
return ret;
}
-static int __0049_get_cjson_value(l_ezlopi_item_t* item, void* arg)
+static int __0049_get_cjson_value(l_ezlopi_item_t *item, void *arg)
{
int ret = 0;
if (item && arg)
{
- cJSON* cj_result = (cJSON*)arg;
+ cJSON *cj_result = (cJSON *)arg;
if (cj_result)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char*)item->user_arg ? item->user_arg : "no_gas");
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char*)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- s_mq2_value_t* MQ2_value = ((s_mq2_value_t*)item->user_arg);
+ s_mq2_value_t *MQ2_value = ((s_mq2_value_t *)item->user_arg);
if (MQ2_value)
{
- char* valueFormatted = ezlopi_valueformatter_float(MQ2_value->_LPG_ppm);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ2_value->_LPG_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ2_value->_LPG_ppm);
if (valueFormatted)
{
-
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ2_value->_LPG_ppm);
free(valueFormatted);
}
}
@@ -335,61 +358,55 @@ static int __0049_get_cjson_value(l_ezlopi_item_t* item, void* arg)
return ret;
}
-static int __0049_notify(l_ezlopi_item_t* item)
+static int __0049_notify(l_ezlopi_item_t *item)
{
int ret = 0;
if (item)
{
- if (item->user_arg)
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
+ const char *curret_value = NULL;
+ if (0 == gpio_get_level(item->interface.gpio.gpio_in.gpio_num)) // when D0 -> 0V,
{
- const char* curret_value = NULL;
- if (0 == gpio_get_level(item->interface.gpio.gpio_in.gpio_num)) // when D0 -> 0V,
- {
- curret_value = "combustible_gas_detected";
- }
- else
- {
- curret_value = "no_gas";
- }
-
- if (curret_value != (char*)item->user_arg) // calls update only if there is change in state
- {
- item->user_arg = (void*)curret_value;
- ezlopi_device_value_updated_from_device_v3(item);
- }
+ curret_value = "combustible_gas_detected";
+ }
+ else
+ {
+ curret_value = "no_gas";
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ if (curret_value != (char *)item->user_arg) // calls update only if there is change in state
+ {
+ item->user_arg = (void *)curret_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
+ }
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ {
+ // extract the sensor_output_values
+ s_mq2_value_t *MQ2_value = (s_mq2_value_t *)item->user_arg;
+ if ((MQ2_value) && (true == MQ2_value->Calibration_complete_LPG))
{
- // extract the sensor_output_values
double new_value = (double)__extract_MQ2_sensor_ppm(item);
- s_mq2_value_t* MQ2_value = (s_mq2_value_t*)item->user_arg;
- if (MQ2_value)
+ if (fabs((double)(MQ2_value->_LPG_ppm) - new_value) > 0.0001)
{
- if (fabs((double)(MQ2_value->_LPG_ppm) - new_value) > 0.0001)
- {
- MQ2_value->_LPG_ppm = (float)new_value;
- ezlopi_device_value_updated_from_device_v3(item);
- }
+ MQ2_value->_LPG_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
}
}
- ret = 1;
}
+ ret = 1;
}
return ret;
}
//------------------------------------------------------------------------------------------------------
-static float __extract_MQ2_sensor_ppm(l_ezlopi_item_t* item)
+static float __extract_MQ2_sensor_ppm(l_ezlopi_item_t *item)
{
- uint32_t mq2_adc_pin = item->interface.adc.gpio_num;
- s_mq2_value_t* MQ2_value = (s_mq2_value_t*)item->user_arg;
- float ret = 0.0;
+ s_mq2_value_t *MQ2_value = (s_mq2_value_t *)item->user_arg;
if (MQ2_value)
- {
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+ { // calculation process
+ //-------------------------------------------------
+ uint32_t mq2_adc_pin = item->interface.adc.gpio_num;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
// extract the mean_sensor_analog_output_voltage
float analog_sensor_volt = 0;
for (uint8_t x = 10; x > 0; x--)
@@ -425,20 +442,18 @@ static float __extract_MQ2_sensor_ppm(l_ezlopi_item_t* item)
_LPG_ppm = 0; // No negative values accepted or upper datasheet recomendation.
}
TRACE_E("_LPG_ppm [LPG] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _LPG_ppm, (float)_ratio, analog_sensor_volt);
-
+ return _LPG_ppm;
//-------------------------------------------------
- ret = _LPG_ppm;
}
- return ret;
+ return 0;
}
-void __calibrate_MQ2_R0_resistance(void* params)
+void __calibrate_MQ2_R0_resistance(void *params)
{
- l_ezlopi_item_t* item = (l_ezlopi_item_t*)params;
+ l_ezlopi_item_t *item = (l_ezlopi_item_t *)params;
if (NULL != item)
{
- s_mq2_value_t* MQ2_value = (s_mq2_value_t*)item->user_arg;
-
+ s_mq2_value_t *MQ2_value = (s_mq2_value_t *)item->user_arg;
if (MQ2_value)
{
uint32_t mq2_adc_pin = item->interface.adc.gpio_num;
@@ -452,7 +467,7 @@ void __calibrate_MQ2_R0_resistance(void* params)
//-------------------------------------------------
// extract the mean_sensor_analog_output_voltage
float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
for (uint8_t i = 100; i > 0; i--)
{
if (i % 20 == 0)
@@ -490,6 +505,6 @@ void __calibrate_MQ2_R0_resistance(void* params)
// Set calibration_complete_LPG flag
MQ2_value->Calibration_complete_LPG = true;
}
- vTaskDelete(NULL);
}
+ vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0050-other-MQ3-alcohol-detector/sensor_0050_other_MQ3_alcohol_detector.c b/ezlopi-sensors-devices/sensor-0050-other-MQ3-alcohol-detector/sensor_0050_other_MQ3_alcohol_detector.c
index 8fc19b1f0..fba3f6b15 100644
--- a/ezlopi-sensors-devices/sensor-0050-other-MQ3-alcohol-detector/sensor_0050_other_MQ3_alcohol_detector.c
+++ b/ezlopi-sensors-devices/sensor-0050-other-MQ3-alcohol-detector/sensor_0050_other_MQ3_alcohol_detector.c
@@ -24,28 +24,28 @@ typedef struct s_mq3_value
bool Calibration_complete_alcohol;
} s_mq3_value_t;
-const char *mq3_sensor_gas_alarm_token[] = {
+const char* mq3_sensor_gas_alarm_token[] = {
"no_gas",
"combustible_gas_detected",
"toxic_gas_detected",
"unknown",
};
//--------------------------------------------------------------------------------------------------------
-static int __0050_prepare(void *arg);
-static int __0050_init(l_ezlopi_item_t *item);
-static int __0050_get_item(l_ezlopi_item_t *item, void *arg);
-static int __0050_get_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __0050_notify(l_ezlopi_item_t *item);
+static int __0050_prepare(void* arg);
+static int __0050_init(l_ezlopi_item_t* item);
+static int __0050_get_item(l_ezlopi_item_t* item, void* arg);
+static int __0050_get_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __0050_notify(l_ezlopi_item_t* item);
-static void __calibrate_MQ3_R0_resistance(void *params);
-static float __extract_MQ3_sensor_ppm(l_ezlopi_item_t *item);
-static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device);
-static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
-static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
-static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data);
+static void __calibrate_MQ3_R0_resistance(void* params);
+static float __extract_MQ3_sensor_ppm(l_ezlopi_item_t* item);
+static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device);
+static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
+static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
+static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data);
//--------------------------------------------------------------------------------------------------------
-int sensor_0050_other_MQ3_alcohol_detector(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0050_other_MQ3_alcohol_detector(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -72,14 +72,7 @@ int sensor_0050_other_MQ3_alcohol_detector(e_ezlopi_actions_t action, l_ezlopi_i
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- if (item)
- {
- s_mq3_value_t *MQ3_value = (s_mq3_value_t *)item->user_arg;
- if (true == MQ3_value->Calibration_complete_alcohol)
- {
- __0050_notify(item);
- }
- }
+ __0050_notify(item);
break;
}
default:
@@ -91,18 +84,18 @@ int sensor_0050_other_MQ3_alcohol_detector(e_ezlopi_actions_t action, l_ezlopi_i
}
//----------------------------------------------------
-static int __0050_prepare(void *arg)
+static int __0050_prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* device_prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
//--------------------------- DIGI - DEVICE 1 --------------------------------------------
- l_ezlopi_device_t *MQ3_device_digi = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t* MQ3_device_digi = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (MQ3_device_digi)
{
__prepare_device_digi_cloud_properties(MQ3_device_digi, device_prep_arg->cjson_device);
- l_ezlopi_item_t *MQ3_item_digi = ezlopi_device_add_item_to_device(MQ3_device_digi, sensor_0050_other_MQ3_alcohol_detector);
+ l_ezlopi_item_t* MQ3_item_digi = ezlopi_device_add_item_to_device(MQ3_device_digi, sensor_0050_other_MQ3_alcohol_detector);
if (MQ3_item_digi)
{
MQ3_item_digi->cloud_properties.device_id = MQ3_device_digi->cloud_properties.device_id;
@@ -117,15 +110,15 @@ static int __0050_prepare(void *arg)
}
//---------------------------- ADC - DEVICE 2 -------------------------------------------
- s_mq3_value_t *MQ3_value = (s_mq3_value_t *)malloc(sizeof(s_mq3_value_t));
+ s_mq3_value_t* MQ3_value = (s_mq3_value_t*)malloc(sizeof(s_mq3_value_t));
if (NULL != MQ3_value)
{
memset(MQ3_value, 0, sizeof(s_mq3_value_t));
- l_ezlopi_device_t *MQ3_device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t* MQ3_device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (MQ3_device_adc)
{
__prepare_device_adc_cloud_properties(MQ3_device_adc, device_prep_arg->cjson_device);
- l_ezlopi_item_t *MQ3_item_adc = ezlopi_device_add_item_to_device(MQ3_device_adc, sensor_0050_other_MQ3_alcohol_detector);
+ l_ezlopi_item_t* MQ3_item_adc = ezlopi_device_add_item_to_device(MQ3_device_adc, sensor_0050_other_MQ3_alcohol_detector);
if (MQ3_item_adc)
{
MQ3_item_adc->cloud_properties.device_id = MQ3_device_adc->cloud_properties.device_id;
@@ -149,43 +142,70 @@ static int __0050_prepare(void *arg)
return ret;
}
-static int __0050_init(l_ezlopi_item_t *item)
+static int __0050_init(l_ezlopi_item_t* item)
{
int ret = 0;
- if (NULL != item)
+ if (item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
- {
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
- }
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
- s_mq3_value_t *MQ3_value = (s_mq3_value_t *)item->user_arg;
- if (false == MQ3_value->Calibration_complete_alcohol)
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ gpio_config(&input_conf);
+ ret = 1;
+ }
+ else
{
- xTaskCreate(__calibrate_MQ3_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
}
}
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- free(item->user_arg);
- item->user_arg = NULL;
+ s_mq3_value_t* MQ3_value = ((s_mq3_value_t*)item->user_arg);
+ if (MQ3_value)
+ {
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ { // calibrate if not done
+ if (false == MQ3_value->Calibration_complete_alcohol)
+ {
+ xTaskCreate(__calibrate_MQ3_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
+ }
}
}
@@ -193,7 +213,7 @@ static int __0050_init(l_ezlopi_item_t *item)
}
//------------------------------------------------------------------------------------------------------
-static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -206,7 +226,7 @@ static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJ
device->cloud_properties.info = NULL;
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -217,11 +237,11 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ3-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
-static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -234,7 +254,7 @@ static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJS
device->cloud_properties.info = NULL;
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data)
+static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -254,23 +274,23 @@ static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj
}
//------------------------------------------------------------------------------------------------------
-static int __0050_get_item(l_ezlopi_item_t *item, void *arg)
+static int __0050_get_item(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
if (item && arg)
{
- cJSON *cj_result = (cJSON *)arg;
+ cJSON* cj_result = (cJSON*)arg;
if (cj_result)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
//------------------- POSSIBLE JSON ENUM CONTENTS ----------------------------------
- cJSON *json_array_enum = cJSON_CreateArray();
+ cJSON* json_array_enum = cJSON_CreateArray();
if (NULL != json_array_enum)
{
for (uint8_t i = 0; i < MQ3_GAS_ALARM_MAX; i++)
{
- cJSON *json_value = cJSON_CreateString(mq3_sensor_gas_alarm_token[i]);
+ cJSON* json_value = cJSON_CreateString(mq3_sensor_gas_alarm_token[i]);
if (NULL != json_value)
{
cJSON_AddItemToArray(json_array_enum, json_value);
@@ -279,16 +299,22 @@ static int __0050_get_item(l_ezlopi_item_t *item, void *arg)
cJSON_AddItemToObject(cj_result, ezlopi_enum_str, json_array_enum);
}
//--------------------------------------------------------------------------------------
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char*)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char*)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- s_mq3_value_t *MQ3_value = ((s_mq3_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ3_value->_alcohol_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ3_value->_alcohol_ppm);
- free(valueFormatted);
+ s_mq3_value_t* MQ3_value = ((s_mq3_value_t*)item->user_arg);
+ if (MQ3_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ3_value->_alcohol_ppm);
+ char* valueFormatted = ezlopi_valueformatter_float(MQ3_value->_alcohol_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -296,26 +322,32 @@ static int __0050_get_item(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __0050_get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __0050_get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
if (item && arg)
{
- cJSON *cj_result = (cJSON *)arg;
+ cJSON* cj_result = (cJSON*)arg;
if (cj_result)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char*)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char*)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- s_mq3_value_t *MQ3_value = ((s_mq3_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ3_value->_alcohol_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ3_value->_alcohol_ppm);
- free(valueFormatted);
+ s_mq3_value_t* MQ3_value = ((s_mq3_value_t*)item->user_arg);
+ if (MQ3_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ3_value->_alcohol_ppm);
+ char* valueFormatted = ezlopi_valueformatter_float(MQ3_value->_alcohol_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -323,14 +355,14 @@ static int __0050_get_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __0050_notify(l_ezlopi_item_t *item)
+static int __0050_notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- const char *curret_value = NULL;
+ const char* curret_value = NULL;
if (0 == gpio_get_level(item->interface.gpio.gpio_in.gpio_num)) // when D0 -> 0V,
{
curret_value = "combustible_gas_detected";
@@ -339,21 +371,24 @@ static int __0050_notify(l_ezlopi_item_t *item)
{
curret_value = "no_gas";
}
- if (curret_value != (char *)item->user_arg) // calls update only if there is change in state
+ if (curret_value != (char*)item->user_arg) // calls update only if there is change in state
{
- item->user_arg = (void *)curret_value;
+ item->user_arg = (void*)curret_value;
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
// extract the sensor_output_values
- double new_value = (double)__extract_MQ3_sensor_ppm(item);
- s_mq3_value_t *MQ3_value = (s_mq3_value_t *)item->user_arg;
- if (fabs((double)(MQ3_value->_alcohol_ppm) - new_value) > 0.0001)
+ s_mq3_value_t* MQ3_value = (s_mq3_value_t*)item->user_arg;
+ if ((MQ3_value) && (true == MQ3_value->Calibration_complete_alcohol))
{
- MQ3_value->_alcohol_ppm = (float)new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ double new_value = (double)__extract_MQ3_sensor_ppm(item);
+ if (fabs((double)(MQ3_value->_alcohol_ppm) - new_value) > 0.0001)
+ {
+ MQ3_value->_alcohol_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
@@ -361,108 +396,113 @@ static int __0050_notify(l_ezlopi_item_t *item)
return ret;
}
//------------------------------------------------------------------------------------------------------
-static float __extract_MQ3_sensor_ppm(l_ezlopi_item_t *item)
+static float __extract_MQ3_sensor_ppm(l_ezlopi_item_t* item)
{
- uint32_t mq3_adc_pin = item->interface.adc.gpio_num;
- s_mq3_value_t *MQ3_value = (s_mq3_value_t *)item->user_arg;
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- // extract the mean_sensor_analog_output_voltage
- float analog_sensor_volt = 0;
- for (uint8_t x = 10; x > 0; x--)
- {
- ezlopi_adc_get_adc_data(mq3_adc_pin, &ezlopi_analog_data);
+ s_mq3_value_t* MQ3_value = (s_mq3_value_t*)item->user_arg;
+ if (MQ3_value)
+ { // calculation process
+ uint32_t mq3_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+ // extract the mean_sensor_analog_output_voltage
+ float analog_sensor_volt = 0;
+ for (uint8_t x = 10; x > 0; x--)
+ {
+ ezlopi_adc_get_adc_data(mq3_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
+ analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
#else
- analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
+ analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
#endif
- vTaskDelay(1);
- }
- analog_sensor_volt = analog_sensor_volt / 10.0f;
+ vTaskDelay(1);
+ }
+ analog_sensor_volt = analog_sensor_volt / 10.0f;
- //-----------------------------------------------------------------------------------
- // Stage_2 : [from 'sensor_0050_ADC_MQ3_methane_gas_detector.h']
+ //-----------------------------------------------------------------------------------
+ // Stage_2 : [from 'sensor_0050_ADC_MQ3_methane_gas_detector.h']
- // 1. Calculate 'Rs_gas' for the gas detected
- float Rs_gas = (((MQ3_VOLT_RESOLUTION_Vc * mq3_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq3_eqv_RL);
+ // 1. Calculate 'Rs_gas' for the gas detected
+ float Rs_gas = (((MQ3_VOLT_RESOLUTION_Vc * mq3_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq3_eqv_RL);
- // 1.1 Calculate @ 'ratio' during alcohol presence
- double _ratio = (Rs_gas / ((MQ3_value->MQ3_R0_constant <= 0) ? (1.0f) : (MQ3_value->MQ3_R0_constant))); // avoid dividing by zero??
- if (_ratio <= 0)
- {
- _ratio = 0;
- }
- //-------------------------------------------------
+ // 1.1 Calculate @ 'ratio' during alcohol presence
+ double _ratio = (Rs_gas / ((MQ3_value->MQ3_R0_constant <= 0) ? (1.0f) : (MQ3_value->MQ3_R0_constant))); // avoid dividing by zero??
+ if (_ratio <= 0)
+ {
+ _ratio = 0;
+ }
+ //-------------------------------------------------
- // 1.2 Calculate _alcohol_ppm
- float _alcohol_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq3) / m_slope_mq3); // ---> _alcohol_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
- if (_alcohol_ppm < 0)
- {
- _alcohol_ppm = 0; // No negative values accepted or upper datasheet recomendation.
- }
- TRACE_E("_alcohol_ppm [alcohol] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _alcohol_ppm, (float)_ratio, analog_sensor_volt);
+ // 1.2 Calculate _alcohol_ppm
+ float _alcohol_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq3) / m_slope_mq3); // ---> _alcohol_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
+ if (_alcohol_ppm < 0)
+ {
+ _alcohol_ppm = 0; // No negative values accepted or upper datasheet recomendation.
+ }
+ TRACE_E("_alcohol_ppm [alcohol] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _alcohol_ppm, (float)_ratio, analog_sensor_volt);
- //-------------------------------------------------
- return _alcohol_ppm;
+ //-------------------------------------------------
+ return _alcohol_ppm;
+ }
+ return 0;
}
-static void __calibrate_MQ3_R0_resistance(void *params)
+static void __calibrate_MQ3_R0_resistance(void* params)
{
- l_ezlopi_item_t *item = (l_ezlopi_item_t *)params;
+ l_ezlopi_item_t* item = (l_ezlopi_item_t*)params;
if (NULL != item)
{
- s_mq3_value_t *MQ3_value = (s_mq3_value_t *)item->user_arg;
-
- uint32_t mq3_adc_pin = item->interface.adc.gpio_num;
- //-------------------------------------------------
- // let the sensor to heat for 20seconds
- for (uint8_t j = 20; j > 0; j--)
+ s_mq3_value_t* MQ3_value = (s_mq3_value_t*)item->user_arg;
+ if (MQ3_value)
{
- TRACE_E("Heating sensor.........time left: %d sec", j);
- vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
- }
- //-------------------------------------------------
- // extract the mean_sensor_analog_output_voltage
- float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- for (uint8_t i = 100; i > 0; i--)
- {
- if (i % 20 == 0)
+ uint32_t mq3_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ // let the sensor to heat for 20seconds
+ for (uint8_t j = 20; j > 0; j--)
{
- TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ TRACE_E("Heating sensor.........time left: %d sec", j);
+ vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
}
- // extract ADC values
- ezlopi_adc_get_adc_data(mq3_adc_pin, &ezlopi_analog_data);
+ //-------------------------------------------------
+ // extract the mean_sensor_analog_output_voltage
+ float _sensor_volt = 0;
+ s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+ for (uint8_t i = 100; i > 0; i--)
+ {
+ if (i % 20 == 0)
+ {
+ TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ }
+ // extract ADC values
+ ezlopi_adc_get_adc_data(mq3_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
+ _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
#else
- _sensor_volt += (float)(ezlopi_analog_data->voltage);
+ _sensor_volt += (float)(ezlopi_analog_data->voltage);
#endif
- vTaskDelay(1); // 10ms
- }
- _sensor_volt = _sensor_volt / 100.0f;
+ vTaskDelay(1); // 10ms
+ }
+ _sensor_volt = _sensor_volt / 100.0f;
- //-------------------------------------------------
- // Calculate the 'Rs' of heater during clean air [calibration phase]
- // Range -> [2Kohm - 20Kohm]
- float RS_calib = 0; // Define variable for sensor resistance
- RS_calib = ((MQ3_VOLT_RESOLUTION_Vc * mq3_eqv_RL) / (_sensor_volt / 1000.0f)) - mq3_eqv_RL; // Calculate RS in fresh air
- TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
- if (RS_calib < 0)
- {
- RS_calib = 0; // No negative values accepted.
- }
- // Calculate the R0_air which is constant through-out
- MQ3_value->MQ3_R0_constant = (RS_calib / RatioMQ3CleanAir); // Calculate MQ3_R0_constant
- TRACE_E("CALIB_TASK -> 'MQ3_R0_constant' = %.2f", MQ3_value->MQ3_R0_constant);
- if (MQ3_value->MQ3_R0_constant < 0)
- {
- MQ3_value->MQ3_R0_constant = 0; // No negative values accepted.
+ //-------------------------------------------------
+ // Calculate the 'Rs' of heater during clean air [calibration phase]
+ // Range -> [2Kohm - 20Kohm]
+ float RS_calib = 0; // Define variable for sensor resistance
+ RS_calib = ((MQ3_VOLT_RESOLUTION_Vc * mq3_eqv_RL) / (_sensor_volt / 1000.0f)) - mq3_eqv_RL; // Calculate RS in fresh air
+ TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
+ if (RS_calib < 0)
+ {
+ RS_calib = 0; // No negative values accepted.
+ }
+ // Calculate the R0_air which is constant through-out
+ MQ3_value->MQ3_R0_constant = (RS_calib / RatioMQ3CleanAir); // Calculate MQ3_R0_constant
+ TRACE_E("CALIB_TASK -> 'MQ3_R0_constant' = %.2f", MQ3_value->MQ3_R0_constant);
+ if (MQ3_value->MQ3_R0_constant < 0)
+ {
+ MQ3_value->MQ3_R0_constant = 0; // No negative values accepted.
+ }
+ // Set calibration_complete_alcohol flag
+ MQ3_value->Calibration_complete_alcohol = true;
}
- // Set calibration_complete_alcohol flag
- MQ3_value->Calibration_complete_alcohol = true;
}
vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0051-other-MQ8-H2-detector/sensor_0051_other_MQ8_H2_detector.c b/ezlopi-sensors-devices/sensor-0051-other-MQ8-H2-detector/sensor_0051_other_MQ8_H2_detector.c
index 5244c4032..4b1626b9a 100644
--- a/ezlopi-sensors-devices/sensor-0051-other-MQ8-H2-detector/sensor_0051_other_MQ8_H2_detector.c
+++ b/ezlopi-sensors-devices/sensor-0051-other-MQ8-H2-detector/sensor_0051_other_MQ8_H2_detector.c
@@ -71,14 +71,8 @@ int sensor_0051_other_MQ8_H2_detector(e_ezlopi_actions_t action, l_ezlopi_item_t
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- if (item)
- {
- s_mq8_value_t *MQ8_value = (s_mq8_value_t *)item->user_arg;
- if (true == MQ8_value->Calibration_complete_H2)
- {
- __0051_notify(item);
- }
- }
+ __0051_notify(item);
+
break;
}
default:
@@ -153,37 +147,64 @@ static int __0051_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
+
s_mq8_value_t *MQ8_value = (s_mq8_value_t *)item->user_arg;
- if (false == MQ8_value->Calibration_complete_H2)
+ if (MQ8_value)
{
- xTaskCreate(__calibrate_MQ8_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ { // calibrate if not done
+ if (false == MQ8_value->Calibration_complete_H2)
+ {
+ xTaskCreate(__calibrate_MQ8_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ else
{
- free(item->user_arg);
- item->user_arg = NULL;
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
}
}
}
@@ -215,7 +236,7 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ8-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
@@ -280,13 +301,19 @@ static int __0051_get_item(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq8_value_t *MQ8_value = ((s_mq8_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ8_value->_H2_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ8_value->_H2_ppm);
- free(valueFormatted);
+ if (MQ8_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ8_value->_H2_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ8_value->_H2_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -307,13 +334,19 @@ static int __0051_get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq8_value_t *MQ8_value = ((s_mq8_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ8_value->_H2_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ8_value->_H2_ppm);
- free(valueFormatted);
+ if (MQ8_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ8_value->_H2_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ8_value->_H2_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -343,15 +376,19 @@ static int __0051_notify(l_ezlopi_item_t *item)
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
// extract the sensor_output_values
- double new_value = (double)__extract_MQ8_sensor_ppm(item);
s_mq8_value_t *MQ8_value = (s_mq8_value_t *)item->user_arg;
- if (fabs((double)(MQ8_value->_H2_ppm) - new_value) > 0.0001)
+ if ((MQ8_value) && (true == MQ8_value->Calibration_complete_H2))
{
- MQ8_value->_H2_ppm = (float)new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ double new_value = (double)__extract_MQ8_sensor_ppm(item);
+
+ if (fabs((double)(MQ8_value->_H2_ppm) - new_value) > 0.0001)
+ {
+ MQ8_value->_H2_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
@@ -361,49 +398,53 @@ static int __0051_notify(l_ezlopi_item_t *item)
//------------------------------------------------------------------------------------------------------
static float __extract_MQ8_sensor_ppm(l_ezlopi_item_t *item)
{
- uint32_t mq8_adc_pin = item->interface.adc.gpio_num;
s_mq8_value_t *MQ8_value = (s_mq8_value_t *)item->user_arg;
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- // extract the mean_sensor_analog_output_voltage
- float analog_sensor_volt = 0;
- for (uint8_t x = 10; x > 0; x--)
+ if (MQ8_value)
{
- ezlopi_adc_get_adc_data(mq8_adc_pin, &ezlopi_analog_data);
+ // calculation process
+ //-------------------------------------------------
+ uint32_t mq8_adc_pin = item->interface.adc.gpio_num;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ // extract the mean_sensor_analog_output_voltage
+ float analog_sensor_volt = 0;
+ for (uint8_t x = 10; x > 0; x--)
+ {
+ ezlopi_adc_get_adc_data(mq8_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
+ analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
#else
- analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
+ analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
#endif
- vTaskDelay(1);
- }
- analog_sensor_volt = analog_sensor_volt / 10.0f;
+ vTaskDelay(1);
+ }
+ analog_sensor_volt = analog_sensor_volt / 10.0f;
- //-----------------------------------------------------------------------------------
- // Stage_2 : [from 'sensor_0051_ADC_MQ8_methane_gas_detector.h']
+ //-----------------------------------------------------------------------------------
+ // Stage_2 : [from 'sensor_0051_ADC_MQ8_methane_gas_detector.h']
- // 1. Calculate 'Rs_gas' for the gas detected
- float Rs_gas = (((MQ8_VOLT_RESOLUTION_Vc * mq8_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq8_eqv_RL);
+ // 1. Calculate 'Rs_gas' for the gas detected
+ float Rs_gas = (((MQ8_VOLT_RESOLUTION_Vc * mq8_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq8_eqv_RL);
- // 1.1 Calculate @ 'ratio' during H2 presence
- double _ratio = (Rs_gas / ((MQ8_value->MQ8_R0_constant <= 0) ? (1.0f) : (MQ8_value->MQ8_R0_constant))); // avoid dividing by zero??
- if (_ratio <= 0)
- {
- _ratio = 0;
- }
- //-------------------------------------------------
+ // 1.1 Calculate @ 'ratio' during H2 presence
+ double _ratio = (Rs_gas / ((MQ8_value->MQ8_R0_constant <= 0) ? (1.0f) : (MQ8_value->MQ8_R0_constant))); // avoid dividing by zero??
+ if (_ratio <= 0)
+ {
+ _ratio = 0;
+ }
+ //-------------------------------------------------
- // 1.2 Calculate _H2_ppm
- float _H2_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq8) / m_slope_mq8); // ---> _H2_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
- if (_H2_ppm < 0)
- {
- _H2_ppm = 0; // No negative values accepted or upper datasheet recomendation.
- }
- TRACE_E("_H2_ppm [H2] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _H2_ppm, (float)_ratio, analog_sensor_volt);
+ // 1.2 Calculate _H2_ppm
+ float _H2_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq8) / m_slope_mq8); // ---> _H2_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
+ if (_H2_ppm < 0)
+ {
+ _H2_ppm = 0; // No negative values accepted or upper datasheet recomendation.
+ }
+ TRACE_E("_H2_ppm [H2] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _H2_ppm, (float)_ratio, analog_sensor_volt);
- //-------------------------------------------------
- return _H2_ppm;
+ //-------------------------------------------------
+ return _H2_ppm;
+ }
+ return 0;
}
static void __calibrate_MQ8_R0_resistance(void *params)
@@ -412,55 +453,57 @@ static void __calibrate_MQ8_R0_resistance(void *params)
if (NULL != item)
{
s_mq8_value_t *MQ8_value = (s_mq8_value_t *)item->user_arg;
-
- uint32_t mq8_adc_pin = item->interface.adc.gpio_num;
- //-------------------------------------------------
- // let the sensor to heat for 20seconds
- for (uint8_t j = 20; j > 0; j--)
- {
- TRACE_E("Heating sensor.........time left: %d sec", j);
- vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
- }
- //-------------------------------------------------
- // extract the mean_sensor_analog_output_voltage
- float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- for (uint8_t i = 100; i > 0; i--)
+ if (MQ8_value)
{
- if (i % 20 == 0)
+ uint32_t mq8_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ // let the sensor to heat for 20seconds
+ for (uint8_t j = 20; j > 0; j--)
{
- TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ TRACE_E("Heating sensor.........time left: %d sec", j);
+ vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
}
- // extract ADC values
- ezlopi_adc_get_adc_data(mq8_adc_pin, &ezlopi_analog_data);
+ //-------------------------------------------------
+ // extract the mean_sensor_analog_output_voltage
+ float _sensor_volt = 0;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ for (uint8_t i = 100; i > 0; i--)
+ {
+ if (i % 20 == 0)
+ {
+ TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ }
+ // extract ADC values
+ ezlopi_adc_get_adc_data(mq8_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
+ _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
#else
- _sensor_volt += (float)(ezlopi_analog_data->voltage);
+ _sensor_volt += (float)(ezlopi_analog_data->voltage);
#endif
- vTaskDelay(1); // 10ms
- }
- _sensor_volt = _sensor_volt / 100.0f;
+ vTaskDelay(1); // 10ms
+ }
+ _sensor_volt = _sensor_volt / 100.0f;
- //-------------------------------------------------
- // Calculate the 'Rs' of heater during clean air [calibration phase]
- // Range -> [2Kohm - 20Kohm]
- float RS_calib = 0; // Define variable for sensor resistance
- RS_calib = ((MQ8_VOLT_RESOLUTION_Vc * mq8_eqv_RL) / (_sensor_volt / 1000.0f)) - mq8_eqv_RL; // Calculate RS in fresh air
- TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
- if (RS_calib < 0)
- {
- RS_calib = 0; // No negative values accepted.
- }
- // Calculate the R0_air which is constant through-out
- MQ8_value->MQ8_R0_constant = (RS_calib / RatioMQ8CleanAir); // Calculate MQ8_R0_constant
- TRACE_E("CALIB_TASK -> 'MQ8_R0_constant' = %.2f", MQ8_value->MQ8_R0_constant);
- if (MQ8_value->MQ8_R0_constant < 0)
- {
- MQ8_value->MQ8_R0_constant = 0; // No negative values accepted.
+ //-------------------------------------------------
+ // Calculate the 'Rs' of heater during clean air [calibration phase]
+ // Range -> [2Kohm - 20Kohm]
+ float RS_calib = 0; // Define variable for sensor resistance
+ RS_calib = ((MQ8_VOLT_RESOLUTION_Vc * mq8_eqv_RL) / (_sensor_volt / 1000.0f)) - mq8_eqv_RL; // Calculate RS in fresh air
+ TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
+ if (RS_calib < 0)
+ {
+ RS_calib = 0; // No negative values accepted.
+ }
+ // Calculate the R0_air which is constant through-out
+ MQ8_value->MQ8_R0_constant = (RS_calib / RatioMQ8CleanAir); // Calculate MQ8_R0_constant
+ TRACE_E("CALIB_TASK -> 'MQ8_R0_constant' = %.2f", MQ8_value->MQ8_R0_constant);
+ if (MQ8_value->MQ8_R0_constant < 0)
+ {
+ MQ8_value->MQ8_R0_constant = 0; // No negative values accepted.
+ }
+ // Set calibration_complete_H2 flag
+ MQ8_value->Calibration_complete_H2 = true;
}
- // Set calibration_complete_H2 flag
- MQ8_value->Calibration_complete_H2 = true;
}
vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0052-other-MQ135-NH3-detector/sensor_0052_other_MQ135_NH3_detector.c b/ezlopi-sensors-devices/sensor-0052-other-MQ135-NH3-detector/sensor_0052_other_MQ135_NH3_detector.c
index e6e2b8a36..ee64694c7 100644
--- a/ezlopi-sensors-devices/sensor-0052-other-MQ135-NH3-detector/sensor_0052_other_MQ135_NH3_detector.c
+++ b/ezlopi-sensors-devices/sensor-0052-other-MQ135-NH3-detector/sensor_0052_other_MQ135_NH3_detector.c
@@ -71,14 +71,9 @@ int sensor_0052_other_MQ135_NH3_detector(e_ezlopi_actions_t action, l_ezlopi_ite
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- if (item)
- {
- s_mq135_value_t *MQ135_value = (s_mq135_value_t *)item->user_arg;
- if (true == MQ135_value->Calibration_complete_NH3)
- {
- __0052_notify(item);
- }
- }
+
+ __0052_notify(item);
+
break;
}
default:
@@ -106,9 +101,11 @@ static int __0052_prepare(void *arg)
{
MQ135_item_digi->cloud_properties.device_id = MQ135_device_digi->cloud_properties.device_id;
__prepare_item_digi_cloud_properties(MQ135_item_digi, device_prep_arg->cjson_device);
+ ret = 1;
}
else
{
+ ret = -1;
ezlopi_device_free_device(MQ135_device_digi);
}
}
@@ -127,18 +124,20 @@ static int __0052_prepare(void *arg)
{
MQ135_item_adc->cloud_properties.device_id = MQ135_item_adc->cloud_properties.device_id;
__prepare_item_adc_cloud_properties(MQ135_item_adc, device_prep_arg->cjson_device, MQ135_value);
+ ret = 1;
}
else
{
+ ret = -1;
ezlopi_device_free_device(MQ135_device_adc);
free(MQ135_value);
}
}
else
{
+ ret = -1;
free(MQ135_value);
}
- ret = 1;
}
}
return ret;
@@ -149,37 +148,63 @@ static int __0052_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
- {
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
- }
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
- s_mq135_value_t *MQ135_value = (s_mq135_value_t *)item->user_arg;
- if (false == MQ135_value->Calibration_complete_NH3)
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
{
- xTaskCreate(__calibrate_MQ135_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
}
- ret = 1;
}
- if (0 == ret)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- ret = -1;
- if (item->user_arg)
+ s_mq135_value_t *MQ135_value = ((s_mq135_value_t *)item->user_arg);
+ if (MQ135_value)
+ {
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ { // calibrate if not done
+ if (false == MQ135_value->Calibration_complete_NH3)
+ {
+ xTaskCreate(__calibrate_MQ135_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
{
- free(item->user_arg);
- item->user_arg = NULL;
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
}
}
}
@@ -211,7 +236,7 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ135-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
@@ -276,16 +301,19 @@ static int __0052_get_item(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq135_value_t *MQ135_value = ((s_mq135_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ135_value->_NH3_ppm);
- if (valueFormatted)
+ if (MQ135_value)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ135_value->_NH3_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ135_value->_NH3_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ135_value->_NH3_ppm);
}
ret = 1;
}
@@ -306,16 +334,19 @@ static int __0052_get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq135_value_t *MQ135_value = ((s_mq135_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ135_value->_NH3_ppm);
- if (valueFormatted)
+ if (MQ135_value)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ135_value->_NH3_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ135_value->_NH3_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
}
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ135_value->_NH3_ppm);
}
ret = 1;
}
@@ -345,15 +376,18 @@ static int __0052_notify(l_ezlopi_item_t *item)
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
// extract the sensor_output_values
- double new_value = (double)__extract_MQ135_sensor_ppm(item);
s_mq135_value_t *MQ135_value = (s_mq135_value_t *)item->user_arg;
- if (fabs((double)(MQ135_value->_NH3_ppm) - new_value) > 0.0001)
+ if ((MQ135_value) && (true == MQ135_value->Calibration_complete_NH3))
{
- MQ135_value->_NH3_ppm = (float)new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ double new_value = (double)__extract_MQ135_sensor_ppm(item);
+ if (fabs((double)(MQ135_value->_NH3_ppm) - new_value) > 0.0001)
+ {
+ MQ135_value->_NH3_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
@@ -363,49 +397,52 @@ static int __0052_notify(l_ezlopi_item_t *item)
//------------------------------------------------------------------------------------------------------
static float __extract_MQ135_sensor_ppm(l_ezlopi_item_t *item)
{
- uint32_t mq135_adc_pin = item->interface.adc.gpio_num;
s_mq135_value_t *MQ135_value = (s_mq135_value_t *)item->user_arg;
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- // extract the mean_sensor_analog_output_voltage
- float analog_sensor_volt = 0;
- for (uint8_t x = 10; x > 0; x--)
- {
- ezlopi_adc_get_adc_data(mq135_adc_pin, &ezlopi_analog_data);
+ if (MQ135_value)
+ { // calculation process
+ //-------------------------------------------------
+ uint32_t mq135_adc_pin = item->interface.adc.gpio_num;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ // extract the mean_sensor_analog_output_voltage
+ float analog_sensor_volt = 0;
+ for (uint8_t x = 10; x > 0; x--)
+ {
+ ezlopi_adc_get_adc_data(mq135_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
+ analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
#else
- analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
+ analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
#endif
- vTaskDelay(1);
- }
- analog_sensor_volt = analog_sensor_volt / 10.0f;
+ vTaskDelay(1);
+ }
+ analog_sensor_volt = analog_sensor_volt / 10.0f;
- //-----------------------------------------------------------------------------------
- // Stage_2 : [from 'sensor_0052_ADC_MQ135_methane_gas_detector.h']
+ //-----------------------------------------------------------------------------------
+ // Stage_2 : [from 'sensor_0052_ADC_MQ135_methane_gas_detector.h']
- // 1. Calculate 'Rs_gas' for the gas detected
- float Rs_gas = (((MQ135_VOLT_RESOLUTION_Vc * mq135_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq135_eqv_RL);
+ // 1. Calculate 'Rs_gas' for the gas detected
+ float Rs_gas = (((MQ135_VOLT_RESOLUTION_Vc * mq135_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq135_eqv_RL);
- // 1.1 Calculate @ 'ratio' during NH3 presence
- double _ratio = (Rs_gas / ((MQ135_value->MQ135_R0_constant <= 0) ? (1.0f) : (MQ135_value->MQ135_R0_constant))); // avoid dividing by zero??
- if (_ratio <= 0)
- {
- _ratio = 0;
- }
- //-------------------------------------------------
+ // 1.1 Calculate @ 'ratio' during NH3 presence
+ double _ratio = (Rs_gas / ((MQ135_value->MQ135_R0_constant <= 0) ? (1.0f) : (MQ135_value->MQ135_R0_constant))); // avoid dividing by zero??
+ if (_ratio <= 0)
+ {
+ _ratio = 0;
+ }
+ //-------------------------------------------------
- // 1.2 Calculate _NH3_ppm
- float _NH3_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq135) / m_slope_mq135); // ---> _NH3_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
- if (_NH3_ppm < 0)
- {
- _NH3_ppm = 0; // No negative values accepted or upper datasheet recomendation.
- }
- TRACE_E("_NH3_ppm [NH3] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _NH3_ppm, (float)_ratio, analog_sensor_volt);
+ // 1.2 Calculate _NH3_ppm
+ float _NH3_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq135) / m_slope_mq135); // ---> _NH3_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
+ if (_NH3_ppm < 0)
+ {
+ _NH3_ppm = 0; // No negative values accepted or upper datasheet recomendation.
+ }
+ TRACE_E("_NH3_ppm [NH3] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _NH3_ppm, (float)_ratio, analog_sensor_volt);
- //-------------------------------------------------
- return _NH3_ppm;
+ //-------------------------------------------------
+ return _NH3_ppm;
+ }
+ return 0;
}
static void __calibrate_MQ135_R0_resistance(void *params)
@@ -414,55 +451,57 @@ static void __calibrate_MQ135_R0_resistance(void *params)
if (NULL != item)
{
s_mq135_value_t *MQ135_value = (s_mq135_value_t *)item->user_arg;
-
- uint32_t mq135_adc_pin = item->interface.adc.gpio_num;
- //-------------------------------------------------
- // let the sensor to heat for 20seconds
- for (uint8_t j = 20; j > 0; j--)
+ if (MQ135_value)
{
- TRACE_E("Heating sensor.........time left: %d sec", j);
- vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
- }
- //-------------------------------------------------
- // extract the mean_sensor_analog_output_voltage
- float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- for (uint8_t i = 100; i > 0; i--)
- {
- if (i % 20 == 0)
+ uint32_t mq135_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ // let the sensor to heat for 20seconds
+ for (uint8_t j = 20; j > 0; j--)
{
- TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ TRACE_E("Heating sensor.........time left: %d sec", j);
+ vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
}
- // extract ADC values
- ezlopi_adc_get_adc_data(mq135_adc_pin, &ezlopi_analog_data);
+ //-------------------------------------------------
+ // extract the mean_sensor_analog_output_voltage
+ float _sensor_volt = 0;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ for (uint8_t i = 100; i > 0; i--)
+ {
+ if (i % 20 == 0)
+ {
+ TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ }
+ // extract ADC values
+ ezlopi_adc_get_adc_data(mq135_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
+ _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
#else
- _sensor_volt += (float)(ezlopi_analog_data->voltage);
+ _sensor_volt += (float)(ezlopi_analog_data->voltage);
#endif
- vTaskDelay(1); // 10ms
- }
- _sensor_volt = _sensor_volt / 100.0f;
+ vTaskDelay(1); // 10ms
+ }
+ _sensor_volt = _sensor_volt / 100.0f;
- //-------------------------------------------------
- // Calculate the 'Rs' of heater during clean air [calibration phase]
- // Range -> [2Kohm - 20Kohm]
- float RS_calib = 0; // Define variable for sensor resistance
- RS_calib = ((MQ135_VOLT_RESOLUTION_Vc * mq135_eqv_RL) / (_sensor_volt / 1000.0f)) - mq135_eqv_RL; // Calculate RS in fresh air
- TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
- if (RS_calib < 0)
- {
- RS_calib = 0; // No negative values accepted.
- }
- // Calculate the R0_air which is constant through-out
- MQ135_value->MQ135_R0_constant = (RS_calib / RatioMQ135CleanAir); // Calculate MQ135_R0_constant
- TRACE_E("CALIB_TASK -> 'MQ135_R0_constant' = %.2f", MQ135_value->MQ135_R0_constant);
- if (MQ135_value->MQ135_R0_constant < 0)
- {
- MQ135_value->MQ135_R0_constant = 0; // No negative values accepted.
+ //-------------------------------------------------
+ // Calculate the 'Rs' of heater during clean air [calibration phase]
+ // Range -> [2Kohm - 20Kohm]
+ float RS_calib = 0; // Define variable for sensor resistance
+ RS_calib = ((MQ135_VOLT_RESOLUTION_Vc * mq135_eqv_RL) / (_sensor_volt / 1000.0f)) - mq135_eqv_RL; // Calculate RS in fresh air
+ TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
+ if (RS_calib < 0)
+ {
+ RS_calib = 0; // No negative values accepted.
+ }
+ // Calculate the R0_air which is constant through-out
+ MQ135_value->MQ135_R0_constant = (RS_calib / RatioMQ135CleanAir); // Calculate MQ135_R0_constant
+ TRACE_E("CALIB_TASK -> 'MQ135_R0_constant' = %.2f", MQ135_value->MQ135_R0_constant);
+ if (MQ135_value->MQ135_R0_constant < 0)
+ {
+ MQ135_value->MQ135_R0_constant = 0; // No negative values accepted.
+ }
+ // Set calibration_complete_NH3 flag
+ MQ135_value->Calibration_complete_NH3 = true;
}
- // Set calibration_complete_NH3 flag
- MQ135_value->Calibration_complete_NH3 = true;
}
vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0053-UART-GYGPS6MV2/sensor_0053_UART_GYGPS6MV2.c b/ezlopi-sensors-devices/sensor-0053-UART-GYGPS6MV2/sensor_0053_UART_GYGPS6MV2.c
index d54f8c659..f7f60e255 100644
--- a/ezlopi-sensors-devices/sensor-0053-UART-GYGPS6MV2/sensor_0053_UART_GYGPS6MV2.c
+++ b/ezlopi-sensors-devices/sensor-0053-UART-GYGPS6MV2/sensor_0053_UART_GYGPS6MV2.c
@@ -152,14 +152,16 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj
/*Here we decide, when uart is allowed to initialize*/
GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
-
- if ((sensor_0053_UART_gps6mv2_data->Latitude_item_id) == item->cloud_properties.item_id)
- {
- item->interface.uart.enable = true;
- }
- else
+ if (sensor_0053_UART_gps6mv2_data)
{
- item->interface.uart.enable = false;
+ if ((sensor_0053_UART_gps6mv2_data->Latitude_item_id) == item->cloud_properties.item_id)
+ {
+ item->interface.uart.enable = true;
+ }
+ else
+ {
+ item->interface.uart.enable = false;
+ }
}
}
//---------------------------------------------------------------------------------------------------------
@@ -241,22 +243,32 @@ static int __0053_init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if ((true == item->interface.uart.enable) && GPIO_IS_VALID_GPIO(item->interface.uart.tx) && GPIO_IS_VALID_GPIO(item->interface.uart.rx))
- {
- s_ezlopi_uart_object_handle_t ezlopi_uart_object_handle = ezlopi_uart_init(item->interface.uart.baudrate, item->interface.uart.tx, item->interface.uart.rx, __uart_gps6mv2_upcall, item);
- item->interface.uart.channel = ezlopi_uart_get_channel(ezlopi_uart_object_handle);
- // TRACE_W(" Initailization complete......");
- ret = 1;
- }
- if (0 == ret)
+ GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
+ if (sensor_0053_UART_gps6mv2_data)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.uart.tx) && GPIO_IS_VALID_GPIO(item->interface.uart.rx))
{
- free(item->user_arg);
+ if (true == item->interface.uart.enable)
+ {
+ s_ezlopi_uart_object_handle_t ezlopi_uart_object_handle = ezlopi_uart_init(item->interface.uart.baudrate, item->interface.uart.tx, item->interface.uart.rx, __uart_gps6mv2_upcall, item);
+ item->interface.uart.channel = ezlopi_uart_get_channel(ezlopi_uart_object_handle);
+ // TRACE_W(" Initailization complete......");
+ ret = 1;
+ }
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -270,45 +282,58 @@ static int __0053_get_value_cjson(l_ezlopi_item_t *item, void *arg)
if (cj_result)
{
GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
-
- if ((sensor_0053_UART_gps6mv2_data->Latitude_item_id) == item->cloud_properties.item_id)
- {
- char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_lat_angle_val);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_lat_angle_val);
- free(valueFormatted);
- }
- if ((sensor_0053_UART_gps6mv2_data->Longitude_item_id) == item->cloud_properties.item_id)
+ if (sensor_0053_UART_gps6mv2_data)
{
- char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_long_angle_val);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_long_angle_val);
- free(valueFormatted);
- }
+ if ((sensor_0053_UART_gps6mv2_data->Latitude_item_id) == item->cloud_properties.item_id)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_lat_angle_val);
+ char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_lat_angle_val);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ else if ((sensor_0053_UART_gps6mv2_data->Longitude_item_id) == item->cloud_properties.item_id)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_long_angle_val);
+ char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_long_angle_val);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
- if ((sensor_0053_UART_gps6mv2_data->Fix_item_id) == item->cloud_properties.item_id)
- {
- const char *valueFormatted = ezlopi_valueformatter_bool(sensor_0053_UART_gps6mv2_data->prev_GPS_FIX);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddBoolToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_GPS_FIX);
- }
+ else if ((sensor_0053_UART_gps6mv2_data->Fix_item_id) == item->cloud_properties.item_id)
+ {
+ cJSON_AddBoolToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_GPS_FIX);
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, ezlopi_valueformatter_bool(sensor_0053_UART_gps6mv2_data->prev_GPS_FIX));
+ }
- if ((sensor_0053_UART_gps6mv2_data->Sea_level_item_id) == item->cloud_properties.item_id)
- {
- char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_antenna_alti);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_antenna_alti);
- free(valueFormatted);
- }
+ else if ((sensor_0053_UART_gps6mv2_data->Sea_level_item_id) == item->cloud_properties.item_id)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_antenna_alti);
+ char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_antenna_alti);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
- if ((sensor_0053_UART_gps6mv2_data->Geoid_item_id) == item->cloud_properties.item_id)
- {
- char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_geoid);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_geoid);
- free(valueFormatted);
+ else if ((sensor_0053_UART_gps6mv2_data->Geoid_item_id) == item->cloud_properties.item_id)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, sensor_0053_UART_gps6mv2_data->prev_geoid);
+ char *valueFormatted = ezlopi_valueformatter_float(sensor_0053_UART_gps6mv2_data->prev_geoid);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ ret = 1;
}
- ret = 1;
}
}
return ret;
@@ -319,68 +344,71 @@ static int __0053_notify(l_ezlopi_item_t *item)
if (item)
{
GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
- if ((sensor_0053_UART_gps6mv2_data->Latitude_item_id) == item->cloud_properties.item_id)
+ if (sensor_0053_UART_gps6mv2_data)
{
- // Invoking data Update only, in this item_id
- (sensor_0053_UART_gps6mv2_data->gps_message_guard) = true;
- __sensor_uart_gps6mv2_update_values(item);
-
- // checking for new values
- float lat_angle_val = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Latitude.lat_degree) + ((float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Latitude.lat_min)) / 60.0f;
- if ((sensor_0053_UART_gps6mv2_data->prev_lat_angle_val) != lat_angle_val)
+ if ((sensor_0053_UART_gps6mv2_data->Latitude_item_id) == item->cloud_properties.item_id)
{
- (sensor_0053_UART_gps6mv2_data->prev_lat_angle_val) = lat_angle_val;
- (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
- ezlopi_device_value_updated_from_device_v3(item);
+ // Invoking data Update only, in this item_id
+ (sensor_0053_UART_gps6mv2_data->gps_message_guard) = true;
+ __sensor_uart_gps6mv2_update_values(item);
+
+ // checking for new values
+ float lat_angle_val = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Latitude.lat_degree) + ((float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Latitude.lat_min)) / 60.0f;
+ if ((sensor_0053_UART_gps6mv2_data->prev_lat_angle_val) != lat_angle_val)
+ {
+ (sensor_0053_UART_gps6mv2_data->prev_lat_angle_val) = lat_angle_val;
+ (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if ((sensor_0053_UART_gps6mv2_data->Longitude_item_id) == item->cloud_properties.item_id)
- {
- // checking for new values
- float long_angle_val = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Longitude.long_degree) + ((float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Longitude.long_min)) / 60.0f;
- if ((sensor_0053_UART_gps6mv2_data->prev_long_angle_val) != long_angle_val)
+ else if ((sensor_0053_UART_gps6mv2_data->Longitude_item_id) == item->cloud_properties.item_id)
{
- (sensor_0053_UART_gps6mv2_data->prev_long_angle_val) = long_angle_val;
- (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
- ezlopi_device_value_updated_from_device_v3(item);
+ // checking for new values
+ float long_angle_val = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Longitude.long_degree) + ((float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Longitude.long_min)) / 60.0f;
+ if ((sensor_0053_UART_gps6mv2_data->prev_long_angle_val) != long_angle_val)
+ {
+ (sensor_0053_UART_gps6mv2_data->prev_long_angle_val) = long_angle_val;
+ (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if ((sensor_0053_UART_gps6mv2_data->Fix_item_id) == item->cloud_properties.item_id)
- {
- // checking for new values
- int total_sat = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Satellites_used);
- int gps_quality = ((int)(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Positon_fix_quality) - 48); // converting character into 'integer'
- gps_quality = (gps_quality < 0) ? 0 : ((gps_quality > 9) ? 9 : gps_quality);
-
- bool GPS_FIX = ((total_sat > 2) && (gps_quality != 0)) ? true : false;
- if ((sensor_0053_UART_gps6mv2_data->prev_GPS_FIX) != GPS_FIX)
+ else if ((sensor_0053_UART_gps6mv2_data->Fix_item_id) == item->cloud_properties.item_id)
{
- (sensor_0053_UART_gps6mv2_data->prev_GPS_FIX) = GPS_FIX;
- (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
- ezlopi_device_value_updated_from_device_v3(item);
+ // checking for new values
+ int total_sat = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Satellites_used);
+ int gps_quality = ((int)(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Positon_fix_quality) - 48); // converting character into 'integer'
+ gps_quality = (gps_quality < 0) ? 0 : ((gps_quality > 9) ? 9 : gps_quality);
+
+ bool GPS_FIX = ((total_sat > 2) && (gps_quality != 0)) ? true : false;
+ if ((sensor_0053_UART_gps6mv2_data->prev_GPS_FIX) != GPS_FIX)
+ {
+ (sensor_0053_UART_gps6mv2_data->prev_GPS_FIX) = GPS_FIX;
+ (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if ((sensor_0053_UART_gps6mv2_data->Sea_level_item_id) == item->cloud_properties.item_id)
- {
- // checking for new values
- float antenna_alti = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Mean_sea_level);
- if ((sensor_0053_UART_gps6mv2_data->prev_antenna_alti) != antenna_alti)
+ else if ((sensor_0053_UART_gps6mv2_data->Sea_level_item_id) == item->cloud_properties.item_id)
{
- (sensor_0053_UART_gps6mv2_data->prev_antenna_alti) = antenna_alti;
- (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
- ezlopi_device_value_updated_from_device_v3(item);
+ // checking for new values
+ float antenna_alti = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Mean_sea_level);
+ if ((sensor_0053_UART_gps6mv2_data->prev_antenna_alti) != antenna_alti)
+ {
+ (sensor_0053_UART_gps6mv2_data->prev_antenna_alti) = antenna_alti;
+ (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
- }
- if ((sensor_0053_UART_gps6mv2_data->Geoid_item_id) == item->cloud_properties.item_id)
- {
- // checking for new values
- float geoid = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Geoid_Separation);
- if ((sensor_0053_UART_gps6mv2_data->prev_geoid) != geoid)
+ else if ((sensor_0053_UART_gps6mv2_data->Geoid_item_id) == item->cloud_properties.item_id)
{
- (sensor_0053_UART_gps6mv2_data->prev_geoid) = geoid;
- (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
- ezlopi_device_value_updated_from_device_v3(item);
+ // checking for new values
+ float geoid = (float)atoi(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.Geoid_Separation);
+ if ((sensor_0053_UART_gps6mv2_data->prev_geoid) != geoid)
+ {
+ (sensor_0053_UART_gps6mv2_data->prev_geoid) = geoid;
+ (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
}
@@ -391,29 +419,31 @@ static int __sensor_uart_gps6mv2_update_values(l_ezlopi_item_t *item)
{
int ret = 0, len = 0;
// 'void_type' addrress -> 'GPS6MV2_t' address
- GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
-
if (NULL != item)
{
- // replace the gps_sentence of GPGGA structure
- if ((sensor_0053_UART_gps6mv2_data->gps_sentence) != NULL)
+ GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
+ if (sensor_0053_UART_gps6mv2_data)
{
- // reset the GPGGA_sentence array
- len = sizeof(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence);
- memset(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence, 0, sizeof(len));
- sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence[len - 1] = '\0';
- strncpy(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence, (sensor_0053_UART_gps6mv2_data->gps_sentence), (len - 1));
- }
+ // replace the gps_sentence of GPGGA structure
+ if ((sensor_0053_UART_gps6mv2_data->gps_sentence) != NULL)
+ {
+ // reset the GPGGA_sentence array
+ len = sizeof(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence);
+ memset(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence, 0, sizeof(len));
+ sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence[len - 1] = '\0';
+ strncpy(sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence, (sensor_0053_UART_gps6mv2_data->gps_sentence), (len - 1));
+ }
- // Check availability of Checksum in the message
- if (strchr((sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence), '*') != NULL)
- {
- //-------------------------------------------------------------------------
- // GPGGA MESSAGE PARSING FUNCTION
- //-------------------------------------------------------------------------
- parse_and_assign_GPGGA_message(sensor_0053_UART_gps6mv2_data);
+ // Check availability of Checksum in the message
+ if (strchr((sensor_0053_UART_gps6mv2_data->GPGGA_data_structure.GPGGA_sentence), '*') != NULL)
+ {
+ //-------------------------------------------------------------------------
+ // GPGGA MESSAGE PARSING FUNCTION
+ //-------------------------------------------------------------------------
+ parse_and_assign_GPGGA_message(sensor_0053_UART_gps6mv2_data);
+ }
+ (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
}
- (sensor_0053_UART_gps6mv2_data->gps_message_guard) = false;
}
return ret;
}
@@ -422,25 +452,27 @@ static int __sensor_uart_gps6mv2_update_values(l_ezlopi_item_t *item)
static void __uart_gps6mv2_upcall(uint8_t *buffer, uint32_t output_len, s_ezlopi_uart_object_handle_t uart_object_handle)
{
// TRACE_E("UART_Buffer => \n%s\n", buffer);
- char *another_buffer = (char *)malloc(256);
- if (another_buffer && (uart_object_handle->arg))
+ char *tmp_buffer = (char *)malloc(256);
+ if (tmp_buffer && (uart_object_handle->arg))
{
- memcpy(another_buffer, buffer, 256);
+ memcpy(tmp_buffer, buffer, 256);
l_ezlopi_item_t *item = (l_ezlopi_item_t *)uart_object_handle->arg;
GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
-
- if (strlen(sensor_0053_UART_gps6mv2_data->gps_cir_buf) < (CIR_BUFSIZE)-255)
- {
- strncpy(((sensor_0053_UART_gps6mv2_data->gps_cir_buf) + strlen(sensor_0053_UART_gps6mv2_data->gps_cir_buf)), another_buffer, strlen(another_buffer));
- }
- else
+ if (sensor_0053_UART_gps6mv2_data)
{
- // TRACE_E("----------- 2. CIR_BUFF - FULL -------------");
- // TRACE_S("CIRCULAR_BUFFER => [%d] \n%s", strlen(gps_cir_buf), gps_cir_buf);
- __retrieve_GPGGA_sentence(item); // CALL a function that extracts the 'GPGGA_sentence' from gps_cir_buf[]
- memset((sensor_0053_UART_gps6mv2_data->gps_cir_buf), 0, sizeof(sensor_0053_UART_gps6mv2_data->gps_cir_buf)); // reset gps_cir_buf[]
+ if (strlen(sensor_0053_UART_gps6mv2_data->gps_cir_buf) < (CIR_BUFSIZE)-255)
+ {
+ strncpy(((sensor_0053_UART_gps6mv2_data->gps_cir_buf) + strlen(sensor_0053_UART_gps6mv2_data->gps_cir_buf)), tmp_buffer, strlen(tmp_buffer));
+ }
+ else
+ {
+ // TRACE_E("----------- 2. CIR_BUFF - FULL -------------");
+ // TRACE_I("CIRCULAR_BUFFER => [%d] \n%s", strlen(gps_cir_buf), gps_cir_buf);
+ __retrieve_GPGGA_sentence(item); // CALL a function that extracts the 'GPGGA_sentence' from gps_cir_buf[]
+ memset((sensor_0053_UART_gps6mv2_data->gps_cir_buf), 0, sizeof(sensor_0053_UART_gps6mv2_data->gps_cir_buf)); // reset gps_cir_buf[]
+ }
}
- free(another_buffer);
+ free(tmp_buffer);
}
}
@@ -449,55 +481,58 @@ static void __retrieve_GPGGA_sentence(l_ezlopi_item_t *item)
if (NULL != item)
{
GPS6MV2_t *sensor_0053_UART_gps6mv2_data = (GPS6MV2_t *)item->user_arg;
- if (NULL == strstr((sensor_0053_UART_gps6mv2_data->gps_cir_buf), "$GPTXT"))
+ if (sensor_0053_UART_gps6mv2_data)
{
- // TRACE_E("................Extracting GPGGA gps_sentence ...........");
- // find the position of '$GSGGA' in the circular buffer
- /** 2000
- * circular_buffer = 'dkfhkhdf .... $GPGGA,061731.00,2740.52772,....,-41.3,M,,*40.....'
- * ^
- * ptr1 => $GPGGA,061731.00,2740.52772,....,-41.3,M,,*40.....
- *
- */
- char *ptr1 = strstr((sensor_0053_UART_gps6mv2_data->gps_cir_buf), "$GPGGA"); // returns a pointer points to the first character of the found 'another_buffer' in "$GPGGA"
- // otherwise a null pointer if "$GPGGA" is not present in 'another_buffer'.
- // If "[$GPGGA]" destination string, points to an empty string, 'another_buffer' is returned
-
- // Continue only if the 'GSGGA-message' exists
- if (NULL != ptr1)
+ if (NULL == strstr((sensor_0053_UART_gps6mv2_data->gps_cir_buf), "$GPTXT"))
{
-
- /** 2053
- * ptr1 => '$GPGGA,061731.00,2740.52772,....,-41.3,M,,*40
- * ^
- * *40_ <- ptr2.....
+ // TRACE_E("................Extracting GPGGA gps_sentence ...........");
+ // find the position of '$GSGGA' in the circular buffer
+ /** 2000
+ * circular_buffer = 'dkfhkhdf .... $GPGGA,061731.00,2740.52772,....,-41.3,M,,*40.....'
+ * ^
+ * ptr1 => $GPGGA,061731.00,2740.52772,....,-41.3,M,,*40.....
*
*/
+ char *ptr1 = strstr((sensor_0053_UART_gps6mv2_data->gps_cir_buf), "$GPGGA"); // returns a pointer points to the first character of the found 'tmp_buffer' in "$GPGGA"
+ // otherwise a null pointer if "$GPGGA" is not present in 'tmp_buffer'.
+ // If "[$GPGGA]" destination string, points to an empty string, 'tmp_buffer' is returned
- char *ptr2 = strchr(ptr1, '*'); // * <- ptr2
- // check if ptr2 exists
- if (NULL != ptr2)
- { // NOW , separate the GSGGA-message and copy to global variable 'gps_sentence'
- ptr2 += 3; // +3 because the checksum consists three character more [*XX]
- // TRACE_E("GPGGA message size = %d (< %d)", (ptr2 - ptr1), MAX_GPGGA_SENTENCE_SIZE);
- if ((ptr2 - ptr1) > 0 && (ptr2 - ptr1) < MAX_GPGGA_SENTENCE_SIZE)
- {
- if (false == (sensor_0053_UART_gps6mv2_data->gps_message_guard))
- {
- memset(&(sensor_0053_UART_gps6mv2_data->gps_sentence), 0, sizeof(sensor_0053_UART_gps6mv2_data->gps_sentence));
- memcpy((sensor_0053_UART_gps6mv2_data->gps_sentence), ptr1, (ptr2 - ptr1)); // (dest_addr , from_addr , length)
- // TRACE_W("gps_sentence (NEW) => %s", gps_sentence);
- }
- else
+ // Continue only if the 'GSGGA-message' exists
+ if (NULL != ptr1)
+ {
+
+ /** 2053
+ * ptr1 => '$GPGGA,061731.00,2740.52772,....,-41.3,M,,*40
+ * ^
+ * *40_ <- ptr2.....
+ *
+ */
+
+ char *ptr2 = strchr(ptr1, '*'); // * <- ptr2
+ // check if ptr2 exists
+ if (NULL != ptr2)
+ { // NOW , separate the GSGGA-message and copy to global variable 'gps_sentence'
+ ptr2 += 3; // +3 because the checksum consists three character more [*XX]
+ // TRACE_E("GPGGA message size = %d (< %d)", (ptr2 - ptr1), MAX_GPGGA_SENTENCE_SIZE);
+ if ((ptr2 - ptr1) > 0 && (ptr2 - ptr1) < MAX_GPGGA_SENTENCE_SIZE)
{
- TRACE_E(" gps_Message_Guard => ON ; Cannot copy NEW message.... in 'gps_sentence'");
+ if (false == (sensor_0053_UART_gps6mv2_data->gps_message_guard))
+ {
+ memset(&(sensor_0053_UART_gps6mv2_data->gps_sentence), 0, sizeof(sensor_0053_UART_gps6mv2_data->gps_sentence));
+ memcpy((sensor_0053_UART_gps6mv2_data->gps_sentence), ptr1, (ptr2 - ptr1)); // (dest_addr , from_addr , length)
+ // TRACE_W("gps_sentence (NEW) => %s", gps_sentence);
+ }
+ else
+ {
+ TRACE_E(" gps_Message_Guard => ON ; Cannot copy NEW message.... in 'gps_sentence'");
+ }
}
}
}
- }
- else
- {
- TRACE_E("NO GPGGA message found in current circular buffer stack....");
+ else
+ {
+ TRACE_E("NO GPGGA message found in current circular buffer stack....");
+ }
}
}
}
diff --git a/ezlopi-sensors-devices/sensor-0054-PWM-YFS201-flowmeter/sensor_0054_PWM_YFS201_flowmeter.c b/ezlopi-sensors-devices/sensor-0054-PWM-YFS201-flowmeter/sensor_0054_PWM_YFS201_flowmeter.c
index 67511932c..beb26358e 100644
--- a/ezlopi-sensors-devices/sensor-0054-PWM-YFS201-flowmeter/sensor_0054_PWM_YFS201_flowmeter.c
+++ b/ezlopi-sensors-devices/sensor-0054-PWM-YFS201-flowmeter/sensor_0054_PWM_YFS201_flowmeter.c
@@ -112,7 +112,7 @@ static void __prepare_item_properties(l_ezlopi_item_t *item, cJSON *cj_device, v
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.pwm.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.pwm.gpio_num);
// passing the custom data_structure
item->user_arg = user_data;
@@ -162,28 +162,35 @@ static int __0054_init(l_ezlopi_item_t *item)
{
int ret = 0;
if (NULL != item)
- { // intialize digital_pin
- if (GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.pwm.gpio_num))
- {
- gpio_config_t input_conf = {
- .pin_bit_mask = (1ULL << item->interface.pwm.gpio_num),
- .intr_type = GPIO_INTR_POSEDGE,
- .mode = GPIO_MODE_INPUT,
- .pull_down_en = GPIO_PULLDOWN_DISABLE,
- .pull_up_en = GPIO_PULLUP_DISABLE,
- };
- gpio_config(&input_conf);
- ret = 1;
- }
- if (0 == ret)
+ {
+ yfs201_t *yfs201_data = (yfs201_t *)item->user_arg;
+ if (yfs201_data)
{
- ret = -1;
- if (item->user_arg)
+ // intialize digital_pin
+ if (GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.pwm.gpio_num))
+ {
+ gpio_config_t input_conf = {
+ .pin_bit_mask = (1ULL << item->interface.pwm.gpio_num),
+ .intr_type = GPIO_INTR_POSEDGE,
+ .mode = GPIO_MODE_INPUT,
+ .pull_down_en = GPIO_PULLDOWN_DISABLE,
+ .pull_up_en = GPIO_PULLUP_DISABLE,
+ };
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -197,24 +204,27 @@ static int __0054_get_cjson_value(l_ezlopi_item_t *item, void *arg)
if (cj_result)
{
yfs201_t *yfs201_data = (yfs201_t *)item->user_arg;
- float freq = 0, Lt_per_hr = 0;
- // converting pulse_counta into frequency (uSec -> Hz)
- freq = yfs201_data->yfs201_dominant_pulse_count * YFS201_QUEUE_SIZE; // [counts_200ms -> counts_1sec]
+ if (yfs201_data)
+ {
+ float freq = 0, Lt_per_hr = 0;
+ // converting pulse_counta into frequency (uSec -> Hz)
+ freq = yfs201_data->yfs201_dominant_pulse_count * YFS201_QUEUE_SIZE; // [counts_200ms -> counts_1sec]
- // liter per hr
- Lt_per_hr = freq * 7.3f;
- Lt_per_hr = (Lt_per_hr < 1) ? 0 : Lt_per_hr;
- Lt_per_hr = (Lt_per_hr > 720) ? 720 : Lt_per_hr;
- // TRACE_E(" Frequency : %.2f Hz --> FlowRate : %.2f [Lt_per_hr]", freq, Lt_per_hr);
+ // liter per hr
+ Lt_per_hr = freq * 7.3f;
+ Lt_per_hr = (Lt_per_hr < 1) ? 0 : Lt_per_hr;
+ Lt_per_hr = (Lt_per_hr > 720) ? 720 : Lt_per_hr;
+ // TRACE_E(" Frequency : %.2f Hz --> FlowRate : %.2f [Lt_per_hr]", freq, Lt_per_hr);
- char *valueFormatted = ezlopi_valueformatter_float(Lt_per_hr);
- if (valueFormatted)
- {
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- free(valueFormatted);
+ char *valueFormatted = ezlopi_valueformatter_float(Lt_per_hr);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, Lt_per_hr);
+ ret = 1;
}
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, Lt_per_hr);
- ret = 1;
}
}
return ret;
@@ -248,94 +258,97 @@ static void __extract_YFS201_Pulse_Count_func(l_ezlopi_item_t *item)
if (NULL != item)
{
yfs201_t *yfs201_data = (yfs201_t *)item->user_arg;
- gpio_num_t pulse_pin = item->interface.pwm.gpio_num;
- // creating queue here
- yfs201_queue = xQueueCreate(YFS201_QUEUE_SIZE, sizeof(int32_t)); // takes max -> 1mSec
- if (yfs201_queue)
+ if (yfs201_data)
{
- int32_t start_time = 0;
- // extract data for untill all queue is filled
- // TRACE_E("--------- Queue Empty --------");
-
- while ((yfs201_data->yfs201_QueueFlag) < YFS201_QUEUE_FULL)
+ gpio_num_t pulse_pin = item->interface.pwm.gpio_num;
+ // creating queue here
+ yfs201_queue = xQueueCreate(YFS201_QUEUE_SIZE, sizeof(int32_t)); // takes max -> 1mSec
+ if (yfs201_queue)
{
- (yfs201_data->_pulses_yfs201) = 0; // reset variable to store fresh counts within [200ms]
- gpio_isr_handler_add(pulse_pin, gpio_isr_handler, &(yfs201_data->_pulses_yfs201)); // add -> gpio_isr_handle(pin_num)
- start_time = (int32_t)esp_timer_get_time();
- while (((int32_t)esp_timer_get_time() - start_time) < (1000000 / YFS201_QUEUE_SIZE)) // 200ms -> 200000uS
- {
- // polls for '(1000000 / YFS201_QUEUE_SIZE)' -> eg. 200ms
- }
- // check queue_full => 1
+ int32_t start_time = 0;
+ // extract data for untill all queue is filled
+ // TRACE_E("--------- Queue Empty --------");
- if (xQueueSend(yfs201_queue, &(yfs201_data->_pulses_yfs201), 0))
- {
- (yfs201_data->yfs201_QueueFlag) = YFS201_QUEUE_AVAILABLE;
- // TRACE_E("Pulse_count : %d", (yfs201_data->_pulses_yfs201));
- }
- else
+ while ((yfs201_data->yfs201_QueueFlag) < YFS201_QUEUE_FULL)
{
- // TRACE_E("--------- Queue Full --------");
- (yfs201_data->yfs201_QueueFlag) = YFS201_QUEUE_FULL;
+ (yfs201_data->_pulses_yfs201) = 0; // reset variable to store fresh counts within [200ms]
+ gpio_isr_handler_add(pulse_pin, gpio_isr_handler, &(yfs201_data->_pulses_yfs201)); // add -> gpio_isr_handle(pin_num)
+ start_time = (int32_t)esp_timer_get_time();
+ while (((int32_t)esp_timer_get_time() - start_time) < (1000000 / YFS201_QUEUE_SIZE)) // 200ms -> 200000uS
+ {
+ // polls for '(1000000 / YFS201_QUEUE_SIZE)' -> eg. 200ms
+ }
+ // check queue_full => 1
+
+ if (xQueueSend(yfs201_queue, &(yfs201_data->_pulses_yfs201), 0))
+ {
+ (yfs201_data->yfs201_QueueFlag) = YFS201_QUEUE_AVAILABLE;
+ // TRACE_E("Pulse_count : %d", (yfs201_data->_pulses_yfs201));
+ }
+ else
+ {
+ // TRACE_E("--------- Queue Full --------");
+ (yfs201_data->yfs201_QueueFlag) = YFS201_QUEUE_FULL;
+ }
+ // disable -> gpio_isr_handle_remove(pin_num)
+ gpio_isr_handler_remove(pulse_pin);
}
- // disable -> gpio_isr_handle_remove(pin_num)
- gpio_isr_handler_remove(pulse_pin);
}
- }
- if ((yfs201_data->yfs201_QueueFlag) == YFS201_QUEUE_FULL)
- {
- // loop through all the queue[0-5] values -> pulse counts
- int32_t P_count[YFS201_QUEUE_SIZE] = {0};
- int val = 0;
- for (uint8_t i = 0; i < YFS201_QUEUE_SIZE; i++)
+ if ((yfs201_data->yfs201_QueueFlag) == YFS201_QUEUE_FULL)
{
- if (xQueueReceive(yfs201_queue, &val, portMAX_DELAY))
+ // loop through all the queue[0-5] values -> pulse counts
+ int32_t P_count[YFS201_QUEUE_SIZE] = {0};
+ int val = 0;
+ for (uint8_t i = 0; i < YFS201_QUEUE_SIZE; i++)
{
- if (val)
+ if (xQueueReceive(yfs201_queue, &val, portMAX_DELAY))
{
- P_count[i] = val; // [0 - YFS201_QUEUE_SIZE]
+ if (val)
+ {
+ P_count[i] = val; // [0 - YFS201_QUEUE_SIZE]
+ }
}
}
- }
- // generate frequency of occurance table from "P_count[]" array values
- uint8_t freq[YFS201_QUEUE_SIZE] = {0};
- float error = 0;
- for (uint8_t x = 0; x < YFS201_QUEUE_SIZE; x++)
- {
- for (uint8_t i = 0; i < YFS201_QUEUE_SIZE; i++)
+ // generate frequency of occurance table from "P_count[]" array values
+ uint8_t freq[YFS201_QUEUE_SIZE] = {0};
+ float error = 0;
+ for (uint8_t x = 0; x < YFS201_QUEUE_SIZE; x++)
{
- error = P_count[x] - P_count[i];
- error = ((error >= 0) ? error : error * -1); // finding difference between two readings
- if (error < P_count[x] * 0.1) // [error less than +-10%]
+ for (uint8_t i = 0; i < YFS201_QUEUE_SIZE; i++)
{
- freq[x] += 1; // increment dominace count
+ error = P_count[x] - P_count[i];
+ error = ((error >= 0) ? error : error * -1); // finding difference between two readings
+ if (error < P_count[x] * 0.1) // [error less than +-10%]
+ {
+ freq[x] += 1; // increment dominace count
+ }
}
}
- }
- // find the dominant period
- uint8_t max_freq_index = 0;
- int32_t dominant_val = 0;
- for (uint8_t i = 0; i < YFS201_QUEUE_SIZE; i++)
- {
- if (freq[i] > dominant_val)
+ // find the dominant period
+ uint8_t max_freq_index = 0;
+ int32_t dominant_val = 0;
+ for (uint8_t i = 0; i < YFS201_QUEUE_SIZE; i++)
{
- dominant_val = freq[i];
- max_freq_index = i;
+ if (freq[i] > dominant_val)
+ {
+ dominant_val = freq[i];
+ max_freq_index = i;
+ }
}
- }
- // TRACE_S("......................Dominant count ......{%d} ", P_count[max_freq_index]);
+ // TRACE_S("......................Dominant count ......{%d} ", P_count[max_freq_index]);
- // reset Queue_flag
- (yfs201_data->yfs201_QueueFlag) = YFS201_QUEUE_AVAILABLE;
+ // reset Queue_flag
+ (yfs201_data->yfs201_QueueFlag) = YFS201_QUEUE_AVAILABLE;
- // write the dominant pulse count
- yfs201_data->yfs201_dominant_pulse_count = P_count[max_freq_index];
- }
+ // write the dominant pulse count
+ yfs201_data->yfs201_dominant_pulse_count = P_count[max_freq_index];
+ }
- // Deleting queue after no use to avoid conflicts
- vQueueDelete(yfs201_queue);
+ // Deleting queue after no use to avoid conflicts
+ vQueueDelete(yfs201_queue);
+ }
}
}
diff --git a/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.c b/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.c
index a081aa090..222a5e0ce 100644
--- a/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.c
+++ b/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.c
@@ -81,7 +81,7 @@ static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.adc.gpio_num);
item->interface.adc.resln_bit = 3; // ADC 12_bit
// passing the custom data_structure
@@ -96,11 +96,10 @@ static int __0055_prepare(void *arg)
s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
- flex_t *FLEX_value = (flex_t *)malloc(sizeof(flex_t));
- if (NULL != FLEX_value)
+ flex_t *flex_res_value = (flex_t *)malloc(sizeof(flex_t));
+ if (flex_res_value)
{
- memset(FLEX_value, 0, sizeof(flex_t));
-
+ memset(flex_res_value, 0, sizeof(flex_t));
l_ezlopi_device_t *device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (device_adc)
{
@@ -109,20 +108,20 @@ static int __0055_prepare(void *arg)
if (item_adc)
{
item_adc->cloud_properties.device_id = device_adc->cloud_properties.device_id;
- __prepare_item_adc_cloud_properties(item_adc, device_prep_arg->cjson_device, FLEX_value);
+ __prepare_item_adc_cloud_properties(item_adc, device_prep_arg->cjson_device, flex_res_value);
ret = 1;
}
else
{
ret = -1;
ezlopi_device_free_device(device_adc);
- free(FLEX_value);
+ free(flex_res_value);
}
}
else
{
ret = -1;
- free(FLEX_value);
+ free(flex_res_value);
}
}
}
@@ -134,21 +133,36 @@ static int __0055_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
- {
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
- }
- if (0 == ret)
+ flex_t *flex_res_value = (flex_t *)malloc(sizeof(flex_t));
+ if (flex_res_value)
{
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ {
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
{
- free(item->user_arg);
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -160,12 +174,18 @@ static int __0055_get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON *cj_result = (cJSON *)arg;
if (cj_result)
{
- flex_t *FLEX_value = (flex_t *)item->user_arg;
- char *valueFormatted = ezlopi_valueformatter_int(FLEX_value->RS_0055);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, FLEX_value->RS_0055);
- free(valueFormatted);
- ret = 1;
+ flex_t *flex_res_value = (flex_t *)item->user_arg;
+ if (flex_res_value)
+ {
+ char *valueFormatted = ezlopi_valueformatter_int(flex_res_value->rs_0055);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, flex_res_value->rs_0055);
+ free(valueFormatted);
+ }
+ ret = 1;
+ }
}
}
return ret;
@@ -175,8 +195,8 @@ static int __0055_notify(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- flex_t *FLEX_value = (flex_t *)item->user_arg;
- if (FLEX_value)
+ flex_t *flex_res_value = (flex_t *)item->user_arg;
+ if (flex_res_value)
{
s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0,
.voltage = 0};
@@ -184,12 +204,12 @@ static int __0055_notify(l_ezlopi_item_t *item)
ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
float Vout = (ezlopi_analog_data.voltage) / 1000.0f; // millivolt -> voltage
- // calculate the 'RS_0055' resistance value using [voltage divider rule]
- int new_RS_0055 = (int)(((flex_Vin / Vout) - 1) * flex_Rout);
- if (new_RS_0055 != FLEX_value->RS_0055)
+ // calculate the 'rs_0055' resistance value using [voltage divider rule]
+ int new_rs_0055 = (int)(((flex_Vin / Vout) - 1) * flex_Rout);
+ if (new_rs_0055 != flex_res_value->rs_0055)
{
ezlopi_device_value_updated_from_device_v3(item);
- FLEX_value->RS_0055 = new_RS_0055;
+ flex_res_value->rs_0055 = new_rs_0055;
}
ret = 1;
}
diff --git a/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.h b/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.h
index bc95b4bc7..852bb2984 100644
--- a/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.h
+++ b/ezlopi-sensors-devices/sensor-0055-ADC-FlexResistor/sensor_0055_ADC_FlexResistor.h
@@ -49,7 +49,7 @@
typedef struct flex_t
{
- int RS_0055;
+ int rs_0055;
} flex_t;
//-----------------------------------------------------------------------------------------------------------------------------
int sensor_0055_ADC_FlexResistor(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg);
diff --git a/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.c b/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.c
index f3e385bfb..4af9f2279 100644
--- a/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.c
+++ b/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.c
@@ -81,7 +81,7 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.adc.gpio_num);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_str, item->interface.adc.gpio_num);
item->interface.adc.resln_bit = 3; // ADC 12_bit
// passing the custom data_structure
@@ -95,10 +95,10 @@ static int __0056_prepare(void *arg)
s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
- fsr_t *FSR_struct = (fsr_t *)malloc(sizeof(fsr_t));
- if (NULL != FSR_struct)
+ fsr_t *fsr_struct = (fsr_t *)malloc(sizeof(fsr_t));
+ if (NULL != fsr_struct)
{
- memset(FSR_struct, 0, sizeof(fsr_t));
+ memset(fsr_struct, 0, sizeof(fsr_t));
l_ezlopi_device_t *FSR_device = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (FSR_device)
@@ -108,20 +108,20 @@ static int __0056_prepare(void *arg)
if (FSR_item)
{
FSR_item->cloud_properties.device_id = FSR_device->cloud_properties.device_id;
- __prepare_item_cloud_properties(FSR_item, device_prep_arg->cjson_device, FSR_struct);
+ __prepare_item_cloud_properties(FSR_item, device_prep_arg->cjson_device, fsr_struct);
ret = 1;
}
else
{
ret = -1;
ezlopi_device_free_device(FSR_device);
- free(FSR_struct);
+ free(fsr_struct);
}
}
else
{
ret = -1;
- free(FSR_struct);
+ free(fsr_struct);
}
}
}
@@ -133,21 +133,36 @@ static int __0056_init(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ fsr_t *fsr_struct = (fsr_t *)item->user_arg;
+ if (fsr_struct)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
{
- free(item->user_arg);
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
@@ -160,11 +175,17 @@ static int __0056_get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON *cj_result = (cJSON *)arg;
if (cj_result)
{
- fsr_t *FSR_struct = (fsr_t *)item->user_arg;
- char *valueFormatted = ezlopi_valueformatter_float(FSR_struct->FSR_value);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, FSR_struct->FSR_value);
- free(valueFormatted);
+ fsr_t *fsr_struct = (fsr_t *)item->user_arg;
+ if (fsr_struct)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, fsr_struct->fsr_value);
+ char *valueFormatted = ezlopi_valueformatter_float(fsr_struct->fsr_value);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
ret = 1;
}
}
@@ -176,20 +197,23 @@ static int __0056_notify(l_ezlopi_item_t *item)
int ret = 0;
if (item)
{
- fsr_t *FSR_struct = (fsr_t *)item->user_arg;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
- float Vout = (ezlopi_analog_data.voltage) / 1000.0f; // millivolt -> voltage
-
- // New Force[N] is :
- float new_force = 0.0098f * Calculate_GramForce(Vout);
- // TRACE_E(" Force[N]: %.4f", FSR_struct->FSR_value);
- if (new_force != FSR_struct->FSR_value)
+ fsr_t *fsr_struct = (fsr_t *)item->user_arg;
+ if (fsr_struct)
{
- FSR_struct->FSR_value = new_force;
- ezlopi_device_value_updated_from_device_v3(item);
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ ezlopi_adc_get_adc_data(item->interface.adc.gpio_num, &ezlopi_analog_data);
+ float Vout = (ezlopi_analog_data.voltage) / 1000.0f; // millivolt -> voltage
+
+ // New Force[N] is :
+ float new_force = 0.0098f * Calculate_GramForce(Vout);
+ // TRACE_E(" Force[N]: %.4f", fsr_struct->fsr_value);
+ if (new_force != fsr_struct->fsr_value)
+ {
+ fsr_struct->fsr_value = new_force;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
+ ret = 1;
}
- ret = 1;
}
return ret;
}
diff --git a/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.h b/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.h
index 8b9c09130..2df421d41 100644
--- a/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.h
+++ b/ezlopi-sensors-devices/sensor-0056-ADC-Force-Sensitive-Resistor/sensor_0056_ADC_Force_Sensitive_Resistor.h
@@ -93,7 +93,7 @@
typedef struct fsr_t
{
- float FSR_value;
+ float fsr_value;
} fsr_t;
//-----------------------------------------------------------------------------------------------------------------------------
int sensor_0056_ADC_Force_Sensitive_Resistor(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg);
diff --git a/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.c b/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.c
index e1124b585..e255e7177 100644
--- a/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.c
+++ b/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.c
@@ -99,10 +99,10 @@ static int __0057_prepare(void *arg)
}
//---------------------------- ADC - DEVICE 2 -------------------------------------------
- flame_t *FLAME_struct = (flame_t *)malloc(sizeof(flame_t));
- if (NULL != FLAME_struct)
+ flame_t *flame_struct = (flame_t *)malloc(sizeof(flame_t));
+ if (NULL != flame_struct)
{
- memset(FLAME_struct, 0, sizeof(flame_t));
+ memset(flame_struct, 0, sizeof(flame_t));
l_ezlopi_device_t *flame_device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (flame_device_adc)
{
@@ -111,20 +111,20 @@ static int __0057_prepare(void *arg)
if (flame_item_adc)
{
flame_item_adc->cloud_properties.device_id = flame_device_adc->cloud_properties.device_id;
- __prepare_item_adc_cloud_properties(flame_item_adc, device_prep_arg->cjson_device, FLAME_struct);
+ __prepare_item_adc_cloud_properties(flame_item_adc, device_prep_arg->cjson_device, flame_struct);
ret = 1;
}
else
{
ret = -1;
ezlopi_device_free_device(flame_device_adc);
- free(FLAME_struct);
+ free(flame_struct);
}
}
else
{
ret = -1;
- free(FLAME_struct);
+ free(flame_struct);
}
}
}
@@ -136,31 +136,55 @@ static int __0057_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_heat_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
- {
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
- }
- if ((ezlopi_item_name_temperature_changes == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ if (ezlopi_item_name_heat_alarm == item->cloud_properties.item_name)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- if (0 == ret)
+ else if (ezlopi_item_name_temperature_changes == item->cloud_properties.item_name)
{
- ret = -1;
- if (item->user_arg)
+ flame_t *flame_struct = (flame_t *)item->user_arg;
+ if (flame_struct)
{
- free(item->user_arg);
- item->user_arg = NULL;
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
+ }
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
}
}
}
@@ -190,7 +214,7 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("flame_> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
@@ -255,16 +279,21 @@ static int __0057_get_item(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "heat_ok");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "heat_ok");
}
- if (ezlopi_item_name_temperature_changes == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_temperature_changes == item->cloud_properties.item_name)
{
- flame_t *FLAME_struct = (flame_t *)item->user_arg;
-
- char *valueFormatted = ezlopi_valueformatter_float(FLAME_struct->_absorbed_percent);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, FLAME_struct->_absorbed_percent);
- free(valueFormatted);
+ flame_t *flame_struct = (flame_t *)item->user_arg;
+ if (flame_struct)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, flame_struct->absorbed_percent);
+ char *valueFormatted = ezlopi_valueformatter_float(flame_struct->absorbed_percent);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
+ ret = 1;
}
- ret = 1;
}
}
return ret;
@@ -283,13 +312,19 @@ static int __0057_get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "heat_ok");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "heat_ok");
}
- if (ezlopi_item_name_temperature_changes == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_temperature_changes == item->cloud_properties.item_name)
{
- flame_t *FLAME_struct = (flame_t *)item->user_arg;
- char *valueFormatted = ezlopi_valueformatter_float(FLAME_struct->_absorbed_percent);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, FLAME_struct->_absorbed_percent);
- free(valueFormatted);
+ flame_t *flame_struct = (flame_t *)item->user_arg;
+ if (flame_struct)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, flame_struct->absorbed_percent);
+ char *valueFormatted = ezlopi_valueformatter_float(flame_struct->absorbed_percent);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -319,18 +354,21 @@ static int __0057_notify(l_ezlopi_item_t *item)
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_temperature_changes == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_temperature_changes == item->cloud_properties.item_name)
{
- flame_t *FLAME_struct = (flame_t *)item->user_arg;
- float analog_sensor_volt = 0, max_volt_reading = 0;
- // extract the sensor_output_values
- __extract_KY026_sensor_value(item->interface.adc.gpio_num, &analog_sensor_volt, &max_volt_reading);
- float new_percent = ((1 - (analog_sensor_volt / max_volt_reading)) * 100.0f);
- // TRACE_E("Heat-detected: %.2f percent", _absorbed_percent);
- if (new_percent != FLAME_struct->_absorbed_percent)
+ flame_t *flame_struct = (flame_t *)item->user_arg;
+ if (flame_struct)
{
- ezlopi_device_value_updated_from_device_v3(item);
- FLAME_struct->_absorbed_percent = new_percent;
+ float analog_sensor_volt = 0, max_volt_reading = 0;
+ // extract the sensor_output_values
+ __extract_KY026_sensor_value(item->interface.adc.gpio_num, &analog_sensor_volt, &max_volt_reading);
+ float new_percent = ((1 - (analog_sensor_volt / max_volt_reading)) * 100.0f);
+ // TRACE_E("Heat-detected: %.2f percent", absorbed_percent);
+ if (new_percent != flame_struct->absorbed_percent)
+ {
+ ezlopi_device_value_updated_from_device_v3(item);
+ flame_struct->absorbed_percent = new_percent;
+ }
}
}
ret = 1;
diff --git a/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.h b/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.h
index 0cfdb2ed3..5e4aa359e 100644
--- a/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.h
+++ b/ezlopi-sensors-devices/sensor-0057-other-KY026-FlameDetector/sensor_0057_other_KY026_FlameDetector.h
@@ -48,7 +48,7 @@ typedef enum
typedef struct flame_t
{
- float _absorbed_percent;
+ float absorbed_percent;
} flame_t;
//----------------------------------------------------
int sensor_0057_other_KY026_FlameDetector(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg);
diff --git a/ezlopi-sensors-devices/sensor-0059-other-MQ6-LPG-detector/sensor_0059_other_MQ6_LPG_detector.c b/ezlopi-sensors-devices/sensor-0059-other-MQ6-LPG-detector/sensor_0059_other_MQ6_LPG_detector.c
index 36875c461..a81bb0afb 100644
--- a/ezlopi-sensors-devices/sensor-0059-other-MQ6-LPG-detector/sensor_0059_other_MQ6_LPG_detector.c
+++ b/ezlopi-sensors-devices/sensor-0059-other-MQ6-LPG-detector/sensor_0059_other_MQ6_LPG_detector.c
@@ -72,14 +72,7 @@ int sensor_0059_other_MQ6_LPG_detector(e_ezlopi_actions_t action, l_ezlopi_item_
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- if (item)
- {
- s_mq6_value_t *MQ6_value = (s_mq6_value_t *)item->user_arg;
- if (true == MQ6_value->Calibration_complete_LPG)
- {
- __0059_notify(item);
- }
- }
+ __0059_notify(item);
break;
}
default:
@@ -154,37 +147,66 @@ static int __0059_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
+ }
}
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ else if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name))
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
s_mq6_value_t *MQ6_value = (s_mq6_value_t *)item->user_arg;
- if (false == MQ6_value->Calibration_complete_LPG)
+ if (MQ6_value)
{
- xTaskCreate(__calibrate_MQ6_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ {
+ // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ // calibrate if not done
+ if (false == MQ6_value->Calibration_complete_LPG)
+ {
+ xTaskCreate(__calibrate_MQ6_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ else
{
- free(item->user_arg);
- item->user_arg = NULL;
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
}
}
}
@@ -216,7 +238,7 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ6-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
@@ -281,13 +303,19 @@ static int __0059_get_item(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq6_value_t *MQ6_value = ((s_mq6_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ6_value->_LPG_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ6_value->_LPG_ppm);
- free(valueFormatted);
+ if (MQ6_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ6_value->_LPG_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ6_value->_LPG_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -308,13 +336,19 @@ static int __0059_get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq6_value_t *MQ6_value = ((s_mq6_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ6_value->_LPG_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ6_value->_LPG_ppm);
- free(valueFormatted);
+ if (MQ6_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ6_value->_LPG_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ6_value->_LPG_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -344,15 +378,18 @@ static int __0059_notify(l_ezlopi_item_t *item)
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
// extract the sensor_output_values
- double new_value = (double)__extract_MQ6_sensor_ppm(item);
s_mq6_value_t *MQ6_value = (s_mq6_value_t *)item->user_arg;
- if (fabs((double)(MQ6_value->_LPG_ppm) - new_value) > 0.0001)
+ if ((MQ6_value) && (true == MQ6_value->Calibration_complete_LPG))
{
- MQ6_value->_LPG_ppm = (float)new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ double new_value = (double)__extract_MQ6_sensor_ppm(item);
+ if (fabs((double)(MQ6_value->_LPG_ppm) - new_value) > 0.0001)
+ {
+ MQ6_value->_LPG_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
@@ -362,49 +399,52 @@ static int __0059_notify(l_ezlopi_item_t *item)
//------------------------------------------------------------------------------------------------------
static float __extract_MQ6_sensor_ppm(l_ezlopi_item_t *item)
{
- uint32_t mq6_adc_pin = item->interface.adc.gpio_num;
s_mq6_value_t *MQ6_value = (s_mq6_value_t *)item->user_arg;
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- // extract the mean_sensor_analog_output_voltage
- float analog_sensor_volt = 0;
- for (uint8_t x = 10; x > 0; x--)
- {
- ezlopi_adc_get_adc_data(mq6_adc_pin, &ezlopi_analog_data);
+ if (MQ6_value)
+ { // calculation process
+ //-------------------------------------------------
+ uint32_t mq6_adc_pin = item->interface.adc.gpio_num;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ // extract the mean_sensor_analog_output_voltage
+ float analog_sensor_volt = 0;
+ for (uint8_t x = 10; x > 0; x--)
+ {
+ ezlopi_adc_get_adc_data(mq6_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
+ analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
#else
- analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
+ analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
#endif
- vTaskDelay(1);
- }
- analog_sensor_volt = analog_sensor_volt / 10.0f;
+ vTaskDelay(1);
+ }
+ analog_sensor_volt = analog_sensor_volt / 10.0f;
- //-----------------------------------------------------------------------------------
- // Stage_2 : [from 'sensor_0059_ADC_MQ6_methane_gas_detector.h']
+ //-----------------------------------------------------------------------------------
+ // Stage_2 : [from 'sensor_0059_ADC_MQ6_methane_gas_detector.h']
- // 1. Calculate 'Rs_gas' for the gas detected
- float Rs_gas = (((MQ6_VOLT_RESOLUTION_Vc * mq6_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq6_eqv_RL);
+ // 1. Calculate 'Rs_gas' for the gas detected
+ float Rs_gas = (((MQ6_VOLT_RESOLUTION_Vc * mq6_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq6_eqv_RL);
- // 1.1 Calculate @ 'ratio' during LPG presence
- double _ratio = (Rs_gas / ((MQ6_value->MQ6_R0_constant <= 0) ? (1.0f) : (MQ6_value->MQ6_R0_constant))); // avoid dividing by zero??
- if (_ratio <= 0)
- {
- _ratio = 0;
- }
- //-------------------------------------------------
+ // 1.1 Calculate @ 'ratio' during LPG presence
+ double _ratio = (Rs_gas / ((MQ6_value->MQ6_R0_constant <= 0) ? (1.0f) : (MQ6_value->MQ6_R0_constant))); // avoid dividing by zero??
+ if (_ratio <= 0)
+ {
+ _ratio = 0;
+ }
+ //-------------------------------------------------
- // 1.2 Calculate _LPG_ppm
- float _LPG_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq6) / m_slope_mq6); // ---> _LPG_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
- if (_LPG_ppm < 0)
- {
- _LPG_ppm = 0; // No negative values accepted or upper datasheet recomendation.
- }
- TRACE_E("_LPG_ppm [LPG] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _LPG_ppm, (float)_ratio, analog_sensor_volt);
+ // 1.2 Calculate _LPG_ppm
+ float _LPG_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq6) / m_slope_mq6); // ---> _LPG_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
+ if (_LPG_ppm < 0)
+ {
+ _LPG_ppm = 0; // No negative values accepted or upper datasheet recomendation.
+ }
+ TRACE_E("_LPG_ppm [LPG] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _LPG_ppm, (float)_ratio, analog_sensor_volt);
- //-------------------------------------------------
- return _LPG_ppm;
+ //-------------------------------------------------
+ return _LPG_ppm;
+ }
+ return 0;
}
static void __calibrate_MQ6_R0_resistance(void *params)
@@ -413,54 +453,56 @@ static void __calibrate_MQ6_R0_resistance(void *params)
if (NULL != item)
{
s_mq6_value_t *MQ6_value = (s_mq6_value_t *)item->user_arg;
-
- uint32_t mq6_adc_pin = item->interface.adc.gpio_num;
- //-------------------------------------------------
- // let the sensor to heat for 20seconds
- for (uint8_t j = 20; j > 0; j--)
- {
- TRACE_E("Heating sensor.........time left: %d sec", j);
- vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
- }
- //-------------------------------------------------
- // extract the mean_sensor_analog_output_voltage
- float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- for (uint8_t i = 100; i > 0; i--)
+ if (MQ6_value)
{
- if (i % 20 == 0)
+ uint32_t mq6_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ // let the sensor to heat for 20seconds
+ for (uint8_t j = 20; j > 0; j--)
{
- TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ TRACE_E("Heating sensor.........time left: %d sec", j);
+ vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
}
- // extract ADC values
- ezlopi_adc_get_adc_data(mq6_adc_pin, &ezlopi_analog_data);
+ //-------------------------------------------------
+ // extract the mean_sensor_analog_output_voltage
+ float _sensor_volt = 0;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ for (uint8_t i = 100; i > 0; i--)
+ {
+ if (i % 20 == 0)
+ {
+ TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ }
+ // extract ADC values
+ ezlopi_adc_get_adc_data(mq6_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
+ _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
#else
- _sensor_volt += (float)(ezlopi_analog_data->voltage);
+ _sensor_volt += (float)(ezlopi_analog_data->voltage);
#endif
- vTaskDelay(1); // 10ms
- }
- _sensor_volt = _sensor_volt / 100.0f;
+ vTaskDelay(1); // 10ms
+ }
+ _sensor_volt = _sensor_volt / 100.0f;
- //-------------------------------------------------
- // Calculate the 'Rs' of heater during clean air [calibration phase]
- // Range -> [2Kohm - 20Kohm]
- float RS_calib = ((MQ6_VOLT_RESOLUTION_Vc * mq6_eqv_RL) / (_sensor_volt / 1000.0f)) - mq6_eqv_RL; // Calculate RS in fresh air
- TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
- if (RS_calib < 0)
- {
- RS_calib = 0; // No negative values accepted.
- }
- // Calculate the R0_air which is constant through-out
- MQ6_value->MQ6_R0_constant = (RS_calib / RatioMQ6CleanAir); // Calculate MQ6_R0_constant
- TRACE_E("CALIB_TASK -> 'MQ6_R0_constant' = %.2f", MQ6_value->MQ6_R0_constant);
- if (MQ6_value->MQ6_R0_constant < 0)
- {
- MQ6_value->MQ6_R0_constant = 0; // No negative values accepted.
+ //-------------------------------------------------
+ // Calculate the 'Rs' of heater during clean air [calibration phase]
+ // Range -> [2Kohm - 20Kohm]
+ float RS_calib = ((MQ6_VOLT_RESOLUTION_Vc * mq6_eqv_RL) / (_sensor_volt / 1000.0f)) - mq6_eqv_RL; // Calculate RS in fresh air
+ TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
+ if (RS_calib < 0)
+ {
+ RS_calib = 0; // No negative values accepted.
+ }
+ // Calculate the R0_air which is constant through-out
+ MQ6_value->MQ6_R0_constant = (RS_calib / RatioMQ6CleanAir); // Calculate MQ6_R0_constant
+ TRACE_E("CALIB_TASK -> 'MQ6_R0_constant' = %.2f", MQ6_value->MQ6_R0_constant);
+ if (MQ6_value->MQ6_R0_constant < 0)
+ {
+ MQ6_value->MQ6_R0_constant = 0; // No negative values accepted.
+ }
+ // Set calibration_complete_LPG flag
+ MQ6_value->Calibration_complete_LPG = true;
}
- // Set calibration_complete_LPG flag
- MQ6_value->Calibration_complete_LPG = true;
}
vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0060-digitalIn-vibration-detector/sensor_0060_digitalIn_vibration_detector.c b/ezlopi-sensors-devices/sensor-0060-digitalIn-vibration-detector/sensor_0060_digitalIn_vibration_detector.c
index f229cd793..48c6dbdcc 100644
--- a/ezlopi-sensors-devices/sensor-0060-digitalIn-vibration-detector/sensor_0060_digitalIn_vibration_detector.c
+++ b/ezlopi-sensors-devices/sensor-0060-digitalIn-vibration-detector/sensor_0060_digitalIn_vibration_detector.c
@@ -93,7 +93,7 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "logic_inv", item->interface.gpio.gpio_in.invert);
item->interface.gpio.gpio_in.enable = true;
@@ -157,15 +157,16 @@ static int __0060_init(l_ezlopi_item_t *item)
item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
ret = 1;
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
diff --git a/ezlopi-sensors-devices/sensor-0061-digitalIn-reed-switch/sensor_0061_digitalIn_reed_switch.c b/ezlopi-sensors-devices/sensor-0061-digitalIn-reed-switch/sensor_0061_digitalIn_reed_switch.c
index 686d7f564..564aefdcb 100644
--- a/ezlopi-sensors-devices/sensor-0061-digitalIn-reed-switch/sensor_0061_digitalIn_reed_switch.c
+++ b/ezlopi-sensors-devices/sensor-0061-digitalIn-reed-switch/sensor_0061_digitalIn_reed_switch.c
@@ -89,7 +89,7 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "logic_inv", item->interface.gpio.gpio_in.invert);
item->interface.gpio.gpio_in.enable = true;
@@ -149,27 +149,24 @@ static int __0061_init(l_ezlopi_item_t *item)
: GPIO_PULLUP_DISABLE,
.intr_type = item->interface.gpio.gpio_in.interrupt,
};
- ret = gpio_config(&input_conf);
- if (ret)
- {
- TRACE_E("Error initializing Reed switch");
- }
- else
+ if (ESP_OK == gpio_config(&input_conf))
{
item->interface.gpio.gpio_in.value = gpio_get_level(item->interface.gpio.gpio_in.gpio_num);
gpio_isr_service_register_v3(item, _0061_update_from_device, 200);
ret = 1;
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
+ TRACE_E("Error initializing Reed switch");
}
}
+ else
+ {
+ ret = -1;
+ ezlopi_device_free_device_by_item(item);
+ }
}
return ret;
}
diff --git a/ezlopi-sensors-devices/sensor-0062-other-MQ7-CO-detector/sensor_0062_other_MQ7_CO_detector.c b/ezlopi-sensors-devices/sensor-0062-other-MQ7-CO-detector/sensor_0062_other_MQ7_CO_detector.c
index dbd05ba80..28c527311 100644
--- a/ezlopi-sensors-devices/sensor-0062-other-MQ7-CO-detector/sensor_0062_other_MQ7_CO_detector.c
+++ b/ezlopi-sensors-devices/sensor-0062-other-MQ7-CO-detector/sensor_0062_other_MQ7_CO_detector.c
@@ -26,7 +26,7 @@ typedef struct s_mq7_value
bool Calibration_complete_CO;
} s_mq7_value_t;
-const char *mq7_sensor_gas_alarm_token[] = {
+const char* mq7_sensor_gas_alarm_token[] = {
"no_gas",
"combustible_gas_detected",
"toxic_gas_detected",
@@ -34,21 +34,21 @@ const char *mq7_sensor_gas_alarm_token[] = {
};
//-------------------------------------------------------------------------
-static int __0062_prepare(void *arg);
-static int __0062_init(l_ezlopi_item_t *item);
-static int __0062_get_item(l_ezlopi_item_t *item, void *arg);
-static int __0062_get_cjson_value(l_ezlopi_item_t *item, void *arg);
-static int __0062_notify(l_ezlopi_item_t *item);
+static int __0062_prepare(void* arg);
+static int __0062_init(l_ezlopi_item_t* item);
+static int __0062_get_item(l_ezlopi_item_t* item, void* arg);
+static int __0062_get_cjson_value(l_ezlopi_item_t* item, void* arg);
+static int __0062_notify(l_ezlopi_item_t* item);
-static void __calibrate_MQ7_R0_resistance(void *params);
-static float __extract_MQ7_sensor_ppm(l_ezlopi_item_t *item);
-static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
-static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device);
-static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device);
-static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data);
+static void __calibrate_MQ7_R0_resistance(void* params);
+static float __extract_MQ7_sensor_ppm(l_ezlopi_item_t* item);
+static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
+static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device);
+static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device);
+static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data);
//--------------------------------------------------------------------------------------------------------
-int sensor_0062_other_MQ7_CO_detector(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0062_other_MQ7_CO_detector(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -75,14 +75,7 @@ int sensor_0062_other_MQ7_CO_detector(e_ezlopi_actions_t action, l_ezlopi_item_t
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- if (item)
- {
- s_mq7_value_t *MQ7_value = (s_mq7_value_t *)item->user_arg;
- if (true == MQ7_value->Calibration_complete_CO)
- {
- __0062_notify(item);
- }
- }
+ __0062_notify(item);
break;
}
default:
@@ -93,18 +86,18 @@ int sensor_0062_other_MQ7_CO_detector(e_ezlopi_actions_t action, l_ezlopi_item_t
return ret;
}
//----------------------------------------------------
-static int __0062_prepare(void *arg)
+static int __0062_prepare(void* arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *device_prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* device_prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (device_prep_arg && (NULL != device_prep_arg->cjson_device))
{
//--------------------------- DIGI - DEVICE 1 --------------------------------------------
- l_ezlopi_device_t *MQ7_device_digi = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t* MQ7_device_digi = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (MQ7_device_digi)
{
__prepare_device_digi_cloud_properties(MQ7_device_digi, device_prep_arg->cjson_device);
- l_ezlopi_item_t *MQ7_item_digi = ezlopi_device_add_item_to_device(MQ7_device_digi, sensor_0062_other_MQ7_CO_detector);
+ l_ezlopi_item_t* MQ7_item_digi = ezlopi_device_add_item_to_device(MQ7_device_digi, sensor_0062_other_MQ7_CO_detector);
if (MQ7_item_digi)
{
MQ7_item_digi->cloud_properties.device_id = MQ7_device_digi->cloud_properties.device_id;
@@ -119,15 +112,15 @@ static int __0062_prepare(void *arg)
}
//---------------------------- ADC - DEVICE 2 -------------------------------------------
- s_mq7_value_t *MQ7_value = (s_mq7_value_t *)malloc(sizeof(s_mq7_value_t));
+ s_mq7_value_t* MQ7_value = (s_mq7_value_t*)malloc(sizeof(s_mq7_value_t));
if (NULL != MQ7_value)
{
memset(MQ7_value, 0, sizeof(s_mq7_value_t));
- l_ezlopi_device_t *MQ7_device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
+ l_ezlopi_device_t* MQ7_device_adc = ezlopi_device_add_device(device_prep_arg->cjson_device);
if (MQ7_device_adc)
{
__prepare_device_adc_cloud_properties(MQ7_device_adc, device_prep_arg->cjson_device);
- l_ezlopi_item_t *MQ7_item_adc = ezlopi_device_add_item_to_device(MQ7_device_adc, sensor_0062_other_MQ7_CO_detector);
+ l_ezlopi_item_t* MQ7_item_adc = ezlopi_device_add_item_to_device(MQ7_device_adc, sensor_0062_other_MQ7_CO_detector);
if (MQ7_item_adc)
{
MQ7_item_adc->cloud_properties.device_id = MQ7_device_adc->cloud_properties.device_id;
@@ -151,42 +144,68 @@ static int __0062_prepare(void *arg)
return ret;
}
-static int __0062_init(l_ezlopi_item_t *item)
+static int __0062_init(l_ezlopi_item_t* item)
{
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
- {
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
- }
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
- s_mq7_value_t *MQ7_value = (s_mq7_value_t *)item->user_arg;
- if (false == MQ7_value->Calibration_complete_CO)
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ { // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
{
- xTaskCreate(__calibrate_MQ7_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
}
- ret = 1;
}
- if (0 == ret)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- ret = -1;
- if (item->user_arg)
+ s_mq7_value_t* MQ7_value = (s_mq7_value_t*)item->user_arg;
+ if (MQ7_value)
+ {
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ { // calibrate if not done
+ if (false == MQ7_value->Calibration_complete_CO)
+ {
+ xTaskCreate(__calibrate_MQ7_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
{
- free(item->user_arg);
- item->user_arg = NULL;
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
}
}
}
@@ -194,7 +213,7 @@ static int __0062_init(l_ezlopi_item_t *item)
}
//------------------------------------------------------------------------------------------------------
-static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -207,7 +226,7 @@ static void __prepare_device_digi_cloud_properties(l_ezlopi_device_t *device, cJ
device->cloud_properties.info = NULL;
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device)
+static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -218,11 +237,11 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ7-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
}
//------------------------------------------------------------------------------------------------------
-static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
+static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
@@ -235,7 +254,7 @@ static void __prepare_device_adc_cloud_properties(l_ezlopi_device_t *device, cJS
device->cloud_properties.info = NULL;
device->cloud_properties.device_type_id = NULL;
}
-static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_device, void *user_data)
+static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_data)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -255,23 +274,23 @@ static void __prepare_item_adc_cloud_properties(l_ezlopi_item_t *item, cJSON *cj
}
//------------------------------------------------------------------------------------------------------
-static int __0062_get_item(l_ezlopi_item_t *item, void *arg)
+static int __0062_get_item(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
if (item && arg)
{
- cJSON *cj_result = (cJSON *)arg;
+ cJSON* cj_result = (cJSON*)arg;
if (cj_result)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
//------------------- POSSIBLE JSON ENUM CONTENTS ----------------------------------
- cJSON *json_array_enum = cJSON_CreateArray();
+ cJSON* json_array_enum = cJSON_CreateArray();
if (NULL != json_array_enum)
{
for (uint8_t i = 0; i < MQ7_GAS_ALARM_MAX; i++)
{
- cJSON *json_value = cJSON_CreateString(mq7_sensor_gas_alarm_token[i]);
+ cJSON* json_value = cJSON_CreateString(mq7_sensor_gas_alarm_token[i]);
if (NULL != json_value)
{
cJSON_AddItemToArray(json_array_enum, json_value);
@@ -280,16 +299,22 @@ static int __0062_get_item(l_ezlopi_item_t *item, void *arg)
cJSON_AddItemToObject(cj_result, ezlopi_enum_str, json_array_enum);
}
//--------------------------------------------------------------------------------------
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char*)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char*)item->user_arg ? item->user_arg : "no_gas");
}
if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- s_mq7_value_t *MQ7_value = ((s_mq7_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ7_value->_CO_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ7_value->_CO_ppm);
- free(valueFormatted);
+ s_mq7_value_t* MQ7_value = ((s_mq7_value_t*)item->user_arg);
+ if (MQ7_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ7_value->_CO_ppm);
+ char* valueFormatted = ezlopi_valueformatter_float(MQ7_value->_CO_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -297,26 +322,32 @@ static int __0062_get_item(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __0062_get_cjson_value(l_ezlopi_item_t *item, void *arg)
+static int __0062_get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;
if (item && arg)
{
- cJSON *cj_result = (cJSON *)arg;
+ cJSON* cj_result = (cJSON*)arg;
if (cj_result)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
- cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char*)item->user_arg ? item->user_arg : "no_gas");
+ cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char*)item->user_arg ? item->user_arg : "no_gas");
}
if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- s_mq7_value_t *MQ7_value = ((s_mq7_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ7_value->_CO_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ7_value->_CO_ppm);
- free(valueFormatted);
+ s_mq7_value_t* MQ7_value = ((s_mq7_value_t*)item->user_arg);
+ if (MQ7_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ7_value->_CO_ppm);
+ char* valueFormatted = ezlopi_valueformatter_float(MQ7_value->_CO_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -324,14 +355,14 @@ static int __0062_get_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}
-static int __0062_notify(l_ezlopi_item_t *item)
+static int __0062_notify(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- const char *curret_value = NULL;
+ const char* curret_value = NULL;
if (0 == gpio_get_level(item->interface.gpio.gpio_in.gpio_num)) // when D0 -> 0V,
{
curret_value = "combustible_gas_detected";
@@ -340,21 +371,24 @@ static int __0062_notify(l_ezlopi_item_t *item)
{
curret_value = "no_gas";
}
- if (curret_value != (char *)item->user_arg) // calls update only if there is change in state
+ if (curret_value != (char*)item->user_arg) // calls update only if there is change in state
{
- item->user_arg = (void *)curret_value;
+ item->user_arg = (void*)curret_value;
ezlopi_device_value_updated_from_device_v3(item);
}
}
if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
// extract the sensor_output_values
- double new_value = (double)__extract_MQ7_sensor_ppm(item);
- s_mq7_value_t *MQ7_value = (s_mq7_value_t *)item->user_arg;
- if (fabs((double)(MQ7_value->_CO_ppm) - new_value) > 0.0001)
+ s_mq7_value_t* MQ7_value = (s_mq7_value_t*)item->user_arg;
+ if ((MQ7_value) && (true == MQ7_value->Calibration_complete_CO))
{
- MQ7_value->_CO_ppm = (float)new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ double new_value = (double)__extract_MQ7_sensor_ppm(item);
+ if (fabs((double)(MQ7_value->_CO_ppm) - new_value) > 0.0001)
+ {
+ MQ7_value->_CO_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
@@ -362,108 +396,114 @@ static int __0062_notify(l_ezlopi_item_t *item)
return ret;
}
//------------------------------------------------------------------------------------------------------
-static float __extract_MQ7_sensor_ppm(l_ezlopi_item_t *item)
+static float __extract_MQ7_sensor_ppm(l_ezlopi_item_t* item)
{
uint32_t mq7_adc_pin = item->interface.adc.gpio_num;
- s_mq7_value_t *MQ7_value = (s_mq7_value_t *)item->user_arg;
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- // extract the mean_sensor_analog_output_voltage
- float analog_sensor_volt = 0;
- for (uint8_t x = 10; x > 0; x--)
- {
- ezlopi_adc_get_adc_data(mq7_adc_pin, &ezlopi_analog_data);
+ s_mq7_value_t* MQ7_value = (s_mq7_value_t*)item->user_arg;
+ if (MQ7_value)
+ { // calculation process
+ //-------------------------------------------------
+ s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+ // extract the mean_sensor_analog_output_voltage
+ float analog_sensor_volt = 0;
+ for (uint8_t x = 10; x > 0; x--)
+ {
+ ezlopi_adc_get_adc_data(mq7_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
+ analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
#else
- analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
+ analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
#endif
- vTaskDelay(1);
- }
- analog_sensor_volt = analog_sensor_volt / 10.0f;
+ vTaskDelay(1);
+ }
+ analog_sensor_volt = analog_sensor_volt / 10.0f;
- //-----------------------------------------------------------------------------------
- // Stage_2 : [from 'sensor_0062_ADC_MQ7_methane_gas_detector.h']
+ //-----------------------------------------------------------------------------------
+ // Stage_2 : [from 'sensor_0062_ADC_MQ7_methane_gas_detector.h']
- // 1. Calculate 'Rs_gas' for the gas detected
- float Rs_gas = (((MQ7_VOLT_RESOLUTION_Vc * mq7_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq7_eqv_RL);
+ // 1. Calculate 'Rs_gas' for the gas detected
+ float Rs_gas = (((MQ7_VOLT_RESOLUTION_Vc * mq7_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq7_eqv_RL);
- // 1.1 Calculate @ 'ratio' during CO presence
- double _ratio = (Rs_gas / ((MQ7_value->MQ7_R0_constant <= 0) ? (1.0f) : (MQ7_value->MQ7_R0_constant))); // avoid dividing by zero??
- if (_ratio <= 0)
- {
- _ratio = 0;
- }
- //-------------------------------------------------
+ // 1.1 Calculate @ 'ratio' during CO presence
+ double _ratio = (Rs_gas / ((MQ7_value->MQ7_R0_constant <= 0) ? (1.0f) : (MQ7_value->MQ7_R0_constant))); // avoid dividing by zero??
+ if (_ratio <= 0)
+ {
+ _ratio = 0;
+ }
+ //-------------------------------------------------
- // 1.2 Calculate _CO_ppm
- float _CO_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq7) / m_slope_mq7); // ---> _CO_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
- if (_CO_ppm < 0)
- {
- _CO_ppm = 0; // No negative values accepted or upper datasheet recomendation.
- }
- TRACE_E("_CO_ppm [CO] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _CO_ppm, (float)_ratio, analog_sensor_volt);
+ // 1.2 Calculate _CO_ppm
+ float _CO_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq7) / m_slope_mq7); // ---> _CO_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
+ if (_CO_ppm < 0)
+ {
+ _CO_ppm = 0; // No negative values accepted or upper datasheet recomendation.
+ }
+ TRACE_E("_CO_ppm [CO] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _CO_ppm, (float)_ratio, analog_sensor_volt);
- //-------------------------------------------------
- return _CO_ppm;
+ //-------------------------------------------------
+ return _CO_ppm;
+ }
+ return 0;
}
-static void __calibrate_MQ7_R0_resistance(void *params)
+static void __calibrate_MQ7_R0_resistance(void* params)
{
- l_ezlopi_item_t *item = (l_ezlopi_item_t *)params;
+ l_ezlopi_item_t* item = (l_ezlopi_item_t*)params;
if (NULL != item)
{
- s_mq7_value_t *MQ7_value = (s_mq7_value_t *)item->user_arg;
-
- uint32_t mq7_adc_pin = item->interface.adc.gpio_num;
- //-------------------------------------------------
- // let the sensor to heat for 20seconds
- for (uint8_t j = 20; j > 0; j--)
+ s_mq7_value_t* MQ7_value = (s_mq7_value_t*)item->user_arg;
+ if (MQ7_value)
{
- TRACE_E("Heating sensor.........time left: %d sec", j);
- vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
- }
- //-------------------------------------------------
- // extract the mean_sensor_analog_output_voltage
- float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- for (uint8_t i = 100; i > 0; i--)
- {
- if (i % 20 == 0)
+ uint32_t mq7_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ // let the sensor to heat for 20seconds
+ for (uint8_t j = 20; j > 0; j--)
{
- TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ TRACE_E("Heating sensor.........time left: %d sec", j);
+ vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
}
- // extract ADC values
- ezlopi_adc_get_adc_data(mq7_adc_pin, &ezlopi_analog_data);
+ //-------------------------------------------------
+ // extract the mean_sensor_analog_output_voltage
+ float _sensor_volt = 0;
+ s_ezlopi_analog_data_t ezlopi_analog_data = { .value = 0, .voltage = 0 };
+ for (uint8_t i = 100; i > 0; i--)
+ {
+ if (i % 20 == 0)
+ {
+ TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ }
+ // extract ADC values
+ ezlopi_adc_get_adc_data(mq7_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
+ _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
#else
- _sensor_volt += (float)(ezlopi_analog_data->voltage);
+ _sensor_volt += (float)(ezlopi_analog_data->voltage);
#endif
- vTaskDelay(1); // 10ms
- }
- _sensor_volt = _sensor_volt / 100.0f;
+ vTaskDelay(1); // 10ms
+ }
+ _sensor_volt = _sensor_volt / 100.0f;
- //-------------------------------------------------
- // Calculate the 'Rs' of heater during clean air [calibration phase]
- // Range -> [2Kohm - 20Kohm]
- float RS_calib = 0; // Define variable for sensor resistance
- RS_calib = ((MQ7_VOLT_RESOLUTION_Vc * mq7_eqv_RL) / (_sensor_volt / 1000.0f)) - mq7_eqv_RL; // Calculate RS in fresh air
- TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
- if (RS_calib < 0)
- {
- RS_calib = 0; // No negative values accepted.
- }
- // Calculate the R0_air which is constant through-out
- MQ7_value->MQ7_R0_constant = (RS_calib / RatioMQ7CleanAir); // Calculate MQ7_R0_constant
- TRACE_E("CALIB_TASK -> 'MQ7_R0_constant' = %.2f", MQ7_value->MQ7_R0_constant);
- if (MQ7_value->MQ7_R0_constant < 0)
- {
- MQ7_value->MQ7_R0_constant = 0; // No negative values accepted.
+ //-------------------------------------------------
+ // Calculate the 'Rs' of heater during clean air [calibration phase]
+ // Range -> [2Kohm - 20Kohm]
+ float RS_calib = 0; // Define variable for sensor resistance
+ RS_calib = ((MQ7_VOLT_RESOLUTION_Vc * mq7_eqv_RL) / (_sensor_volt / 1000.0f)) - mq7_eqv_RL; // Calculate RS in fresh air
+ TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
+ if (RS_calib < 0)
+ {
+ RS_calib = 0; // No negative values accepted.
+ }
+ // Calculate the R0_air which is constant through-out
+ MQ7_value->MQ7_R0_constant = (RS_calib / RatioMQ7CleanAir); // Calculate MQ7_R0_constant
+ TRACE_E("CALIB_TASK -> 'MQ7_R0_constant' = %.2f", MQ7_value->MQ7_R0_constant);
+ if (MQ7_value->MQ7_R0_constant < 0)
+ {
+ MQ7_value->MQ7_R0_constant = 0; // No negative values accepted.
+ }
+ // Set calibration_complete_CO flag
+ MQ7_value->Calibration_complete_CO = true;
}
- // Set calibration_complete_CO flag
- MQ7_value->Calibration_complete_CO = true;
}
+
vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0063-other-MQ9-LPG-flameable-detector/sensor_0063_other_MQ9_LPG_flameable_detector.c b/ezlopi-sensors-devices/sensor-0063-other-MQ9-LPG-flameable-detector/sensor_0063_other_MQ9_LPG_flameable_detector.c
index 9e9ed6a79..f6d85113a 100644
--- a/ezlopi-sensors-devices/sensor-0063-other-MQ9-LPG-flameable-detector/sensor_0063_other_MQ9_LPG_flameable_detector.c
+++ b/ezlopi-sensors-devices/sensor-0063-other-MQ9-LPG-flameable-detector/sensor_0063_other_MQ9_LPG_flameable_detector.c
@@ -73,11 +73,7 @@ int sensor_0063_other_MQ9_LPG_flameable_detector(e_ezlopi_actions_t action, l_ez
}
case EZLOPI_ACTION_NOTIFY_1000_MS:
{
- s_mq9_value_t *MQ9_value = (s_mq9_value_t *)item->user_arg;
- if (true == MQ9_value->Calibration_complete_LPG_flameable)
- {
- __0063_notify(item);
- }
+ __0063_notify(item);
break;
}
default:
@@ -152,37 +148,65 @@ static int __0063_init(l_ezlopi_item_t *item)
int ret = 0;
if (NULL != item)
{
- if ((ezlopi_item_name_gas_alarm == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ if (ezlopi_item_name_gas_alarm == item->cloud_properties.item_name)
{
- // intialize digital_pin
- gpio_config_t input_conf = {};
- input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
- input_conf.intr_type = GPIO_INTR_DISABLE;
- input_conf.mode = GPIO_MODE_INPUT;
- input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&input_conf);
- ret = 1;
+ if (GPIO_IS_VALID_GPIO(item->interface.gpio.gpio_in.gpio_num))
+ {
+ // intialize digital_pin
+ gpio_config_t input_conf = {};
+ input_conf.pin_bit_mask = (1ULL << (item->interface.gpio.gpio_in.gpio_num));
+ input_conf.intr_type = GPIO_INTR_DISABLE;
+ input_conf.mode = GPIO_MODE_INPUT;
+ input_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
+ input_conf.pull_up_en = GPIO_PULLUP_ENABLE;
+ ret = (0 == gpio_config(&input_conf)) ? 1 : -1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- if ((ezlopi_item_name_smoke_density == item->cloud_properties.item_name) && GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
- // initialize analog_pin
- ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit);
- // calibrate if not done
s_mq9_value_t *MQ9_value = (s_mq9_value_t *)item->user_arg;
- if (false == MQ9_value->Calibration_complete_LPG_flameable)
+ if (MQ9_value)
{
- xTaskCreate(__calibrate_MQ9_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ if (GPIO_IS_VALID_GPIO(item->interface.adc.gpio_num))
+ { // initialize analog_pin
+ if (0 == ezlopi_adc_init(item->interface.adc.gpio_num, item->interface.adc.resln_bit))
+ {
+ // calibrate if not done
+ if (false == MQ9_value->Calibration_complete_LPG_flameable)
+ {
+ xTaskCreate(__calibrate_MQ9_R0_resistance, "Task_to_calculate_R0_air", 2048, item, 1, NULL);
+ }
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
+ }
+ else
+ {
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ free(item->user_arg);
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item); // remove the item itself
+ }
}
- ret = 1;
- }
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
+ else
{
- free(item->user_arg);
- item->user_arg = NULL;
+ ret = -1;
+ TRACE_E("Deleting Item!!");
+ ezlopi_device_free_device_by_item(item); // remove the item itself;
}
}
}
@@ -214,7 +238,7 @@ static void __prepare_item_digi_cloud_properties(l_ezlopi_item_t *item, cJSON *c
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio1_str, item->interface.gpio.gpio_in.gpio_num);
TRACE_S("MQ9-> DIGITAL_PIN: %d ", item->interface.gpio.gpio_in.gpio_num);
char *user_arg = (char *)malloc(40);
if (user_arg)
@@ -285,13 +309,19 @@ static int __0063_get_item(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq9_value_t *MQ9_value = ((s_mq9_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ9_value->_LPG_flameable_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ9_value->_LPG_flameable_ppm);
- free(valueFormatted);
+ if (MQ9_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ9_value->_LPG_flameable_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ9_value->_LPG_flameable_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -312,13 +342,19 @@ static int __0063_get_cjson_value(l_ezlopi_item_t *item, void *arg)
cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, (char *)item->user_arg ? item->user_arg : "no_gas");
cJSON_AddStringToObject(cj_result, ezlopi_value_str, (char *)item->user_arg ? item->user_arg : "no_gas");
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
s_mq9_value_t *MQ9_value = ((s_mq9_value_t *)item->user_arg);
- char *valueFormatted = ezlopi_valueformatter_float(MQ9_value->_LPG_flameable_ppm);
- cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
- cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ9_value->_LPG_flameable_ppm);
- free(valueFormatted);
+ if (MQ9_value)
+ {
+ cJSON_AddNumberToObject(cj_result, ezlopi_value_str, MQ9_value->_LPG_flameable_ppm);
+ char *valueFormatted = ezlopi_valueformatter_float(MQ9_value->_LPG_flameable_ppm);
+ if (valueFormatted)
+ {
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, valueFormatted);
+ free(valueFormatted);
+ }
+ }
}
ret = 1;
}
@@ -349,15 +385,18 @@ static int __0063_notify(l_ezlopi_item_t *item)
ezlopi_device_value_updated_from_device_v3(item);
}
}
- if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
+ else if (ezlopi_item_name_smoke_density == item->cloud_properties.item_name)
{
// extract the sensor_output_values
- double new_value = (double)__extract_MQ9_sensor_ppm(item);
s_mq9_value_t *MQ9_value = (s_mq9_value_t *)item->user_arg;
- if (fabs((double)(MQ9_value->_LPG_flameable_ppm) - new_value) > 0.0001)
+ if ((MQ9_value) && (true == MQ9_value->Calibration_complete_LPG_flameable))
{
- MQ9_value->_LPG_flameable_ppm = (float)new_value;
- ezlopi_device_value_updated_from_device_v3(item);
+ double new_value = (double)__extract_MQ9_sensor_ppm(item);
+ if (fabs((double)(MQ9_value->_LPG_flameable_ppm) - new_value) > 0.0001)
+ {
+ MQ9_value->_LPG_flameable_ppm = (float)new_value;
+ ezlopi_device_value_updated_from_device_v3(item);
+ }
}
}
ret = 1;
@@ -367,49 +406,52 @@ static int __0063_notify(l_ezlopi_item_t *item)
//------------------------------------------------------------------------------------------------------
static float __extract_MQ9_sensor_ppm(l_ezlopi_item_t *item)
{
- uint32_t mq9_adc_pin = item->interface.adc.gpio_num;
s_mq9_value_t *MQ9_value = (s_mq9_value_t *)item->user_arg;
- // calculation process
- //-------------------------------------------------
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- // extract the mean_sensor_analog_output_voltage
- float analog_sensor_volt = 0;
- for (uint8_t x = 10; x > 0; x--)
- {
- ezlopi_adc_get_adc_data(mq9_adc_pin, &ezlopi_analog_data);
+ if (MQ9_value)
+ { // calculation process
+ //-------------------------------------------------
+ uint32_t mq9_adc_pin = item->interface.adc.gpio_num;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ // extract the mean_sensor_analog_output_voltage
+ float analog_sensor_volt = 0;
+ for (uint8_t x = 10; x > 0; x--)
+ {
+ ezlopi_adc_get_adc_data(mq9_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
+ analog_sensor_volt += ((float)(ezlopi_analog_data.voltage) * 2.0f);
#else
- analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
+ analog_sensor_volt += (float)(ezlopi_analog_data.voltage);
#endif
- vTaskDelay(1);
- }
- analog_sensor_volt = analog_sensor_volt / 10.0f;
+ vTaskDelay(1);
+ }
+ analog_sensor_volt = analog_sensor_volt / 10.0f;
- //-----------------------------------------------------------------------------------
- // Stage_2 : [from 'sensor_0063_ADC_MQ9_methane_gas_detector.h']
+ //-----------------------------------------------------------------------------------
+ // Stage_2 : [from 'sensor_0063_ADC_MQ9_methane_gas_detector.h']
- // 1. Calculate 'Rs_gas' for the gas detected
- float Rs_gas = (((MQ9_VOLT_RESOLUTION_Vc * mq9_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq9_eqv_RL);
+ // 1. Calculate 'Rs_gas' for the gas detected
+ float Rs_gas = (((MQ9_VOLT_RESOLUTION_Vc * mq9_eqv_RL) / (analog_sensor_volt / 1000.0f)) - mq9_eqv_RL);
- // 1.1 Calculate @ 'ratio' during LPG_flameable presence
- double _ratio = (Rs_gas / ((MQ9_value->MQ9_R0_constant <= 0) ? (1.0f) : (MQ9_value->MQ9_R0_constant))); // avoid dividing by zero??
- if (_ratio <= 0)
- {
- _ratio = 0;
- }
- //-------------------------------------------------
+ // 1.1 Calculate @ 'ratio' during LPG_flameable presence
+ double _ratio = (Rs_gas / ((MQ9_value->MQ9_R0_constant <= 0) ? (1.0f) : (MQ9_value->MQ9_R0_constant))); // avoid dividing by zero??
+ if (_ratio <= 0)
+ {
+ _ratio = 0;
+ }
+ //-------------------------------------------------
- // 1.2 Calculate _LPG_flameable_ppm
- float _LPG_flameable_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq9) / m_slope_mq9); // ---> _LPG_flameable_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
- if (_LPG_flameable_ppm < 0)
- {
- _LPG_flameable_ppm = 0; // No negative values accepted or upper datasheet recomendation.
- }
- TRACE_E("_LPG_flameable_ppm [LPG_flameable] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _LPG_flameable_ppm, (float)_ratio, analog_sensor_volt);
+ // 1.2 Calculate _LPG_flameable_ppm
+ float _LPG_flameable_ppm = (float)pow(10, (((float)log10(_ratio)) - b_coeff_mq9) / m_slope_mq9); // ---> _LPG_flameable_ppm = 10 ^ [ ( log(ratio) - b ) / m ]
+ if (_LPG_flameable_ppm < 0)
+ {
+ _LPG_flameable_ppm = 0; // No negative values accepted or upper datasheet recomendation.
+ }
+ TRACE_E("_LPG_flameable_ppm [LPG_flameable] : %.2f -> ratio[RS/R0] : %.2f -> Volts : %0.2fmv", _LPG_flameable_ppm, (float)_ratio, analog_sensor_volt);
- //-------------------------------------------------
- return _LPG_flameable_ppm;
+ //-------------------------------------------------
+ return _LPG_flameable_ppm;
+ }
+ return 0;
}
static void __calibrate_MQ9_R0_resistance(void *params)
@@ -418,55 +460,57 @@ static void __calibrate_MQ9_R0_resistance(void *params)
if (NULL != item)
{
s_mq9_value_t *MQ9_value = (s_mq9_value_t *)item->user_arg;
-
- uint32_t mq9_adc_pin = item->interface.adc.gpio_num;
- //-------------------------------------------------
- // let the sensor to heat for 20seconds
- for (uint8_t j = 20; j > 0; j--)
+ if (MQ9_value)
{
- TRACE_E("Heating sensor.........time left: %d sec", j);
- vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
- }
- //-------------------------------------------------
- // extract the mean_sensor_analog_output_voltage
- float _sensor_volt = 0;
- s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
- for (uint8_t i = 100; i > 0; i--)
- {
- if (i % 20 == 0)
+ uint32_t mq9_adc_pin = item->interface.adc.gpio_num;
+ //-------------------------------------------------
+ // let the sensor to heat for 20seconds
+ for (uint8_t j = 20; j > 0; j--)
{
- TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ TRACE_E("Heating sensor.........time left: %d sec", j);
+ vTaskDelay(100); // vTaskDelay(1000 / portTICK_PERIOD_MS); // 1sec delay before calibration
}
- // extract ADC values
- ezlopi_adc_get_adc_data(mq9_adc_pin, &ezlopi_analog_data);
+ //-------------------------------------------------
+ // extract the mean_sensor_analog_output_voltage
+ float _sensor_volt = 0;
+ s_ezlopi_analog_data_t ezlopi_analog_data = {.value = 0, .voltage = 0};
+ for (uint8_t i = 100; i > 0; i--)
+ {
+ if (i % 20 == 0)
+ {
+ TRACE_W("Please Wait..Collecting Ambient Air data ........... [Avoid Smokes/gases]");
+ }
+ // extract ADC values
+ ezlopi_adc_get_adc_data(mq9_adc_pin, &ezlopi_analog_data);
#ifdef VOLTAGE_DIVIDER_ADDED
- _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
+ _sensor_volt += (float)((ezlopi_analog_data.voltage) * 2.0f); // [0-2.4V] X2
#else
- _sensor_volt += (float)(ezlopi_analog_data->voltage);
+ _sensor_volt += (float)(ezlopi_analog_data->voltage);
#endif
- vTaskDelay(1); // 10ms
- }
- _sensor_volt = _sensor_volt / 100.0f;
+ vTaskDelay(1); // 10ms
+ }
+ _sensor_volt = _sensor_volt / 100.0f;
- //-------------------------------------------------
- // Calculate the 'Rs' of heater during clean air [calibration phase]
- // Range -> [2Kohm - 20Kohm]
- float RS_calib = 0; // Define variable for sensor resistance
- RS_calib = ((MQ9_VOLT_RESOLUTION_Vc * mq9_eqv_RL) / (_sensor_volt / 1000.0f)) - mq9_eqv_RL; // Calculate RS in fresh air
- TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
- if (RS_calib < 0)
- {
- RS_calib = 0; // No negative values accepted.
- }
- // Calculate the R0_air which is constant through-out
- MQ9_value->MQ9_R0_constant = (RS_calib / RatioMQ9CleanAir); // Calculate MQ9_R0_constant
- TRACE_E("CALIB_TASK -> 'MQ9_R0_constant' = %.2f", MQ9_value->MQ9_R0_constant);
- if (MQ9_value->MQ9_R0_constant < 0)
- {
- MQ9_value->MQ9_R0_constant = 0; // No negative values accepted.
+ //-------------------------------------------------
+ // Calculate the 'Rs' of heater during clean air [calibration phase]
+ // Range -> [2Kohm - 20Kohm]
+ float RS_calib = 0; // Define variable for sensor resistance
+ RS_calib = ((MQ9_VOLT_RESOLUTION_Vc * mq9_eqv_RL) / (_sensor_volt / 1000.0f)) - mq9_eqv_RL; // Calculate RS in fresh air
+ TRACE_E("CALIB_TASK -> 'RS_calib' = %.2f", RS_calib);
+ if (RS_calib < 0)
+ {
+ RS_calib = 0; // No negative values accepted.
+ }
+ // Calculate the R0_air which is constant through-out
+ MQ9_value->MQ9_R0_constant = (RS_calib / RatioMQ9CleanAir); // Calculate MQ9_R0_constant
+ TRACE_E("CALIB_TASK -> 'MQ9_R0_constant' = %.2f", MQ9_value->MQ9_R0_constant);
+ if (MQ9_value->MQ9_R0_constant < 0)
+ {
+ MQ9_value->MQ9_R0_constant = 0; // No negative values accepted.
+ }
+ // Set calibration_complete_LPG_flameable flag
+ MQ9_value->Calibration_complete_LPG_flameable = true;
}
- // Set calibration_complete_LPG_flameable flag
- MQ9_value->Calibration_complete_LPG_flameable = true;
}
vTaskDelete(NULL);
}
\ No newline at end of file
diff --git a/ezlopi-sensors-devices/sensor-0065-digitalIn-float-switch/sensor_0065_digitalIn_float_switch.c b/ezlopi-sensors-devices/sensor-0065-digitalIn-float-switch/sensor_0065_digitalIn_float_switch.c
index 0f36241c0..b9be1662f 100644
--- a/ezlopi-sensors-devices/sensor-0065-digitalIn-float-switch/sensor_0065_digitalIn_float_switch.c
+++ b/ezlopi-sensors-devices/sensor-0065-digitalIn-float-switch/sensor_0065_digitalIn_float_switch.c
@@ -90,7 +90,7 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_dev
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type); // _max = 10
- CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
+ CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cj_device, "logic_inv", item->interface.gpio.gpio_in.invert);
item->interface.gpio.gpio_in.enable = true;
@@ -161,17 +161,14 @@ static int __0065_init(l_ezlopi_item_t *item)
else
{
ret = -1;
+ ezlopi_device_free_device_by_item(item);
TRACE_E("Error initializing float switch");
}
}
- if (0 == ret)
+ else
{
ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
diff --git a/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/CMakeLists.txt b/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/CMakeLists.txt
index e79d01160..3cd30a5b1 100644
--- a/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/CMakeLists.txt
+++ b/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/CMakeLists.txt
@@ -5,6 +5,7 @@ idf_component_register(SRCS "sensor_0066_other_R307_FingerPrint.c" "R307_AS606.c
driver
freertos
esp_timer
+
ezlopi-core-timer
ezlopi-core-cloud
ezlopi-core-actions
diff --git a/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/sensor_0066_other_R307_FingerPrint.c b/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/sensor_0066_other_R307_FingerPrint.c
index 41f34b114..14d1d9177 100644
--- a/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/sensor_0066_other_R307_FingerPrint.c
+++ b/ezlopi-sensors-devices/sensor-0066-other-R307-FingerPrint/sensor_0066_other_R307_FingerPrint.c
@@ -52,25 +52,28 @@ static void __timer_callback(void *param)
if (item)
{
server_packet_t *user_data = (server_packet_t *)item->user_arg;
- time_t now = 0;
- time(&now);
- if ((now - (user_data->timeout_start_time)) <= (time_t)30) // 30 sec
+ if (user_data)
{
- TRACE_W("...timer ON...");
- if (user_data->opmode != FINGERPRINT_ENROLLMENT_MODE)
+ time_t now = 0;
+ time(&now);
+ if ((now - (user_data->timeout_start_time)) <= (time_t)30) // 30 sec
{
- TRACE_E("...timer OFF...");
+ TRACE_W("...timer ON...");
+ if (user_data->opmode != FINGERPRINT_ENROLLMENT_MODE)
+ {
+ TRACE_E("...timer OFF...");
+ user_data->opmode = FINGERPRINT_MATCH_MODE;
+ esp_timer_stop(user_data->timerHandler);
+ }
+ }
+ else
+ {
+ TRACE_S("...timer OFF...");
user_data->opmode = FINGERPRINT_MATCH_MODE;
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL]);
esp_timer_stop(user_data->timerHandler);
}
}
- else
- {
- TRACE_S("...timer OFF...");
- user_data->opmode = FINGERPRINT_MATCH_MODE;
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL]);
- esp_timer_stop(user_data->timerHandler);
- }
}
}
@@ -101,7 +104,7 @@ int sensor_0066_other_R307_FingerPrint(e_ezlopi_actions_t action, l_ezlopi_item_
if (item)
{
server_packet_t *user_data = (server_packet_t *)item->user_arg;
- if (false == user_data->notify_flag)
+ if ((user_data) && (false == user_data->notify_flag))
{
user_data->notify_flag = true;
ret = __0066_get_value_cjson(item, arg);
@@ -114,7 +117,9 @@ int sensor_0066_other_R307_FingerPrint(e_ezlopi_actions_t action, l_ezlopi_item_
if (item)
{
server_packet_t *user_data = (server_packet_t *)item->user_arg;
- if (((false == user_data->notify_flag)) && (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL] == item->cloud_properties.item_id)) // enroll
+ if ((user_data) &&
+ (false == user_data->notify_flag) &&
+ (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL] == item->cloud_properties.item_id)) // enroll
{
user_data->notify_flag = true;
}
@@ -187,9 +192,9 @@ static void __prepare_item_interface_properties(l_ezlopi_item_t *item, cJSON *cj
server_packet_t *user_data = (server_packet_t *)item->user_arg;
if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL] == item->cloud_properties.item_id) // while initialization; setup only once (during Match item setup)
{
- CJSON_GET_VALUE_INT(cj_device, "gpio1", item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_device, "gpio2", item->interface.uart.rx);
- CJSON_GET_VALUE_INT(cj_device, "gpio3", user_data->intr_pin);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio1_str, item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio2_str, item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio3_str, user_data->intr_pin);
item->interface.uart.baudrate = FINGERPRINT_UART_BAUDRATE;
item->interface.uart.enable = true;
}
@@ -263,78 +268,83 @@ static int __0066_prepare(void *arg)
static int __0066_init(l_ezlopi_item_t *item)
{
int ret = 0;
- if (NULL != item)
+ if ((NULL != item))
{
server_packet_t *user_data = (server_packet_t *)item->user_arg;
- if ((true == (item->interface.uart.enable)) && GPIO_IS_VALID_GPIO((gpio_num_t)user_data->intr_pin) && GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.uart.tx) && GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.uart.rx))
+ if (user_data)
{
- gpio_num_t intr_pin = user_data->intr_pin;
- // #warning "Riken needs to fix this warning, compile and check about the warning details !"
- s_ezlopi_uart_object_handle_t ezlopi_uart_object_handle = ezlopi_uart_init(item->interface.uart.baudrate, item->interface.uart.tx, item->interface.uart.rx, __uart_0066_fingerprint_upcall, item);
- item->interface.uart.channel = ezlopi_uart_get_channel(ezlopi_uart_object_handle);
-
- const gpio_config_t FingerPrint_intr_gpio_config = {
- .pin_bit_mask = (1ULL << (intr_pin)),
- .intr_type = GPIO_INTR_NEGEDGE,
- .mode = GPIO_MODE_INPUT,
- .pull_up_en = GPIO_PULLUP_DISABLE,
- .pull_down_en = GPIO_PULLDOWN_DISABLE,
- };
-
- if (0 == gpio_config(&FingerPrint_intr_gpio_config))
+ if (GPIO_IS_VALID_GPIO((gpio_num_t)user_data->intr_pin) && GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.uart.tx) && GPIO_IS_VALID_GPIO((gpio_num_t)item->interface.uart.rx))
{
- if (FINGERPRINT_OK == r307_as606_fingerprint_config(item))
+ if (true == item->interface.uart.enable)
{
- if (0 == gpio_isr_handler_add(intr_pin, gpio_notify_isr, item))
+ gpio_num_t intr_pin = user_data->intr_pin;
+ // #warning "Riken needs to fix this warning, compile and check about the warning details !"
+ s_ezlopi_uart_object_handle_t ezlopi_uart_object_handle = ezlopi_uart_init(item->interface.uart.baudrate, item->interface.uart.tx, item->interface.uart.rx, __uart_0066_fingerprint_upcall, item);
+ item->interface.uart.channel = ezlopi_uart_get_channel(ezlopi_uart_object_handle);
+
+ const gpio_config_t FingerPrint_intr_gpio_config = {
+ .pin_bit_mask = (1ULL << (intr_pin)),
+ .intr_type = GPIO_INTR_NEGEDGE,
+ .mode = GPIO_MODE_INPUT,
+ .pull_up_en = GPIO_PULLUP_DISABLE,
+ .pull_down_en = GPIO_PULLDOWN_DISABLE,
+ };
+ ret = 1;
+ if (0 == gpio_config(&FingerPrint_intr_gpio_config))
{
- if (NULL == (user_data->notifyHandler))
+ if (FINGERPRINT_OK == r307_as606_fingerprint_config(item))
{
- TRACE_S(" ---->>> Creating Fingerprint_activation Task <<<----");
- xTaskCreate(__fingerprint_operation_task, "Fingerprint_activation", 2048 * 2, item, 1, &(user_data->notifyHandler));
- }
+ if (0 == gpio_isr_handler_add(intr_pin, gpio_notify_isr, item))
+ {
+ if (NULL == (user_data->notifyHandler))
+ {
+ TRACE_I(" ---->>> Creating Fingerprint_activation Task <<<----");
+ xTaskCreate(__fingerprint_operation_task, "Fingerprint_activation", 2048 * 2, item, 1, &(user_data->notifyHandler));
+ }
- const esp_timer_create_args_t esp_timer_create_args = {
- .callback = __timer_callback,
- .arg = (void *)item,
- .name = "Enrollment timer"};
- if (0 == esp_timer_create(&esp_timer_create_args, &(user_data->timerHandler)))
+ const esp_timer_create_args_t esp_timer_create_args = {
+ .callback = __timer_callback,
+ .arg = (void *)item,
+ .name = "Enrollment timer"};
+ if (0 == esp_timer_create(&esp_timer_create_args, &(user_data->timerHandler)))
+ {
+ TRACE_I(" ---->>> Creating Enrollment Timer <<<----");
+ }
+ }
+ else
+ {
+ ret = -1;
+ gpio_isr_handler_remove(intr_pin);
+ TRACE_E("Error!! : Failed to add GPIO ISR handler.");
+ }
+ }
+ else
{
- TRACE_S(" ---->>> Creating Enrollment Timer <<<----");
+ ret = -1;
+ TRACE_E("Need to Reconfigure : Fingerprint sensor ..... Please, Reset ESP32.");
}
- ret = 1;
}
else
{
ret = -1;
- TRACE_E("Error!! : Failed to add GPIO ISR handler.");
- gpio_isr_handler_remove(intr_pin);
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ TRACE_E("Error!! : Problem is 'GPIO_intr_pin' Config......");
}
}
- else
- {
- ret = -1;
- TRACE_E("Need to Reconfigure : Fingerprint sensor ..... Please, Reset ESP32.");
- }
}
else
{
ret = -1;
- TRACE_E("Error!! : Problem is 'GPIO_intr_pin' Config......");
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
}
}
else
{
ret = -1;
- }
-
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
@@ -347,34 +357,34 @@ static int __0066_get_value_cjson(l_ezlopi_item_t *item, void *arg)
if (cj_result && item)
{
server_packet_t *user_data = (server_packet_t *)item->user_arg;
- if (user_data->notify_flag)
+ if ((user_data) && (user_data->notify_flag))
{
if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ACTION] == item->cloud_properties.item_id) // match
{
cJSON *cj_value = cJSON_CreateObject();
cJSON_AddNumberToObject(cj_value, "id", user_data->matched_id);
cJSON_AddNumberToObject(cj_value, "confidence_level", user_data->matched_confidence_level);
- cJSON_AddItemToObject(cj_result, "value", cj_value);
- cJSON_AddStringToObject(cj_result, "valueFormatted", "");
+ cJSON_AddItemToObject(cj_result, ezlopi_value_str, cj_value);
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, "");
}
if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL] == item->cloud_properties.item_id) // enroll
{
TRACE_E("(get_cjson) op_mode : %d", user_data->opmode);
if (user_data->opmode != FINGERPRINT_ENROLLMENT_MODE)
{
- cJSON_AddFalseToObject(cj_result, "value");
- cJSON_AddStringToObject(cj_result, "valueFormatted", "false");
+ cJSON_AddFalseToObject(cj_result, ezlopi_value_str);
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, "false");
}
else
{
- cJSON_AddTrueToObject(cj_result, "value");
- cJSON_AddStringToObject(cj_result, "valueFormatted", "true");
+ cJSON_AddTrueToObject(cj_result, ezlopi_value_str);
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, "true");
}
}
if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS] == item->cloud_properties.item_id) // erase or list
{
cJSON_AddStringToObject(cj_result, "elementType", "int");
- cJSON *cj_value_array = cJSON_AddArrayToObject(cj_result, "value");
+ cJSON *cj_value_array = cJSON_AddArrayToObject(cj_result, ezlopi_value_str);
for (int idx = 1; idx <= FINGERPRINT_MAX_CAPACITY_LIMIT; idx++)
{
@@ -383,7 +393,7 @@ static int __0066_get_value_cjson(l_ezlopi_item_t *item, void *arg)
cJSON_AddItemToArray(cj_value_array, cJSON_CreateNumber(idx));
}
}
- cJSON_AddStringToObject(cj_result, "valueFormatted", "");
+ cJSON_AddStringToObject(cj_result, ezlopi_valueFormatted_str, "");
}
user_data->notify_flag = false;
}
@@ -399,68 +409,71 @@ static int __0066_set_value(l_ezlopi_item_t *item, void *arg)
if ((NULL != cjson_params) && (NULL != item))
{
server_packet_t *user_data = (server_packet_t *)item->user_arg;
- if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL] == item->cloud_properties.item_id) // Set conditon trigger enroll mode
+ if (user_data)
{
- cJSON *cj_value_cmd = cJSON_GetObjectItem(cjson_params, "value");
- if (cj_value_cmd)
+ if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL] == item->cloud_properties.item_id) // Set conditon trigger enroll mode
{
- TRACE_E("HERE!! enroll");
- if (cJSON_IsTrue(cj_value_cmd)) // true conditon
+ cJSON *cj_value_cmd = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
+ if (cj_value_cmd)
{
- time(&user_data->timeout_start_time); // !< reset the internal timer_start_time
- user_data->opmode = FINGERPRINT_ENROLLMENT_MODE;
-
- /* Start the timers */
- esp_err_t _tm_state = esp_timer_start_periodic(user_data->timerHandler, 1000000);
- if (0 != _tm_state) // ESP_ERR_INVALID_STATE
+ TRACE_E("HERE!! enroll");
+ if (cJSON_IsTrue(cj_value_cmd)) // true conditon
{
- TRACE_W("Restarting timer...");
- esp_timer_stop(user_data->timerHandler);
- esp_timer_start_periodic(user_data->timerHandler, 1000000);
+ time(&user_data->timeout_start_time); // !< reset the internal timer_start_time
+ user_data->opmode = FINGERPRINT_ENROLLMENT_MODE;
+
+ /* Start the timers */
+ esp_err_t _tm_state = esp_timer_start_periodic(user_data->timerHandler, 1000000);
+ if (0 != _tm_state) // ESP_ERR_INVALID_STATE
+ {
+ TRACE_W("Restarting timer...");
+ esp_timer_stop(user_data->timerHandler);
+ esp_timer_start_periodic(user_data->timerHandler, 1000000);
+ }
+ else
+ {
+ TRACE_W("Starting timer...");
+ }
}
else
{
- TRACE_W("Starting timer...");
+ user_data->opmode = FINGERPRINT_MATCH_MODE;
}
}
- else
- {
- user_data->opmode = FINGERPRINT_MATCH_MODE;
- }
}
- }
- else if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS] == item->cloud_properties.item_id) // Set condition erase IDs
- {
- cJSON *cj_value_ids = cJSON_GetObjectItem(cjson_params, "value");
- if ((cj_value_ids != NULL) && cJSON_IsArray(cj_value_ids))
+ else if (user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS] == item->cloud_properties.item_id) // Set condition erase IDs
{
- time(&user_data->timeout_start_time); // !< reset the internal timer_start_time
- uint16_t value_array_size = cJSON_GetArraySize(cj_value_ids);
- if (value_array_size > 0)
+ cJSON *cj_value_ids = cJSON_GetObjectItem(cjson_params, ezlopi_value_str);
+ if ((cj_value_ids != NULL) && cJSON_IsArray(cj_value_ids))
{
- TRACE_W("HERE!! erase specific");
- for (uint16_t i = 0; i < value_array_size; i++) // eg. first protect => [2,4,5]
+ time(&user_data->timeout_start_time); // !< reset the internal timer_start_time
+ uint16_t value_array_size = cJSON_GetArraySize(cj_value_ids);
+ if (value_array_size > 0)
{
- cJSON *fp_id = cJSON_GetArrayItem(cj_value_ids, i);
- TRACE_S("Protected ID:[#%d]", (fp_id->valueint));
- user_data->protect[fp_id->valueint] = true; // eg. protect this ID -> 2/4/5
- }
+ TRACE_W("HERE!! erase specific");
+ for (uint16_t i = 0; i < value_array_size; i++) // eg. first protect => [2,4,5]
+ {
+ cJSON *fp_id = cJSON_GetArrayItem(cj_value_ids, i);
+ TRACE_S("Protected ID:[#%d]", (fp_id->valueint));
+ user_data->protect[fp_id->valueint] = true; // eg. protect this ID -> 2/4/5
+ }
- user_data->opmode = FINGERPRINT_ERASE_WITH_IDS_MODE;
- if (false == (user_data->__busy_guard))
- {
- user_data->__busy_guard = true;
- xTaskNotifyGive(user_data->notifyHandler); // activate the task
+ user_data->opmode = FINGERPRINT_ERASE_WITH_IDS_MODE;
+ if (false == (user_data->__busy_guard))
+ {
+ user_data->__busy_guard = true;
+ xTaskNotifyGive(user_data->notifyHandler); // activate the task
+ }
}
- }
- else
- {
- TRACE_W("HERE!! erase all");
- user_data->opmode = FINGERPRINT_ERASE_ALL_MODE;
- if (false == (user_data->__busy_guard))
+ else
{
- user_data->__busy_guard = true;
- xTaskNotifyGive(user_data->notifyHandler); // activate the task
+ TRACE_W("HERE!! erase all");
+ user_data->opmode = FINGERPRINT_ERASE_ALL_MODE;
+ if (false == (user_data->__busy_guard))
+ {
+ user_data->__busy_guard = true;
+ xTaskNotifyGive(user_data->notifyHandler); // activate the task
+ }
}
}
}
@@ -476,7 +489,6 @@ static void __uart_0066_fingerprint_upcall(uint8_t *buffer, uint32_t output_len,
if (NULL != temp_buf)
{
memset(temp_buf, 0, 256);
-
if ((NULL != buffer) && (output_len) && (uart_object_handle->arg))
{
memcpy(temp_buf, buffer, 256);
@@ -484,85 +496,87 @@ static void __uart_0066_fingerprint_upcall(uint8_t *buffer, uint32_t output_len,
l_ezlopi_item_t *item = (l_ezlopi_item_t *)uart_object_handle->arg;
server_packet_t *user_data = (server_packet_t *)item->user_arg;
-
- uint16_t package_len = 0;
- uint8_t another_buffer[MAX_PACKET_LENGTH_VAL] = {0};
- memcpy(another_buffer, temp_buf, MAX_PACKET_LENGTH_VAL);
- // Programmed only for ACK_operation [0x07h] with 256byte results.
- if (another_buffer[6] == FINGERPRINT_PID_ACKPACKET)
+ if (user_data)
{
- // Check the Header+Addr bytes and Then copy PID,package_len,confirmation_code and checksum to -> recieved_packet buffer
- uint8_t idx = 0;
- bool __err_message = false;
-
- while ((!__err_message) && (idx < 9))
+ uint16_t package_len = 0;
+ uint8_t another_buffer[MAX_PACKET_LENGTH_VAL] = {0};
+ memcpy(another_buffer, temp_buf, MAX_PACKET_LENGTH_VAL);
+ // Programmed only for ACK_operation [0x07h] with 256byte results.
+ if (another_buffer[6] == FINGERPRINT_PID_ACKPACKET)
{
- switch (idx)
- {
- case 0: // header -> ACK = 0xEFh
+ // Check the Header+Addr bytes and Then copy PID,package_len,confirmation_code and checksum to -> recieved_packet buffer
+ uint8_t idx = 0;
+ bool __err_message = false;
+
+ while ((!__err_message) && (idx < 9))
{
- if (FINGERPRINT_HEADER_MSB != (another_buffer[idx]))
+ switch (idx)
{
- TRACE_E("Header code mismatch....");
- __err_message = true;
- }
+ case 0: // header -> ACK = 0xEFh
+ {
+ if (FINGERPRINT_HEADER_MSB != (another_buffer[idx]))
+ {
+ TRACE_E("Header code mismatch....");
+ __err_message = true;
+ }
- break;
- }
- case 1: // header -> ACK = 0x01h
- {
- if (FINGERPRINT_HEADER_LSB != (another_buffer[idx]))
+ break;
+ }
+ case 1: // header -> ACK = 0x01h
{
- TRACE_E("Header code mismatch....");
- __err_message = true;
+ if (FINGERPRINT_HEADER_LSB != (another_buffer[idx]))
+ {
+ TRACE_E("Header code mismatch....");
+ __err_message = true;
+ }
+ break;
}
- break;
- }
- case 2:
- case 3:
- case 4:
- case 5: // Address -> ACK = 0xFFh
- {
- if (FINGERPRINT_DEVICE_ADDR_BIT != (another_buffer[idx]))
+ case 2:
+ case 3:
+ case 4:
+ case 5: // Address -> ACK = 0xFFh
{
- TRACE_E("DEV_ADDR code mismatch....");
- __err_message = true;
+ if (FINGERPRINT_DEVICE_ADDR_BIT != (another_buffer[idx]))
+ {
+ TRACE_E("DEV_ADDR code mismatch....");
+ __err_message = true;
+ }
+ break;
}
- break;
- }
- case 6: // PID -> ACK = 0x07h
- {
- if (FINGERPRINT_PID_ACKPACKET != (another_buffer[idx]))
+ case 6: // PID -> ACK = 0x07h
+ {
+ if (FINGERPRINT_PID_ACKPACKET != (another_buffer[idx]))
+ {
+ TRACE_E("ACK code mismatch....");
+ __err_message = true;
+ }
+ break;
+ }
+ case 7: // P_len -> ACK = 0x__h [MSB]
+ {
+ package_len = (uint16_t)(another_buffer[idx]);
+ break;
+ }
+ case 8: // P_len -> ACK = 0x__h [LSB]
{
- TRACE_E("ACK code mismatch....");
- __err_message = true;
+ package_len = (package_len << 8) + (uint16_t)(another_buffer[idx] & 0xFF);
+ break;
+ }
+ default:
+ break;
}
- break;
+ idx++;
}
- case 7: // P_len -> ACK = 0x__h [MSB]
+
+ if (!__err_message)
{
- package_len = (uint16_t)(another_buffer[idx]);
- break;
+ size_t _copy_size = (3 + (int)package_len);
+ memcpy((user_data->recieved_buffer), (another_buffer + 6), (_copy_size < MAX_PACKET_LENGTH_VAL) ? (_copy_size) : (MAX_PACKET_LENGTH_VAL)); // pid + p_len + confirmation + checksum
}
- case 8: // P_len -> ACK = 0x__h [LSB]
+ else
{
- package_len = (package_len << 8) + (uint16_t)(another_buffer[idx] & 0xFF);
- break;
- }
- default:
- break;
+ memset((user_data->recieved_buffer), 0, sizeof(user_data->recieved_buffer));
}
- idx++;
- }
-
- if (!__err_message)
- {
- size_t _copy_size = (3 + (int)package_len);
- memcpy((user_data->recieved_buffer), (another_buffer + 6), (_copy_size < MAX_PACKET_LENGTH_VAL) ? (_copy_size) : (MAX_PACKET_LENGTH_VAL)); // pid + p_len + confirmation + checksum
- }
- else
- {
- memset((user_data->recieved_buffer), 0, sizeof(user_data->recieved_buffer));
}
}
}
@@ -576,150 +590,153 @@ static void __fingerprint_operation_task(void *params)
if (NULL != item)
{
server_packet_t *user_data = (server_packet_t *)item->user_arg;
- time(&user_data->timeout_start_time); // !< reset the internal timer_start_time
- r307_as606_update_id_status_list(item); // !< The best place to update ID_status_list
- for (;;)
+ if (user_data)
{
- ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
- user_data->__busy_guard = true;
- gpio_isr_handler_remove(user_data->intr_pin);
-
- switch (user_data->opmode)
- {
- case FINGERPRINT_MATCH_MODE:
+ time(&user_data->timeout_start_time); // !< reset the internal timer_start_time
+ r307_as606_update_id_status_list(item); // !< The best place to update ID_status_list
+ for (;;)
{
- uint16_t tempelate_count;
- uint16_t temp_id = user_data->user_id;
- if (ReadTempNum(item->interface.uart.channel, &tempelate_count, (user_data->recieved_buffer), 500))
+ ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
+ user_data->__busy_guard = true;
+ gpio_isr_handler_remove(user_data->intr_pin);
+
+ switch (user_data->opmode)
{
- if (tempelate_count > 0)
+ case FINGERPRINT_MATCH_MODE:
+ {
+ uint16_t tempelate_count;
+ uint16_t temp_id = user_data->user_id;
+ if (ReadTempNum(item->interface.uart.channel, &tempelate_count, (user_data->recieved_buffer), 500))
{
- for (uint16_t j = 1; j <= FINGERPRINT_MAX_CAPACITY_LIMIT; j++)
+ if (tempelate_count > 0)
{
- if (true == user_data->validity[j]) // if user_id is occupied then only perform 'match_action'
+ for (uint16_t j = 1; j <= FINGERPRINT_MAX_CAPACITY_LIMIT; j++)
{
- user_data->user_id = j;
- if (r307_as606_match_id(item))
+ if (true == user_data->validity[j]) // if user_id is occupied then only perform 'match_action'
{
- user_data->matched_id = user_data->user_id;
- user_data->matched_confidence_level = (((user_data->confidence_level) > (uint16_t)100) ? 100 : (user_data->confidence_level));
- TRACE_I(" ----> Matched ID: [%d] ; Confidence : [%d]", (user_data->matched_id), (user_data->matched_confidence_level));
- break;
- }
- else
- {
- user_data->matched_id = user_data->user_id;
- user_data->matched_confidence_level = 0;
+ user_data->user_id = j;
+ if (r307_as606_match_id(item))
+ {
+ user_data->matched_id = user_data->user_id;
+ user_data->matched_confidence_level = (((user_data->confidence_level) > (uint16_t)100) ? 100 : (user_data->confidence_level));
+ TRACE_I(" ----> Matched ID: [%d] ; Confidence : [%d]", (user_data->matched_id), (user_data->matched_confidence_level));
+ break;
+ }
+ else
+ {
+ user_data->matched_id = user_data->user_id;
+ user_data->matched_confidence_level = 0;
+ }
}
}
}
}
- }
- else
- {
- TRACE_E("No USER_ID found ; internal library is empty.... Please trigger [ENROLLMENT] mode to add fingerprint");
- }
- TRACE_W("____ MATCH_IDS: SENDING _____");
- user_data->notify_flag = true;
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ACTION]);
-
- user_data->user_id = temp_id;
- break;
- }
- case FINGERPRINT_ENROLLMENT_MODE:
- {
- uint16_t current_id = r307_as606_find_immediate_vaccant_id(item);
- if ((current_id) > 0)
- {
- current_id = r307_as606_enroll_fingerprint(item);
- if (0 != current_id)
+ else
{
- if ((user_data->user_id) == current_id)
- {
- TRACE_I("RESULT:...Enrollment of user_id[%d].... process => Success", current_id);
-
- user_data->opmode = FINGERPRINT_MATCH_MODE;
- TRACE_W("____ ENROLL_IDS: SENDING _____");
- user_data->notify_flag = true;
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS]);
- user_data->notify_flag = true;
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL]);
- }
- else
- {
- TRACE_I("RESULT:...Duplicate in user_id[%d].... process => Blocked", current_id);
- }
+ TRACE_E("No USER_ID found ; internal library is empty.... Please trigger [ENROLLMENT] mode to add fingerprint");
}
- }
- else
- {
- TRACE_E("ALL user_id => occupied ; ... Delete IDs to enroll again.");
- }
- break;
- }
-
- case FINGERPRINT_ERASE_WITH_IDS_MODE:
- {
- uint16_t temp_id = user_data->user_id;
+ TRACE_W("____ MATCH_IDS: SENDING _____");
+ user_data->notify_flag = true;
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ACTION]);
- for (uint16_t i = 1; i <= FINGERPRINT_MAX_CAPACITY_LIMIT; i++)
+ user_data->user_id = temp_id;
+ break;
+ }
+ case FINGERPRINT_ENROLLMENT_MODE:
{
- if (false == user_data->protect[i]) // first check if this ID is unprotected
+ uint16_t current_id = r307_as606_find_immediate_vaccant_id(item);
+ if ((current_id) > 0)
{
- if (true == user_data->validity[i]) // second check if the id is occupied
+ current_id = r307_as606_enroll_fingerprint(item);
+ if (0 != current_id)
{
- TRACE_W("DELETING ID[#%d]", i);
- user_data->user_id = i;
- if (r307_as606_erase_specified_id(item)) // then delete and update 'validity[]' status
+ if ((user_data->user_id) == current_id)
{
- TRACE_S(" Success... DELETED ID[#%d]", i);
- user_data->validity[i] = false;
+ TRACE_I("RESULT:...Enrollment of user_id[%d].... process => Success", current_id);
+
+ user_data->opmode = FINGERPRINT_MATCH_MODE;
+ TRACE_W("____ ENROLL_IDS: SENDING _____");
+ user_data->notify_flag = true;
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS]);
+ user_data->notify_flag = true;
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_ENROLL]);
}
else
{
- TRACE_S(" Fail... NOT DELETED ID[#%d]", i);
+ TRACE_I("RESULT:...Duplicate in user_id[%d].... process => Blocked", current_id);
}
}
}
- }
- for (uint16_t i = 1; i <= FINGERPRINT_MAX_CAPACITY_LIMIT; i++)
- {
- user_data->protect[i] = false;
+ else
+ {
+ TRACE_E("ALL user_id => occupied ; ... Delete IDs to enroll again.");
+ }
+ break;
}
- user_data->user_id = temp_id;
- TRACE_W("____ ERASE_SPECIFIC_IDS: SENDING _____");
- user_data->notify_flag = true;
- ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS]);
- user_data->opmode = FINGERPRINT_MATCH_MODE;
- break;
- }
- case FINGERPRINT_ERASE_ALL_MODE:
- {
- if (r307_as606_erase_all_id(item))
+ case FINGERPRINT_ERASE_WITH_IDS_MODE:
{
+ uint16_t temp_id = user_data->user_id;
+
+ for (uint16_t i = 1; i <= FINGERPRINT_MAX_CAPACITY_LIMIT; i++)
+ {
+ if (false == user_data->protect[i]) // first check if this ID is unprotected
+ {
+ if (true == user_data->validity[i]) // second check if the id is occupied
+ {
+ TRACE_W("DELETING ID[#%d]", i);
+ user_data->user_id = i;
+ if (r307_as606_erase_specified_id(item)) // then delete and update 'validity[]' status
+ {
+ TRACE_S(" Success... DELETED ID[#%d]", i);
+ user_data->validity[i] = false;
+ }
+ else
+ {
+ TRACE_S(" Fail... NOT DELETED ID[#%d]", i);
+ }
+ }
+ }
+ }
for (uint16_t i = 1; i <= FINGERPRINT_MAX_CAPACITY_LIMIT; i++)
{
- user_data->validity[i] = false;
+ user_data->protect[i] = false;
}
- TRACE_W("____ ERASE_ALL: SENDING _____");
+
+ user_data->user_id = temp_id;
+ TRACE_W("____ ERASE_SPECIFIC_IDS: SENDING _____");
user_data->notify_flag = true;
ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS]);
+ user_data->opmode = FINGERPRINT_MATCH_MODE;
+ break;
+ }
+ case FINGERPRINT_ERASE_ALL_MODE:
+ {
+ if (r307_as606_erase_all_id(item))
+ {
+ for (uint16_t i = 1; i <= FINGERPRINT_MAX_CAPACITY_LIMIT; i++)
+ {
+ user_data->validity[i] = false;
+ }
+ TRACE_W("____ ERASE_ALL: SENDING _____");
+ user_data->notify_flag = true;
+ ezlopi_device_value_updated_from_device_item_id_v3(user_data->sensor_fp_item_ids[SENSOR_FP_ITEM_ID_FP_IDS]);
+ }
+ user_data->opmode = FINGERPRINT_MATCH_MODE;
+ break;
}
- user_data->opmode = FINGERPRINT_MATCH_MODE;
- break;
- }
- default:
- {
- TRACE_E("Invalid OPMODE is set..... {%d}. Reverting Back to default: 'MATCH_MODE-[0]'", user_data->opmode);
- user_data->opmode = FINGERPRINT_MATCH_MODE;
- break;
- }
+ default:
+ {
+ TRACE_E("Invalid OPMODE is set..... {%d}. Reverting Back to default: 'MATCH_MODE-[0]'", user_data->opmode);
+ user_data->opmode = FINGERPRINT_MATCH_MODE;
+ break;
+ }
+ }
+ TRACE_S(" --->> Remove Finger; To activate next Task_notify <<----");
+ gpio_isr_handler_add(user_data->intr_pin, gpio_notify_isr, item);
+ user_data->__busy_guard = false;
}
- TRACE_S(" --->> Remove Finger; To activate next Task_notify <<----");
- gpio_isr_handler_add(user_data->intr_pin, gpio_notify_isr, item);
- user_data->__busy_guard = false;
}
}
vTaskDelete(NULL);
diff --git a/ezlopi-sensors-devices/sensor-0067-UART-hilink-presence-sensor/sensor_0067_hilink_presence_sensor.c b/ezlopi-sensors-devices/sensor-0067-UART-hilink-presence-sensor/sensor_0067_hilink_presence_sensor.c
index f5523347f..18f4a9445 100644
--- a/ezlopi-sensors-devices/sensor-0067-UART-hilink-presence-sensor/sensor_0067_hilink_presence_sensor.c
+++ b/ezlopi-sensors-devices/sensor-0067-UART-hilink-presence-sensor/sensor_0067_hilink_presence_sensor.c
@@ -14,24 +14,24 @@
#include "sensor_0067_hilink_presence_sensor.h"
#include "hilink_presence_sensor_setting.h"
-static const char *hilink_presence_sensor_motion_direction_enum[] = {
+static const char* hilink_presence_sensor_motion_direction_enum[] = {
"unknown",
"no_motion",
"incoming",
"outgoing",
};
-static l_ezlopi_item_t *motion_item;
-static l_ezlopi_item_t *motion_direction_item;
-static l_ezlopi_item_t *distance_item;
+static l_ezlopi_item_t* motion_item;
+static l_ezlopi_item_t* motion_direction_item;
+static l_ezlopi_item_t* distance_item;
-static int __prepare(void *arg, void *user_arg);
-static int __init(l_ezlopi_item_t *item);
-static int __get_hub_item_value(l_ezlopi_item_t *item, void *args);
-static int __get_cjson_value(l_ezlopi_item_t *item, void *args);
-static int __notify(l_ezlopi_item_t *item);
+static int __prepare(void* arg, void* user_arg);
+static int __init(l_ezlopi_item_t* item);
+static int __get_hub_item_value(l_ezlopi_item_t* item, void* args);
+static int __get_cjson_value(l_ezlopi_item_t* item, void* args);
+static int __notify(l_ezlopi_item_t* item);
-int sensor_0067_hilink_presence_sensor_v3(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
+int sensor_0067_hilink_presence_sensor_v3(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;
switch (action)
@@ -69,7 +69,7 @@ int sensor_0067_hilink_presence_sensor_v3(e_ezlopi_actions_t action, l_ezlopi_it
return ret;
}
-static void __notify_if_needed(ld2410_outputs_t *hilink_data, ld2410_outputs_t *present_hilink_data)
+static void __notify_if_needed(ld2410_outputs_t* hilink_data, ld2410_outputs_t* present_hilink_data)
{
// Update specific item to the cloud only when the target's value is changed, else continue.
if (hilink_data->direction != present_hilink_data->direction)
@@ -89,11 +89,11 @@ static void __notify_if_needed(ld2410_outputs_t *hilink_data, ld2410_outputs_t *
}
}
-static int __notify(l_ezlopi_item_t *item)
+static int __notify(l_ezlopi_item_t* item)
{
int ret = 0;
static int sec_count = 0;
- ld2410_outputs_t *hilink_data = (ld2410_outputs_t *)item->user_arg;
+ ld2410_outputs_t* hilink_data = (ld2410_outputs_t*)item->user_arg;
if (hilink_data)
{
ld2410_outputs_t present_hilink_data;
@@ -133,12 +133,12 @@ static int __notify(l_ezlopi_item_t *item)
return ret;
}
-static int __add_array_to_object(cJSON *cj_params, const char *const *arr, const int count)
+static int __add_array_to_object(cJSON* cj_params, const char* const* arr, const int count)
{
int ret = 0;
if (cj_params && arr)
{
- cJSON *enum_array = cJSON_CreateStringArray(arr, count);
+ cJSON* enum_array = cJSON_CreateStringArray(arr, count);
cJSON_AddItemToObject(cj_params, "enum", enum_array);
TRACE_I("%s", cJSON_Print(cj_params));
}
@@ -149,10 +149,10 @@ static int __add_array_to_object(cJSON *cj_params, const char *const *arr, const
return ret;
}
-static int __add_value_to_cjson(l_ezlopi_item_t *item, cJSON *cj_params, bool is_hub_request)
+static int __add_value_to_cjson(l_ezlopi_item_t* item, cJSON* cj_params, bool is_hub_request)
{
int ret = 0;
- ld2410_outputs_t *hilink_data = (ld2410_outputs_t *)item->user_arg;
+ ld2410_outputs_t* hilink_data = (ld2410_outputs_t*)item->user_arg;
if (item && cj_params && hilink_data)
{
@@ -163,8 +163,8 @@ static int __add_value_to_cjson(l_ezlopi_item_t *item, cJSON *cj_params, bool is
{
motion = true;
}
- cJSON_AddBoolToObject(cj_params, "valueFormatted", motion);
- cJSON_AddBoolToObject(cj_params, "value", motion);
+ cJSON_AddBoolToObject(cj_params, ezlopi_valueFormatted_str, motion);
+ cJSON_AddBoolToObject(cj_params, ezlopi_value_str, motion);
}
if (ezlopi_item_name_motion_direction == item->cloud_properties.item_name)
{
@@ -172,24 +172,24 @@ static int __add_value_to_cjson(l_ezlopi_item_t *item, cJSON *cj_params, bool is
{
ESP_ERROR_CHECK(__add_array_to_object(cj_params, hilink_presence_sensor_motion_direction_enum, 4));
}
- cJSON_AddStringToObject(cj_params, "valueFormatted", hilink_presence_sensor_motion_direction_enum[hilink_data->direction + 1]);
- cJSON_AddStringToObject(cj_params, "value", hilink_presence_sensor_motion_direction_enum[hilink_data->direction + 1]);
+ cJSON_AddStringToObject(cj_params, ezlopi_valueFormatted_str, hilink_presence_sensor_motion_direction_enum[hilink_data->direction + 1]);
+ cJSON_AddStringToObject(cj_params, ezlopi_value_str, hilink_presence_sensor_motion_direction_enum[hilink_data->direction + 1]);
}
if (ezlopi_item_name_distance == item->cloud_properties.item_name)
{
- cJSON_AddNumberToObject(cj_params, "valueFormatted", hilink_data->moving_target_distance);
- cJSON_AddNumberToObject(cj_params, "value", hilink_data->moving_target_distance);
+ cJSON_AddNumberToObject(cj_params, ezlopi_valueFormatted_str, hilink_data->moving_target_distance);
+ cJSON_AddNumberToObject(cj_params, ezlopi_value_str, hilink_data->moving_target_distance);
}
}
return ret;
}
-static int __get_hub_item_value(l_ezlopi_item_t *item, void *args)
+static int __get_hub_item_value(l_ezlopi_item_t* item, void* args)
{
int ret = 0;
- cJSON *cj_params = (cJSON *)args;
+ cJSON* cj_params = (cJSON*)args;
if (cj_params)
{
ESP_ERROR_CHECK(__add_value_to_cjson(item, cj_params, true));
@@ -202,11 +202,11 @@ static int __get_hub_item_value(l_ezlopi_item_t *item, void *args)
return ret;
}
-static int __get_cjson_value(l_ezlopi_item_t *item, void *args)
+static int __get_cjson_value(l_ezlopi_item_t* item, void* args)
{
int ret = 0;
- cJSON *cj_params = (cJSON *)args;
+ cJSON* cj_params = (cJSON*)args;
if (cj_params)
{
@@ -220,49 +220,46 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *args)
return ret;
}
-static int __init(l_ezlopi_item_t *item)
+static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
- if (item)
+ if ((item))
{
ld2410_outputs_t *hilink_data = (ld2410_outputs_t *)item->user_arg;
- if (item->interface.uart.enable && hilink_data)
+ if (hilink_data)
{
- s_ezlopi_uart_t uart_settings = {
- .baudrate = LD2410_BAUDRATE,
- .tx = item->interface.uart.tx,
- .rx = item->interface.uart.rx,
- };
- if (ESP_OK == ld2410_setup(uart_settings))
+ if (item->interface.uart.enable)
{
- ESP_ERROR_CHECK(hilink_presence_sensor_apply_settings());
- ESP_ERROR_CHECK(ld2410_get_data(hilink_data));
- ret = 1;
- }
- else
- {
- ret = -1;
+ s_ezlopi_uart_t uart_settings = {
+ .baudrate = LD2410_BAUDRATE,
+ .tx = item->interface.uart.tx,
+ .rx = item->interface.uart.rx,
+ };
+ if (ESP_OK == ld2410_setup(uart_settings))
+ {
+ ESP_ERROR_CHECK(hilink_presence_sensor_apply_settings());
+ ESP_ERROR_CHECK(ld2410_get_data(hilink_data));
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ free(item->user_arg); // this will free ; memory address linked to all items
+ item->user_arg = NULL;
+ ezlopi_device_free_device_by_item(item);
+ }
}
}
else
{
ret = -1;
- }
-
- if (0 == ret)
- {
- ret = -1;
- if (item->user_arg)
- {
- free(item->user_arg);
- item->user_arg = NULL;
- }
+ ezlopi_device_free_device_by_item(item);
}
}
return ret;
}
-static void __perare_hilink_device_cloud_properties(l_ezlopi_device_t *device)
+static void __perare_hilink_device_cloud_properties(l_ezlopi_device_t* device)
{
device->cloud_properties.category = category_security_sensor;
device->cloud_properties.subcategory = subcategory_motion;
@@ -271,7 +268,7 @@ static void __perare_hilink_device_cloud_properties(l_ezlopi_device_t *device)
device->cloud_properties.parent_device_id = device->cloud_properties.device_id;
}
-static void __prepare_hilink_motion_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_properties, void *user_args)
+static void __prepare_hilink_motion_item_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_properties, void* user_args)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -285,14 +282,14 @@ static void __prepare_hilink_motion_item_cloud_properties(l_ezlopi_item_t *item,
item->interface.uart.enable = true;
item->interface.uart.channel = 0;
- CJSON_GET_VALUE_INT(cj_properties, "baudrate", item->interface.uart.baudrate);
- CJSON_GET_VALUE_INT(cj_properties, "tx", item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "rx", item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_baud_str, item->interface.uart.baudrate);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio_tx_str, item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio_rx_str, item->interface.uart.rx);
item->user_arg = user_args;
}
-static void __prepare_hilink_motion_direction_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_properties, void *user_arg)
+static void __prepare_hilink_motion_direction_item_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_properties, void* user_arg)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -306,14 +303,14 @@ static void __prepare_hilink_motion_direction_item_cloud_properties(l_ezlopi_ite
item->interface.uart.enable = false;
item->interface.uart.channel = 0;
- CJSON_GET_VALUE_INT(cj_properties, "baudrate", item->interface.uart.baudrate);
- CJSON_GET_VALUE_INT(cj_properties, "tx", item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "rx", item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_baud_str, item->interface.uart.baudrate);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio_tx_str, item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio_rx_str, item->interface.uart.rx);
item->user_arg = user_arg;
}
-static void __prepare_hilink_distance_item_cloud_properties(l_ezlopi_item_t *item, cJSON *cj_properties, void *user_arg)
+static void __prepare_hilink_distance_item_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_properties, void* user_arg)
{
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -327,23 +324,23 @@ static void __prepare_hilink_distance_item_cloud_properties(l_ezlopi_item_t *ite
item->interface.uart.enable = false;
item->interface.uart.channel = 0;
- CJSON_GET_VALUE_INT(cj_properties, "baudrate", item->interface.uart.baudrate);
- CJSON_GET_VALUE_INT(cj_properties, "tx", item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_properties, "rx", item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_baud_str, item->interface.uart.baudrate);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio_tx_str, item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_properties, ezlopi_gpio_rx_str, item->interface.uart.rx);
item->user_arg = user_arg;
}
-static int __prepare(void *arg, void *user_arg)
+static int __prepare(void* arg, void* user_arg)
{
int ret = 0;
- s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
+ s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg)
{
- ld2410_outputs_t *hilink_data = (ld2410_outputs_t *)malloc(sizeof(ld2410_outputs_t));
+ ld2410_outputs_t* hilink_data = (ld2410_outputs_t*)malloc(sizeof(ld2410_outputs_t));
if (hilink_data)
{
- l_ezlopi_device_t *hilink_device = ezlopi_device_add_device(prep_arg->cjson_device);
+ l_ezlopi_device_t* hilink_device = ezlopi_device_add_device(prep_arg->cjson_device);
if (hilink_device)
{
memset(hilink_data, 0, sizeof(ld2410_outputs_t));
@@ -352,18 +349,18 @@ static int __prepare(void *arg, void *user_arg)
motion_item = ezlopi_device_add_item_to_device(hilink_device, sensor_0067_hilink_presence_sensor_v3);
if (motion_item)
{
- __prepare_hilink_motion_item_cloud_properties(motion_item, prep_arg->cjson_device, (void *)hilink_data);
+ __prepare_hilink_motion_item_cloud_properties(motion_item, prep_arg->cjson_device, (void*)hilink_data);
}
motion_direction_item = ezlopi_device_add_item_to_device(hilink_device, sensor_0067_hilink_presence_sensor_v3);
if (motion_direction_item)
{
- __prepare_hilink_motion_direction_item_cloud_properties(motion_direction_item, prep_arg->cjson_device, (void *)hilink_data);
+ __prepare_hilink_motion_direction_item_cloud_properties(motion_direction_item, prep_arg->cjson_device, (void*)hilink_data);
}
distance_item = ezlopi_device_add_item_to_device(hilink_device, sensor_0067_hilink_presence_sensor_v3);
if (distance_item)
{
- __prepare_hilink_distance_item_cloud_properties(distance_item, prep_arg->cjson_device, (void *)hilink_data);
+ __prepare_hilink_distance_item_cloud_properties(distance_item, prep_arg->cjson_device, (void*)hilink_data);
}
if (!motion_item && !motion_direction_item && !distance_item)
{
diff --git a/ezlopi-sensors-devices/sensor-0068-I2C-ENS160-gas-sensor/sensor_0068_ENS160_gas_sensor.c b/ezlopi-sensors-devices/sensor-0068-I2C-ENS160-gas-sensor/sensor_0068_ENS160_gas_sensor.c
index f1b89a6fe..4b1bff128 100644
--- a/ezlopi-sensors-devices/sensor-0068-I2C-ENS160-gas-sensor/sensor_0068_ENS160_gas_sensor.c
+++ b/ezlopi-sensors-devices/sensor-0068-I2C-ENS160-gas-sensor/sensor_0068_ENS160_gas_sensor.c
@@ -11,6 +11,7 @@
#include "ezlopi_hal_i2c_master.h"
+#include "ezlopi_cloud_keywords.h"
#include "ezlopi_cloud_category_str.h"
#include "ezlopi_cloud_subcategory_str.h"
#include "ezlopi_cloud_device_types_str.h"
@@ -208,7 +209,7 @@ static void __prepare_ens160_gas_sensor_device_cloud_properties(l_ezlopi_device_
static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_device, void* user_arg)
{
- CJSON_GET_VALUE_INT(cj_device, "dev_type", item->interface_type);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.has_getter = true;
item->cloud_properties.has_setter = false;
@@ -216,8 +217,8 @@ static void __prepare_item_cloud_properties(l_ezlopi_item_t* item, cJSON* cj_dev
item->user_arg = user_arg;
item->interface.i2c_master.clock_speed = ENS160_I2C_SPEED;
- CJSON_GET_VALUE_INT(cj_device, "gpio_scl", item->interface.i2c_master.scl);
- CJSON_GET_VALUE_INT(cj_device, "gpio_sda", item->interface.i2c_master.sda);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_scl_str, item->interface.i2c_master.scl);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_sda_str, item->interface.i2c_master.sda);
item->interface.i2c_master.channel = I2C_NUM_0;
item->interface.i2c_master.address = ENS160_I2C_ADDRESS;
item->interface.i2c_master.enable = false;
diff --git a/ezlopi-sensors-devices/sensor-0069-UART-ze08-ch02-gas-sensor/sensor_0069_ze08_ch02_gas_sensor.c b/ezlopi-sensors-devices/sensor-0069-UART-ze08-ch02-gas-sensor/sensor_0069_ze08_ch02_gas_sensor.c
index c1a90e90c..c877e423a 100644
--- a/ezlopi-sensors-devices/sensor-0069-UART-ze08-ch02-gas-sensor/sensor_0069_ze08_ch02_gas_sensor.c
+++ b/ezlopi-sensors-devices/sensor-0069-UART-ze08-ch02-gas-sensor/sensor_0069_ze08_ch02_gas_sensor.c
@@ -149,9 +149,9 @@ static void __prepare_ze08_ch2o_sensor_ppm_item_cloud_properties(l_ezlopi_item_t
item->cloud_properties.value_type = value_type_substance_amount;
item->cloud_properties.scale = scales_parts_per_million;
- CJSON_GET_VALUE_INT(cj_device, "gpio_tx", item->interface.uart.tx);
- CJSON_GET_VALUE_INT(cj_device, "gpio_rx", item->interface.uart.rx);
- CJSON_GET_VALUE_INT(cj_device, "baud", item->interface.uart.baudrate);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_tx_str, item->interface.uart.tx);
+ CJSON_GET_VALUE_INT(cj_device, ezlopi_gpio_rx_str, item->interface.uart.rx);
+ CJSON_GET_VALUE_INT(cj_device,ezlopi_baud_str, item->interface.uart.baudrate);
item->interface.uart.enable = true;
item->user_arg = user_arg;
diff --git a/ezlopi-services/ezlopi-service-ble/CMakeLists.txt b/ezlopi-services/ezlopi-service-ble/CMakeLists.txt
index 507205118..0f2df9c89 100644
--- a/ezlopi-services/ezlopi-service-ble/CMakeLists.txt
+++ b/ezlopi-services/ezlopi-service-ble/CMakeLists.txt
@@ -5,12 +5,13 @@ set(EZLOPI_CORE_COMPONENTS
ezlopi-core-devices
ezlopi-core-ble
ezlopi-core-reset
- ezlopi-user-config
+ # ezlopi-user-config
)
-idf_component_register(SRCS "ezlopi_service_ble_provisioning.c" "ezlopi_ble_service_security.c" "ezlopi_service_ble_security.c" "ezlopi_service_ble_device_info.c" "ezlopi_service_ble.c" "ezlopi_service_ble_dynamic_config.c" "${src_files}"
+idf_component_register(SRCS "ezlopi_service_ble_wifi.c" "${src_files}"
INCLUDE_DIRS "."
REQUIRES ${EZLOPI_CORE_COMPONENTS}
)
+
diff --git a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c
index 4ee360778..41b0b8165 100644
--- a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c
+++ b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c
@@ -168,7 +168,6 @@ static void __provisioning_info_write_func(esp_gatt_value_t* value, esp_ble_gatt
cJSON* root = cJSON_ParseWithLength((const char*)param->write.value, param->write.len);
if (root)
{
-
uint32_t len = CJ_GET_NUMBER(ezlopi_len_str);
uint32_t tot_len = CJ_GET_NUMBER(ezlopi_total_len_str);
uint32_t sequence = CJ_GET_NUMBER(ezlopi_sequence_str);
diff --git a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_wifi.c b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_wifi.c
index 84397ec7e..394c17cb7 100644
--- a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_wifi.c
+++ b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_wifi.c
@@ -19,14 +19,14 @@
#include "ezlopi_service_ble_ble_auth.h"
#include "ezlopi_service_ble.h"
-static s_linked_buffer_t *wifi_creds_linked_buffer = NULL;
+static s_linked_buffer_t* wifi_creds_linked_buffer = NULL;
-static void wifi_creds_write_func(esp_gatt_value_t *value, esp_ble_gatts_cb_param_t *param);
-static void wifi_creds_write_exec_func(esp_gatt_value_t *value, esp_ble_gatts_cb_param_t *param);
-static void wifi_creds_parse_and_connect(uint8_t *value, uint32_t len);
+static void wifi_creds_write_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param);
+static void wifi_creds_write_exec_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param);
+static void wifi_creds_parse_and_connect(uint8_t* value, uint32_t len);
// static void wifi_event_notify_upcall(esp_event_base_t event, void *arg);
-static s_gatt_service_t *wifi_ble_service;
+static s_gatt_service_t* wifi_ble_service;
void ezlopi_ble_service_wifi_profile_init(void)
{
@@ -46,7 +46,7 @@ void ezlopi_ble_service_wifi_profile_init(void)
ezlopi_ble_gatt_add_characteristic(wifi_ble_service, &uuid, permission, properties, NULL, wifi_creds_write_func, wifi_creds_write_exec_func);
}
-static void wifi_creds_write_func(esp_gatt_value_t *value, esp_ble_gatts_cb_param_t *param)
+static void wifi_creds_write_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param)
{
if (0 == param->write.is_prep) // Data received in single packet
{
@@ -68,7 +68,7 @@ static void wifi_creds_write_func(esp_gatt_value_t *value, esp_ble_gatts_cb_para
}
}
-static void wifi_creds_write_exec_func(esp_gatt_value_t *value, esp_ble_gatts_cb_param_t *param)
+static void wifi_creds_write_exec_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param)
{
if (wifi_creds_linked_buffer)
{
@@ -79,22 +79,23 @@ static void wifi_creds_write_exec_func(esp_gatt_value_t *value, esp_ble_gatts_cb
}
}
-static void wifi_creds_parse_and_connect(uint8_t *value, uint32_t len)
+static void wifi_creds_parse_and_connect(uint8_t* value, uint32_t len)
{
if ((NULL != value) && (len > 0))
{
- cJSON *root = cJSON_Parse((const char *)value);
+ cJSON* root = cJSON_Parse((const char*)value);
+
if (root)
{
- cJSON *cj_ssid = cJSON_GetObjectItemCaseSensitive(root, ezlopi_wifi_ssid_str);
- cJSON *cj_user_id = cJSON_GetObjectItemCaseSensitive(root, ezlopi_user_id_str);
- cJSON *cj_password = cJSON_GetObjectItemCaseSensitive(root, ezlopi_wifi_password_str);
+ cJSON* cj_ssid = cJSON_GetObjectItemCaseSensitive(root, ezlopi_wifi_ssid_str);
+ cJSON* cj_user_id = cJSON_GetObjectItemCaseSensitive(root, ezlopi_user_id_str);
+ cJSON* cj_password = cJSON_GetObjectItemCaseSensitive(root, ezlopi_wifi_password_str);
if (cj_user_id && cj_user_id->valuestring && cj_password && cj_password->valuestring && cj_ssid && cj_ssid->valuestring)
{
- char *ssid = cj_ssid->valuestring;
- char *password = cj_password->valuestring;
- char *user_id_str = cj_user_id->valuestring;
+ char* ssid = cj_ssid->valuestring;
+ char* password = cj_password->valuestring;
+ char* user_id_str = cj_user_id->valuestring;
if (user_id_str && ssid && password)
{
diff --git a/ezlopi-services/ezlopi-service-broadcast/CMakeLists.txt b/ezlopi-services/ezlopi-service-broadcast/CMakeLists.txt
new file mode 100644
index 000000000..67579a839
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-broadcast/CMakeLists.txt
@@ -0,0 +1,27 @@
+
+file(GLOB_RECURSE provisioning_src "*.c*")
+
+set(EZLOPI_UTIL_COMPONENTS
+ ezlopi-util-trace
+)
+
+set(SDK_COMPONENTS
+)
+
+set(EZLOPI_CORE_COMPONENTS
+ ezlopi-core-ezlopi
+)
+
+set(EZLOPI_CLOUD_COMPONENTS
+
+)
+
+
+
+idf_component_register(SRCS "${provisioning_src}"
+ INCLUDE_DIRS "."
+ REQUIRES ${SDK_COMPONENTS}
+ ${EZLOPI_CORE_COMPONENTS}
+ ${EZLOPI_UTIL_COMPONENTS}
+ ${EZLOPI_CLOUD_COMPONENTS}
+ )
diff --git a/ezlopi-services/ezlopi-service-broadcast/ezlopi_service_broadcast.c b/ezlopi-services/ezlopi-service-broadcast/ezlopi_service_broadcast.c
new file mode 100644
index 000000000..17406102c
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-broadcast/ezlopi_service_broadcast.c
@@ -0,0 +1,64 @@
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/queue.h"
+
+#include "ezlopi_service_broadcast.h"
+#include "ezlopi_core_ezlopi_broadcast.h"
+
+static QueueHandle_t __broadcast_queue = NULL;
+
+static void __broadcast_process(void* pv);
+static int ezlopi_service_broadcast_send_to_queue(char* data);
+
+
+void ezlopi_service_broadcast_init(void)
+{
+ __broadcast_queue = xQueueCreate(sizeof(char*), 30);
+ if (__broadcast_queue)
+ {
+ xTaskCreate(__broadcast_process, "broadcast-service", 4 * 1024, NULL, 2, NULL);
+ ezlopi_core_ezlopi_broadcast_methods_set_queue(ezlopi_service_broadcast_send_to_queue);
+ }
+}
+
+static void __broadcast_process(void* pv) {
+ while (1)
+ {
+ char* data = NULL;
+ if (pdTRUE == xQueueReceive(__broadcast_queue, &data, portMAX_DELAY))
+ {
+ if (data)
+ {
+ vTaskDelay(1000 / portTICK_PERIOD_MS);
+ ezlopi_core_ezlopi_broadcast_execute(data);
+ free(data);
+ }
+ }
+ }
+}
+
+static int ezlopi_service_broadcast_send_to_queue(char* data)
+{
+ int ret = 0;
+ if (__broadcast_queue && data)
+ {
+ if (xQueueIsQueueFullFromISR(__broadcast_queue))
+ {
+ char* tmp_data = NULL;
+ if (pdTRUE == xQueueReceive(__broadcast_queue, &tmp_data, 0))
+ {
+ if (tmp_data)
+ {
+ free(tmp_data);
+ }
+ }
+ }
+
+ char* tmp_data = data;
+ if (pdTRUE == xQueueSend(__broadcast_queue, &tmp_data, 1000 / portTICK_PERIOD_MS))
+ {
+ ret = 1;
+ }
+ }
+ return ret;
+}
\ No newline at end of file
diff --git a/ezlopi-services/ezlopi-service-broadcast/ezlopi_service_broadcast.h b/ezlopi-services/ezlopi-service-broadcast/ezlopi_service_broadcast.h
new file mode 100644
index 000000000..260cf6026
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-broadcast/ezlopi_service_broadcast.h
@@ -0,0 +1,9 @@
+#ifndef __EZLOPI_SERVICE_BROADCAST_H__
+#define __EZLOPI_SERVICE_BROADCAST_H__
+
+#include
+
+void ezlopi_service_broadcast_init(void);
+
+
+#endif // __EZLOPI_SERVICE_BROADCAST_H__
diff --git a/ezlopi-services/ezlopi-service-gpioisr/ezlopi_service_gpioisr..c b/ezlopi-services/ezlopi-service-gpioisr/ezlopi_service_gpioisr..c
index e0071590d..7e64bdfb0 100644
--- a/ezlopi-services/ezlopi-service-gpioisr/ezlopi_service_gpioisr..c
+++ b/ezlopi-services/ezlopi-service-gpioisr/ezlopi_service_gpioisr..c
@@ -55,7 +55,7 @@ void gpio_isr_service_register_v3(l_ezlopi_item_t *item, f_interrupt_upcall_t __
}
else
{
- TRACE_S("Successfully added GPIO ISR handler.");
+ TRACE_S("Successfully added GPIO ISR handler for pin: %d.", item->interface.gpio.gpio_in.gpio_num);
}
}
}
diff --git a/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.c b/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.c
index 6fcdef678..3539f191c 100644
--- a/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.c
+++ b/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.c
@@ -4,19 +4,20 @@
#include "ezlopi_util_trace.h"
#include "ezlopi_core_scenes_status_changed.h"
+#include "ezlopi_core_scenes_v2.h"
#include "ezlopi_cloud_constants.h"
#include "ezlopi_service_meshbot.h"
-static void __scenes_process(void *arg);
-static int __execute_then_condition(l_scenes_list_v2_t *scene_node);
-static int __execute_else_condition(l_scenes_list_v2_t *scene_node);
+static void __scenes_process(void* arg);
+static int __execute_then_condition(l_scenes_list_v2_t* scene_node);
+static int __execute_else_condition(l_scenes_list_v2_t* scene_node);
uint32_t ezlopi_meshbot_service_stop_for_scene_id(uint32_t _id)
{
uint32_t ret = 0;
- l_scenes_list_v2_t *scene_node = ezlopi_scenes_get_by_id_v2(_id);
+ l_scenes_list_v2_t* scene_node = ezlopi_scenes_get_by_id_v2(_id);
if (scene_node)
{
if (EZLOPI_SCENE_STATUS_RUNNING == scene_node->status)
@@ -37,7 +38,7 @@ uint32_t ezlopi_meshbot_service_stop_for_scene_id(uint32_t _id)
return ret;
}
-uint32_t ezlopi_meshobot_service_stop_scene(l_scenes_list_v2_t *scene_node)
+uint32_t ezlopi_meshobot_service_stop_scene(l_scenes_list_v2_t* scene_node)
{
int ret = 0;
if (scene_node)
@@ -59,7 +60,7 @@ uint32_t ezlopi_meshobot_service_stop_scene(l_scenes_list_v2_t *scene_node)
return ret;
}
-uint32_t ezlopi_meshbot_service_start_scene(l_scenes_list_v2_t *scene_node)
+uint32_t ezlopi_meshbot_service_start_scene(l_scenes_list_v2_t* scene_node)
{
int ret = 0;
if (scene_node)
@@ -95,7 +96,7 @@ uint32_t ezlopi_scenes_service_run_by_id(uint32_t _id)
{
uint32_t ret = 0;
TRACE_D("Scene-id: %d", _id);
- l_scenes_list_v2_t *scene_node = ezlopi_scenes_get_by_id_v2(_id);
+ l_scenes_list_v2_t* scene_node = ezlopi_scenes_get_by_id_v2(_id);
if (scene_node)
{
@@ -133,7 +134,7 @@ uint32_t ezlopi_scenes_service_run_by_id(uint32_t _id)
void ezlopi_scenes_meshbot_init(void)
{
- l_scenes_list_v2_t *scene_node = ezlopi_scenes_get_scenes_head_v2();
+ l_scenes_list_v2_t* scene_node = ezlopi_scenes_get_scenes_head_v2();
while (scene_node)
{
if (scene_node->enabled && scene_node->when_block && (scene_node->else_block || scene_node->then_block))
@@ -149,9 +150,36 @@ void ezlopi_scenes_meshbot_init(void)
}
}
-static void __scenes_process(void *arg)
+uint32_t ezlopi_meshbot_execute_scene_else_action_group(uint32_t scene_id)
{
- l_scenes_list_v2_t *scene_node = (l_scenes_list_v2_t *)arg;
+ int ret = 0;
+ l_scenes_list_v2_t* scene_node = ezlopi_scenes_get_by_id_v2(scene_id);
+ if (scene_node)
+ {
+ if (scene_node->else_block)
+ {
+ if (1 == __execute_else_condition(scene_node))
+ {
+ ezlopi_scenes_status_change_broadcast(scene_node, scene_status_finished_str);
+ }
+ else
+ {
+ ezlopi_scenes_status_change_broadcast(scene_node, scene_status_failed_str);
+ ret = 1;
+ }
+ }
+ }
+ else
+ {
+ ezlopi_scenes_status_change_broadcast(scene_node, scene_status_failed_str);
+ ret = 1;
+ }
+ return ret;
+}
+
+static void __scenes_process(void* arg)
+{
+ l_scenes_list_v2_t* scene_node = (l_scenes_list_v2_t*)arg;
scene_node->status = EZLOPI_SCENE_STATUS_RUN;
TRACE_I("task - '%s': Running", scene_node->name);
uint32_t stopped_condition_count = 0;
@@ -164,14 +192,14 @@ static void __scenes_process(void *arg)
scene_node->status = EZLOPI_SCENE_STATUS_RUNNING;
uint32_t when_condition_returned = 0;
- l_when_block_v2_t *when_condition_node = scene_node->when_block;
+ l_when_block_v2_t* when_condition_node = scene_node->when_block;
if (when_condition_node)
{
f_scene_method_v2_t when_method = ezlopi_scene_get_method_v2(when_condition_node->block_options.method.type);
if (when_method)
{
- when_condition_returned = when_method(scene_node, (void *)when_condition_node);
+ when_condition_returned = when_method(scene_node, (void*)when_condition_node);
if (when_condition_returned)
{
if (started_condition_fired_count < 2)
@@ -247,10 +275,10 @@ static void __scenes_process(void *arg)
vTaskDelete(NULL);
}
-static int __execute_then_condition(l_scenes_list_v2_t *scene_node)
+static int __execute_then_condition(l_scenes_list_v2_t* scene_node)
{
int ret = 0;
- l_action_block_v2_t *then_node = scene_node->then_block;
+ l_action_block_v2_t* then_node = scene_node->then_block;
while (then_node)
{
uint32_t delay_ms = (then_node->delay.days * (24 * 60 * 60) + then_node->delay.hours * (60 * 60) + then_node->delay.minutes * 60 + then_node->delay.seconds) * 1000;
@@ -260,7 +288,7 @@ static int __execute_then_condition(l_scenes_list_v2_t *scene_node)
vTaskDelay(delay_ms / portTICK_RATE_MS);
}
- const char *method_name = ezlopi_scene_get_scene_method_name(then_node->block_options.method.type);
+ const char* method_name = ezlopi_scene_get_scene_method_name(then_node->block_options.method.type);
if (method_name)
{
TRACE_D("Calling: %s", method_name);
@@ -275,7 +303,7 @@ static int __execute_then_condition(l_scenes_list_v2_t *scene_node)
if (then_method)
{
ret = 1;
- then_method(scene_node, (void *)then_node);
+ then_method(scene_node, (void*)then_node);
}
if (then_node->next)
@@ -289,10 +317,10 @@ static int __execute_then_condition(l_scenes_list_v2_t *scene_node)
return ret;
}
-static int __execute_else_condition(l_scenes_list_v2_t *scene_node)
+static int __execute_else_condition(l_scenes_list_v2_t* scene_node)
{
int ret = 0;
- l_action_block_v2_t *else_node = scene_node->else_block;
+ l_action_block_v2_t* else_node = scene_node->else_block;
while (else_node)
{
uint32_t delay_ms = (else_node->delay.days * (24 * 60 * 60) + else_node->delay.hours * (60 * 60) + else_node->delay.minutes * 60 + else_node->delay.seconds) * 1000;
@@ -302,7 +330,7 @@ static int __execute_else_condition(l_scenes_list_v2_t *scene_node)
vTaskDelay(delay_ms / portTICK_RATE_MS);
}
- const char *method_name = ezlopi_scene_get_scene_method_name(else_node->block_options.method.type);
+ const char* method_name = ezlopi_scene_get_scene_method_name(else_node->block_options.method.type);
if (method_name)
{
TRACE_D("Calling: %s", method_name);
@@ -317,7 +345,7 @@ static int __execute_else_condition(l_scenes_list_v2_t *scene_node)
if (else_method)
{
ret = 1;
- else_method(scene_node, (void *)else_node);
+ else_method(scene_node, (void*)else_node);
}
else_node = else_node->next;
diff --git a/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.h b/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.h
index bfc511a96..3a4cd89e6 100644
--- a/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.h
+++ b/ezlopi-services/ezlopi-service-meshbot/ezlopi_service_meshbot.h
@@ -7,9 +7,12 @@
void ezlopi_scenes_meshbot_init(void);
uint32_t ezlopi_scenes_service_run_by_id(uint32_t _id);
-uint32_t ezlopi_meshbot_service_start_scene(l_scenes_list_v2_t *scene_node);
+uint32_t ezlopi_meshbot_service_start_scene(l_scenes_list_v2_t* scene_node);
uint32_t ezlopi_meshbot_service_stop_for_scene_id(uint32_t _id);
-uint32_t ezlopi_meshobot_service_stop_scene(l_scenes_list_v2_t *scene_node);
+uint32_t ezlopi_meshobot_service_stop_scene(l_scenes_list_v2_t* scene_node);
+
+
+uint32_t ezlopi_meshbot_execute_scene_else_action_group(uint32_t scene_id);
#endif // _EZLOPI_SERVICE_MESHBOT_H_
diff --git a/ezlopi-services/ezlopi-service-modes/ezlopi_service_modes.c b/ezlopi-services/ezlopi-service-modes/ezlopi_service_modes.c
index 92edb5a64..c7fd2f6e8 100644
--- a/ezlopi-services/ezlopi-service-modes/ezlopi_service_modes.c
+++ b/ezlopi-services/ezlopi-service-modes/ezlopi_service_modes.c
@@ -3,13 +3,15 @@
#include "ezlopi_util_trace.h"
+#include "ezlopi_cloud_modes.h"
+
#include "ezlopi_core_modes.h"
#include "ezlopi_core_devices.h"
-#include "ezlopi_cloud_modes.h"
#include "ezlopi_core_modes_cjson.h"
-#include "ezlopi_service_webprov.h"
+#include "ezlopi_core_ezlopi_broadcast.h"
#include "ezlopi_service_modes.h"
+#include "ezlopi_service_webprov.h"
static TaskHandle_t sg_process_handle = NULL;
@@ -81,10 +83,19 @@ static void __modes_service(void* pv)
ezlopi_core_modes_store_to_nvs();
- cJSON* cj_response = ezlopi_core_modes_cjson_changed();
- if (cj_response)
+ cJSON* cj_update = ezlopi_core_modes_cjson_changed();
+ if (cj_update)
{
- web_provisioning_send_to_nma_websocket(cj_response, TRACE_TYPE_I);
+ char* update_str = cJSON_Print(cj_update);
+ cJSON_Delete(cj_update);
+
+ if (update_str)
+ {
+ ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(update_str, TRACE_TYPE_I);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(update_str)) {
+ free(update_str);
+ }
+ }
}
}
}
diff --git a/ezlopi-services/ezlopi-service-ota/ezlopi_service_ota.c b/ezlopi-services/ezlopi-service-ota/ezlopi_service_ota.c
index 2259a2d93..01df87676 100644
--- a/ezlopi-services/ezlopi-service-ota/ezlopi_service_ota.c
+++ b/ezlopi-services/ezlopi-service-ota/ezlopi_service_ota.c
@@ -13,14 +13,15 @@
#include "ezlopi_service_ota.h"
#include "ezlopi_service_webprov.h"
+#include "ezlopi_core_ezlopi_broadcast.h"
-static void ota_service_process(void *pv);
+static void ota_service_process(void* pv);
void ota_service_init(void)
{
xTaskCreate(ota_service_process, "ota-service-process", 2 * 2048, NULL, 2, NULL);
}
-static void ota_service_process(void *pv)
+static void ota_service_process(void* pv)
{
ezlopi_wait_for_wifi_to_connect(portMAX_DELAY);
ezlopi_event_group_set_event(EZLOPI_EVENT_OTA);
@@ -35,19 +36,22 @@ static void ota_service_process(void *pv)
if ((-1 != ret_nma_reg) || (-1 != ret_ota))
{
TRACE_D("Sending firmware check request...");
- uint32_t message_counter = web_provisioning_get_message_count();
- cJSON *firmware_info_request = firmware_send_firmware_query_to_nma_server(message_counter);
+ uint32_t message_counter = ezlopi_service_web_provisioning_get_message_count();
+ cJSON* firmware_info_request = firmware_send_firmware_query_to_nma_server(message_counter);
if (NULL != firmware_info_request)
{
- char *data_to_send = cJSON_Print(firmware_info_request);
+ char* data_to_send = cJSON_Print(firmware_info_request);
cJSON_Delete(firmware_info_request);
firmware_info_request = NULL;
if (data_to_send)
{
cJSON_Minify(data_to_send);
- ret_ota = web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
- free(data_to_send);
+ ret_ota = ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, TRACE_TYPE_D);
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data_to_send))
+ {
+ free(data_to_send);
+ }
}
}
}
diff --git a/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c b/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c
index 41ff66ac2..c44e08a52 100644
--- a/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c
+++ b/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c
@@ -50,12 +50,12 @@ static const int RX_BUF_SIZE = 3096;
// cJson Types
static void ezlopi_service_uart_get_info();
-static void ezlopi_service_uart_set_wifi(const char *data);
+static void ezlopi_service_uart_set_wifi(const char* data);
static void ezlopi_service_uart_response(uint8_t cmd, uint8_t status_write, uint8_t status_connect);
-static void ezlopi_service_uart_save_config(const char *data);
+static void ezlopi_service_uart_save_config(const char* data);
static void ezlopi_service_uart_read_config(void);
-int EZPI_SERVICE_uart_tx_data(int len, uint8_t *data)
+int EZPI_SERVICE_uart_tx_data(int len, uint8_t* data)
{
int ret = 0;
// char start_bytes[] = {0x80, '\r', '\n'};
@@ -82,7 +82,7 @@ static void serial_init(void)
uart_set_pin(UART_NUM_0, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}
-static char *ezlopi_esp_reset_reason_str(esp_reset_reason_t reason)
+static char* ezlopi_esp_reset_reason_str(esp_reset_reason_t reason)
{
switch (reason)
{
@@ -125,7 +125,7 @@ static char *ezlopi_esp_reset_reason_str(esp_reset_reason_t reason)
}
}
-static char *ezlopi_chip_type_str(int chip_type)
+static char* ezlopi_chip_type_str(int chip_type)
{
switch (chip_type)
{
@@ -158,16 +158,16 @@ static int ezlopi_service_uart_execute_command_0(uint8_t sub_cmd)
case 0:
{
TRACE_E("Factory restore command");
- const static char *reboot_response = "{\"cmd\":0, \"sub_cmd\":0,\"status\":1}";
- EZPI_SERVICE_uart_tx_data(strlen(reboot_response), (uint8_t *)reboot_response);
+ const static char* reboot_response = "{\"cmd\":0, \"sub_cmd\":0,\"status\":1}";
+ EZPI_SERVICE_uart_tx_data(strlen(reboot_response), (uint8_t*)reboot_response);
EZPI_CORE_factory_restore();
break;
}
case 1:
{
TRACE_E("Reboot only command");
- const static char *reboot_response = "{\"cmd\":0, \"sub_cmd\":1, \"status\":1}";
- EZPI_SERVICE_uart_tx_data(strlen(reboot_response), (uint8_t *)reboot_response);
+ const static char* reboot_response = "{\"cmd\":0, \"sub_cmd\":1, \"status\":1}";
+ EZPI_SERVICE_uart_tx_data(strlen(reboot_response), (uint8_t*)reboot_response);
EZPI_CORE_reboot();
break;
}
@@ -179,9 +179,9 @@ static int ezlopi_service_uart_execute_command_0(uint8_t sub_cmd)
return ret;
}
-static int qt_serial_parse_rx_data(const char *data)
+static int qt_serial_parse_rx_data(const char* data)
{
- cJSON *root = cJSON_Parse(data);
+ cJSON* root = cJSON_Parse(data);
if (root)
{
@@ -239,11 +239,11 @@ static int qt_serial_parse_rx_data(const char *data)
return 1;
}
-static void ezlopi_service_uart_rx_task(void *arg)
+static void ezlopi_service_uart_rx_task(void* arg)
{
- static const char *RX_TASK_TAG = "RX_TASK";
+ static const char* RX_TASK_TAG = "RX_TASK";
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
- uint8_t *data = (uint8_t *)malloc(RX_BUF_SIZE + 1);
+ uint8_t* data = (uint8_t*)malloc(RX_BUF_SIZE + 1);
memset(data, 0, RX_BUF_SIZE + 1);
while (1)
@@ -254,7 +254,7 @@ static void ezlopi_service_uart_rx_task(void *arg)
{
data[rxBytes] = 0;
TRACE_I("%s", data);
- qt_serial_parse_rx_data((const char *)data);
+ qt_serial_parse_rx_data((const char*)data);
}
}
@@ -264,26 +264,26 @@ static void ezlopi_service_uart_rx_task(void *arg)
static void ezlopi_service_uart_get_info()
{
- cJSON *get_info = cJSON_CreateObject();
+ cJSON* get_info = cJSON_CreateObject();
if (get_info)
{
unsigned long long serial_id = ezlopi_factory_info_v3_get_id();
- char *controller_uuid = ezlopi_factory_info_v3_get_device_uuid();
- char *provisioning_uuid = ezlopi_factory_info_v3_get_provisioning_uuid();
- char *device_model = ezlopi_factory_info_v3_get_model();
- char *device_brand = ezlopi_factory_info_v3_get_brand();
- char *device_manufacturer = ezlopi_factory_info_v3_get_manufacturer();
- char *device_name = ezlopi_factory_info_v3_get_name();
- char *device_type = ezlopi_factory_info_v3_get_device_type();
- char *device_mac = ezlopi_factory_info_v3_get_ezlopi_mac();
- char *wifi_ssid = ezlopi_factory_info_v3_get_ssid();
+ char* controller_uuid = ezlopi_factory_info_v3_get_device_uuid();
+ char* provisioning_uuid = ezlopi_factory_info_v3_get_provisioning_uuid();
+ char* device_model = ezlopi_factory_info_v3_get_model();
+ char* device_brand = ezlopi_factory_info_v3_get_brand();
+ char* device_manufacturer = ezlopi_factory_info_v3_get_manufacturer();
+ char* device_name = ezlopi_factory_info_v3_get_name();
+ char* device_type = ezlopi_factory_info_v3_get_device_type();
+ char* device_mac = ezlopi_factory_info_v3_get_ezlopi_mac();
+ char* wifi_ssid = ezlopi_factory_info_v3_get_ssid();
cJSON_AddNumberToObject(get_info, "cmd", 1);
cJSON_AddStringToObject(get_info, "firmware_version", VERSION_STR);
cJSON_AddNumberToObject(get_info, "build", BUILD);
- cJSON *json_chip_info = cJSON_CreateObject();
+ cJSON* json_chip_info = cJSON_CreateObject();
if (json_chip_info)
{
esp_chip_info_t chip_info;
@@ -315,11 +315,11 @@ static void ezlopi_service_uart_get_info()
cJSON_AddStringToObject(get_info, ezlopi_manf_name_str, device_manufacturer ? device_manufacturer : "");
cJSON_AddStringToObject(get_info, ezlopi_model_num_str, device_model ? device_model : "");
- cJSON *json_net_info = cJSON_CreateObject();
+ cJSON* json_net_info = cJSON_CreateObject();
if (json_net_info)
{
- s_ezlopi_net_status_t *net_stat = ezlopi_get_net_status();
+ s_ezlopi_net_status_t* net_stat = ezlopi_get_net_status();
cJSON_AddStringToObject(json_net_info, "wifi_mode", "STA");
if (net_stat)
{
@@ -327,7 +327,7 @@ static void ezlopi_service_uart_get_info()
{
cJSON_AddTrueToObject(json_net_info, "wifi_connection_status");
- char *ip_addr = (char *)malloc(sizeof(char) * 30);
+ char* ip_addr = (char*)malloc(sizeof(char) * 30);
ip_addr = esp_ip4addr_ntoa(&net_stat->wifi_status->ip_info->ip, ip_addr, 30);
cJSON_AddStringToObject(json_net_info, "ip_sta", ip_addr);
@@ -369,20 +369,20 @@ static void ezlopi_service_uart_get_info()
cJSON_AddItemToObject(get_info, "net_info", json_net_info);
}
- ezlopi_factory_info_v3_free((void *)controller_uuid);
- ezlopi_factory_info_v3_free((void *)provisioning_uuid);
- ezlopi_factory_info_v3_free((void *)device_model);
- ezlopi_factory_info_v3_free((void *)device_brand);
- ezlopi_factory_info_v3_free((void *)device_manufacturer);
- ezlopi_factory_info_v3_free((void *)device_name);
- ezlopi_factory_info_v3_free((void *)device_mac);
- ezlopi_factory_info_v3_free((void *)wifi_ssid);
+ ezlopi_factory_info_v3_free((void*)controller_uuid);
+ ezlopi_factory_info_v3_free((void*)provisioning_uuid);
+ ezlopi_factory_info_v3_free((void*)device_model);
+ ezlopi_factory_info_v3_free((void*)device_brand);
+ ezlopi_factory_info_v3_free((void*)device_manufacturer);
+ ezlopi_factory_info_v3_free((void*)device_name);
+ ezlopi_factory_info_v3_free((void*)device_mac);
+ ezlopi_factory_info_v3_free((void*)wifi_ssid);
- char *serial_data_json_string = cJSON_Print(get_info);
+ char* serial_data_json_string = cJSON_Print(get_info);
if (serial_data_json_string)
{
cJSON_Minify(serial_data_json_string);
- EZPI_SERVICE_uart_tx_data(strlen(serial_data_json_string), (uint8_t *)serial_data_json_string);
+ EZPI_SERVICE_uart_tx_data(strlen(serial_data_json_string), (uint8_t*)serial_data_json_string);
cJSON_free(serial_data_json_string);
}
@@ -390,20 +390,20 @@ static void ezlopi_service_uart_get_info()
}
}
-static void ezlopi_service_uart_set_wifi(const char *data)
+static void ezlopi_service_uart_set_wifi(const char* data)
{
uint32_t status = 0;
- cJSON *root = cJSON_Parse(data);
+ cJSON* root = cJSON_Parse(data);
uint8_t status_write = 0;
if (root)
{
- cJSON *cj_wifi_ssid = cJSON_GetObjectItem(root, ezlopi_ssid_str);
- cJSON *cj_wifi_pass = cJSON_GetObjectItem(root, ezlopi_pass_str);
+ cJSON* cj_wifi_ssid = cJSON_GetObjectItem(root, ezlopi_ssid_str);
+ cJSON* cj_wifi_pass = cJSON_GetObjectItem(root, ezlopi_pass_str);
if (cj_wifi_ssid && cj_wifi_pass && cj_wifi_ssid->valuestring && cj_wifi_pass->valuestring)
{
- char *ssid = cj_wifi_ssid->valuestring;
- char *pass = cj_wifi_pass->valuestring;
+ char* ssid = cj_wifi_ssid->valuestring;
+ char* pass = cj_wifi_pass->valuestring;
if (strlen(pass) >= EZLOPI_WIFI_MIN_PASS_CHAR)
{
@@ -412,13 +412,13 @@ static void ezlopi_service_uart_set_wifi(const char *data)
{
status_write = 1;
}
- ezlopi_wifi_set_new_wifi_flag();
+ // ezlopi_wifi_set_new_wifi_flag();
uint8_t attempt = 1;
while (attempt <= EZLOPI_WIFI_CONN_RETRY_ATTEMPT)
{
- ezlopi_wifi_connect((const char *)ssid, (const char *)pass);
+ ezlopi_wifi_connect((const char*)ssid, (const char*)pass);
ezlopi_wait_for_wifi_to_connect((uint32_t)EZLOPI_WIFI_CONN_ATTEMPT_INTERVAL);
- s_ezlopi_net_status_t *net_stat = ezlopi_get_net_status();
+ s_ezlopi_net_status_t* net_stat = ezlopi_get_net_status();
if (net_stat)
{
if (net_stat->wifi_status->wifi_connection)
@@ -455,7 +455,7 @@ static void ezlopi_service_uart_set_wifi(const char *data)
static void ezlopi_service_uart_response(uint8_t cmd, uint8_t status_write, uint8_t status_connect)
{
- cJSON *response = NULL;
+ cJSON* response = NULL;
response = cJSON_CreateObject();
if (response)
@@ -464,22 +464,22 @@ static void ezlopi_service_uart_response(uint8_t cmd, uint8_t status_write, uint
cJSON_AddNumberToObject(response, ezlopi_status_write_str, status_write);
cJSON_AddNumberToObject(response, "status_connect", status_connect);
- char *my_json_string = cJSON_Print(response);
+ char* my_json_string = cJSON_Print(response);
cJSON_Delete(response); // free Json string
if (my_json_string)
{
cJSON_Minify(my_json_string);
- EZPI_SERVICE_uart_tx_data(strlen(my_json_string), (uint8_t *)my_json_string);
+ EZPI_SERVICE_uart_tx_data(strlen(my_json_string), (uint8_t*)my_json_string);
cJSON_free(my_json_string);
}
}
}
-static void ezlopi_service_uart_save_config(const char *data)
+static void ezlopi_service_uart_save_config(const char* data)
{
- uint8_t ret = ezlopi_nvs_write_config_data_str((char *)data);
+ uint8_t ret = ezlopi_nvs_write_config_data_str((char*)data);
TRACE_I("ezlopi_factory_info_set_ezlopi_config: %d", ret);
if (ret)
{
@@ -491,8 +491,8 @@ static void ezlopi_service_uart_save_config(const char *data)
static void ezlopi_service_uart_read_config(void)
{
- cJSON *root = NULL;
- char *buf = ezlopi_factory_info_v3_get_ezlopi_config();
+ cJSON* root = NULL;
+ char* buf = ezlopi_factory_info_v3_get_ezlopi_config();
if (buf)
{
@@ -531,14 +531,14 @@ static void ezlopi_service_uart_read_config(void)
if (root)
{
- char *my_json_string = cJSON_Print(root);
+ char* my_json_string = cJSON_Print(root);
if (my_json_string)
{
cJSON_Minify(my_json_string);
cJSON_Delete(root); // free Json string
const int len = strlen(my_json_string);
- EZPI_SERVICE_uart_tx_data(len, (uint8_t *)my_json_string); // Send the data over uart
+ EZPI_SERVICE_uart_tx_data(len, (uint8_t*)my_json_string); // Send the data over uart
// TRACE_D("Sending: %s", my_json_string);
cJSON_free(my_json_string);
}
diff --git a/ezlopi-services/ezlopi-service-webprov/CMakeLists.txt b/ezlopi-services/ezlopi-service-webprov/CMakeLists.txt
index 547cc62b4..c000d469d 100644
--- a/ezlopi-services/ezlopi-service-webprov/CMakeLists.txt
+++ b/ezlopi-services/ezlopi-service-webprov/CMakeLists.txt
@@ -2,28 +2,15 @@
file(GLOB_RECURSE provisioning_src "*.c*")
set(EZLOPI_CORE_COMPONENTS
- ezlopi-core-factory-info
ezlopi-core-wifi
- ezlopi-core-websocket_client
ezlopi-core-http
+ ezlopi-core-ezlopi
+ ezlopi-core-event-group
+ ezlopi-core-factory-info
+ ezlopi-core-websocket_client
)
set(EZLOPI_CLOUD_COMPONENTS
- ezlopi-cloud-data
- ezlopi-cloud-devices
- ezlopi-cloud-scenes
- ezlopi-cloud-registration
- ezlopi-cloud-favorite
- ezlopi-cloud-gateways
- ezlopi-cloud-info
- ezlopi-cloud-modes
- ezlopi-cloud-items
- ezlopi-cloud-room
- ezlopi-cloud-settings
- ezlopi-cloud-network
- ezlopi-cloud-ota
- ezlopi-cloud-location
- ezlopi-cloud-coordinates
)
diff --git a/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c b/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c
index 8d61d1b16..6b8c0f991 100644
--- a/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c
+++ b/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c
@@ -1,36 +1,20 @@
-#include "esp_mac.h"
-#include "esp_wifi_types.h"
-#include "esp_idf_version.h"
+#include
+#include
+#include
+#include
+#include
#include "ezlopi_util_trace.h"
+#include "ezlopi_cloud_constants.h"
-#include "ezlopi_core_wifi.h"
#include "ezlopi_core_http.h"
-#include "ezlopi_core_factory_info.h"
+#include "ezlopi_core_wifi.h"
#include "ezlopi_core_event_group.h"
+#include "ezlopi_core_factory_info.h"
+#include "ezlopi_core_ezlopi_methods.h"
#include "ezlopi_core_websocket_client.h"
-#include "ezlopi_cloud_data.h"
-#include "ezlopi_cloud_devices.h"
-#include "ezlopi_cloud_scenes.h"
-#include "ezlopi_cloud_registration.h"
-#include "ezlopi_cloud_favorite.h"
-#include "ezlopi_cloud_gateways.h"
-#include "ezlopi_cloud_info.h"
-#include "ezlopi_cloud_modes.h"
-#include "ezlopi_cloud_modes_updaters.h"
-#include "ezlopi_cloud_items.h"
-#include "ezlopi_cloud_room.h"
-#include "ezlopi_cloud_network.h"
-#include "ezlopi_cloud_ota.h"
-#include "ezlopi_cloud_settings.h"
-#include "ezlopi_cloud_constants.h"
-#include "ezlopi_cloud_scenes_scripts.h"
-#include "ezlopi_cloud_scenes_expressions.h"
-#include "ezlopi_cloud_location.h"
-#include "ezlopi_cloud_coordinates.h"
-
#include "ezlopi_service_webprov.h"
static uint32_t message_counter = 0;
@@ -38,35 +22,20 @@ static xTaskHandle _task_handle = NULL;
static TaskHandle_t ezlopi_update_config_notifier = NULL;
+static void __config_check(void* pv);
+static void __fetch_wss_endpoint(void* pv);
static void __connection_upcall(bool connected);
+static void __hub_reboot(cJSON* cj_request, cJSON* cj_response);
static void __message_upcall(const char* payload, uint32_t len);
static void __rpc_method_notfound(cJSON* cj_request, cJSON* cj_response);
-static void __hub_reboot(cJSON* cj_request, cJSON* cj_response);
-static void __fetch_wss_endpoint(void* pv);
-static void web_provisioning_config_check(void* pv);
static void __print_sending_data(char* data_str, e_trace_type_t print_type);
-typedef void (*f_method_func_t)(cJSON* cj_request, cJSON* cj_response);
-typedef struct s_method_list_v2
-{
- char* method_name;
- f_method_func_t method;
- f_method_func_t updater;
-} s_method_list_v2_t;
-
-static const s_method_list_v2_t method_list_v2[] = {
-#define CLOUD_METHOD(name, func, updater_func) {.method_name = name, .method = func, .updater = updater_func},
-#include "ezlopi_api_url_macros.h"
-#undef CLOUD_METHOD
- {.method_name = NULL, .method = NULL, .updater = NULL},
-};
-
-uint32_t web_provisioning_get_message_count(void)
+uint32_t ezlopi_service_web_provisioning_get_message_count(void)
{
return message_counter;
}
-int web_provisioning_send_str_data_to_nma_websocket(char* str_data, e_trace_type_t print_type)
+int ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(char* str_data, e_trace_type_t print_type)
{
int ret = 0;
if (str_data)
@@ -95,7 +64,7 @@ int web_provisioning_send_str_data_to_nma_websocket(char* str_data, e_trace_type
return ret;
}
-int web_provisioning_send_to_nma_websocket(cJSON* cjson_data, e_trace_type_t print_type)
+int ezlopi_service_web_provisioning_send_to_nma_websocket(cJSON* cjson_data, e_trace_type_t print_type)
{
int ret = 0;
if (ezlopi_websocket_client_is_connected())
@@ -136,9 +105,9 @@ int web_provisioning_send_to_nma_websocket(cJSON* cjson_data, e_trace_type_t pri
return ret;
}
-void web_provisioning_init(void)
+void ezlopi_service_web_provisioning_init(void)
{
- xTaskCreate(web_provisioning_config_check, "web-provisioning config check", 4 * 2048, NULL, 5, NULL);
+ xTaskCreate(__config_check, "web-provisioning config check", 4 * 2048, NULL, 5, NULL);
xTaskCreate(__fetch_wss_endpoint, "web-provisioning fetch wss endpoint", 3 * 2048, NULL, 5, &ezlopi_update_config_notifier);
}
@@ -179,7 +148,8 @@ static uint8_t web_provisioning_config_update(void* arg)
if (NULL != cJSON_uuid)
{
- const char* uuid = cJSON_uuid->valuestring;
+ #warning "Lomas need to check this"
+ const char* uuid = cJSON_uuid->valuestring;
TRACE_I("uuid: %s", uuid);
config_check_factoryInfo->device_uuid = (char*)uuid;
}
@@ -190,7 +160,8 @@ static uint8_t web_provisioning_config_update(void* arg)
if (NULL != cJSON_cloud_uuid)
{
- const char* cloud_uuid = cJSON_cloud_uuid->valuestring;
+ #warning "Lomas need to check this"
+ const char* cloud_uuid = cJSON_cloud_uuid->valuestring;
TRACE_S("cloud_uuid: %s", cloud_uuid);
config_check_factoryInfo->prov_uuid = cloud_uuid;
}
@@ -319,7 +290,7 @@ static uint8_t web_provisioning_config_update(void* arg)
return ret;
}
-static void web_provisioning_config_check(void* pv)
+static void __config_check(void* pv)
{
uint8_t flag_break_loop = 0;
static uint8_t retry_count = 0;
@@ -423,7 +394,7 @@ static void web_provisioning_config_check(void* pv)
vTaskDelete(NULL);
}
-void web_provisioning_deinit(void)
+void ezlopi_service_web_provisioning_deinit(void)
{
if (_task_handle)
{
@@ -504,7 +475,7 @@ static void __connection_upcall(bool connected)
{
TRACE_S("Web-socket re-connected.");
TRACE_I("Starting registration process....");
- registration_init();
+ ezlopi_core_ezlopi_methods_registration_init();
}
}
else
@@ -515,32 +486,11 @@ static void __connection_upcall(bool connected)
prev_status = connected;
}
-static uint32_t __search_method_in_list(cJSON* method)
-{
- uint32_t found_method = 0;
- uint32_t idx = 0;
-
- while (method_list_v2[idx].method_name)
- {
- uint32_t request_method_name_len = strlen(method->valuestring);
- uint32_t list_method_name_len = strlen(method_list_v2[idx].method_name);
- uint32_t comp_len = list_method_name_len > request_method_name_len ? list_method_name_len : request_method_name_len;
- if (0 == strncmp(method->valuestring, method_list_v2[idx].method_name, comp_len))
- {
- found_method = 1;
- break;
- }
- idx++;
- }
-
- return (found_method ? idx : UINT32_MAX);
-}
-
static void __call_method_and_send_response(cJSON* cj_request, cJSON* cj_method, f_method_func_t method_func, e_trace_type_t print_type)
{
if (method_func)
{
- if (registered == method_func)
+ if (ezlopi_core_elzlopi_methods_check_method_register(method_func))
{
method_func(cj_request, NULL);
}
@@ -563,7 +513,7 @@ static void __call_method_and_send_response(cJSON* cj_request, cJSON* cj_method,
if (data_to_send)
{
cJSON_Minify(data_to_send);
- web_provisioning_send_str_data_to_nma_websocket(data_to_send, print_type);
+ ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(data_to_send, print_type);
free(data_to_send);
}
}
@@ -590,17 +540,28 @@ static void __message_upcall(const char* payload, uint32_t len)
{
TRACE_S("## WS Rx <<<<<<<<<< '%s'\r\n%.*s", (cj_method->valuestring ? cj_method->valuestring : ezlopi__str), len, payload);
- uint32_t method_idx = __search_method_in_list(cj_method);
+ uint32_t method_id = ezlopi_core_ezlopi_methods_search_in_list(cj_method);
- if (UINT32_MAX != method_idx)
+ if (UINT32_MAX != method_id)
{
- TRACE_D("Method[%d]: %s", method_idx, method_list_v2[method_idx].method_name);
- __call_method_and_send_response(cj_request, cj_method, method_list_v2[method_idx].method, TRACE_TYPE_D);
- __call_method_and_send_response(cj_request, cj_method, method_list_v2[method_idx].updater, TRACE_TYPE_D);
+ char* method_name = ezlopi_core_ezlopi_methods_get_name_by_id(method_id);
+ TRACE_D("Method[%d]: %s", method_id, method_name ? method_name : "null");
+
+ f_method_func_t method = ezlopi_core_ezlopi_methods_get_by_id(method_id);
+ if (method)
+ {
+ __call_method_and_send_response(cj_request, cj_method, method, TRACE_TYPE_D);
+ }
+
+ f_method_func_t updater = ezlopi_core_ezlopi_methods_get_updater_by_id(method_id);
+ if (updater)
+ {
+ __call_method_and_send_response(cj_request, cj_method, updater, TRACE_TYPE_D);
+ }
}
else
{
- __call_method_and_send_response(cj_request, cj_method, __rpc_method_notfound, TRACE_TYPE_E);
+ __call_method_and_send_response(cj_request, cj_method, ezlopi_core_ezlopi_methods_rpc_method_notfound, TRACE_TYPE_E);
}
}
}
@@ -614,27 +575,6 @@ static void __message_upcall(const char* payload, uint32_t len)
}
}
-static void __rpc_method_notfound(cJSON* cj_request, cJSON* cj_response)
-{
- cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str));
- cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str));
- cJSON* cjson_error = cJSON_AddObjectToObject(cj_response, ezlopi_error_str);
- if (cjson_error)
- {
- cJSON_AddNumberToObject(cjson_error, ezlopi_code_str, -32602);
- cJSON_AddStringToObject(cjson_error, ezlopi_data_str, ezlopi_rpc_method_notfound_str);
- cJSON_AddStringToObject(cjson_error, ezlopi_message_str, ezlopi_Unknown_method_str);
- }
-
- cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
-}
-
-static void __hub_reboot(cJSON* cj_request, cJSON* cj_response)
-{
- web_provisioning_deinit();
- esp_restart();
-}
-
static void __print_sending_data(char* data_str, e_trace_type_t print_type)
{
switch (print_type)
@@ -647,6 +587,7 @@ static void __print_sending_data(char* data_str, e_trace_type_t print_type)
case TRACE_TYPE_B:
{
TRACE_I("## WSS-SENDING >>>>>>>>>>>>>>>>>>>\r\n%s", data_str);
+ break;
}
case TRACE_TYPE_D:
{
diff --git a/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.h b/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.h
index f4da63f58..1e2ac478d 100644
--- a/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.h
+++ b/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.h
@@ -17,15 +17,15 @@ extern "C"
TRACE_TYPE_B,
TRACE_TYPE_D, // debug (White)
TRACE_TYPE_I, // Info (Blue)
- TRACE_TYPE_E // Error (Red)
+ TRACE_TYPE_E, // Error (Red)
+
} e_trace_type_t;
- void web_provisioning_init(void);
- void web_provisioning_deinit(void);
- uint32_t web_provisioning_get_message_count(void);
- char *parse_device_from_web_payload(void *ws_ctx, char *web_payload);
- int web_provisioning_send_to_nma_websocket(cJSON *cjson_data, e_trace_type_t print_type);
- int web_provisioning_send_str_data_to_nma_websocket(char *str_data, e_trace_type_t print_type);
+ void ezlopi_service_web_provisioning_init(void);
+ void ezlopi_service_web_provisioning_deinit(void);
+ uint32_t ezlopi_service_web_provisioning_get_message_count(void);
+ int ezlopi_service_web_provisioning_send_to_nma_websocket(cJSON* cjson_data, e_trace_type_t print_type);
+ int ezlopi_service_web_provisioning_send_str_data_to_nma_websocket(char* str_data, e_trace_type_t print_type);
#ifdef __cplusplus
}
diff --git a/ezlopi-services/ezlopi-service-ws-server/CMakeLists.txt b/ezlopi-services/ezlopi-service-ws-server/CMakeLists.txt
new file mode 100644
index 000000000..e3372d163
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-ws-server/CMakeLists.txt
@@ -0,0 +1,29 @@
+
+file(GLOB_RECURSE provisioning_src "*.c*")
+
+set(EZLOPI_UTIL_COMPONENTS
+ ezlopi-util-trace
+)
+
+set(SDK_COMPONENTS
+ esp_http_server
+)
+
+set(EZLOPI_CORE_COMPONENTS
+ ezlopi-core-wifi
+ ezlopi-core-ezlopi
+)
+
+set(EZLOPI_CLOUD_COMPONENTS
+
+)
+
+
+
+idf_component_register(SRCS "ezlopi_service_ws_server.c" "ezlopi_service_ws_server_clients.c" "${provisioning_src}"
+ INCLUDE_DIRS "."
+ REQUIRES ${SDK_COMPONENTS}
+ ${EZLOPI_CORE_COMPONENTS}
+ ${EZLOPI_UTIL_COMPONENTS}
+ ${EZLOPI_CLOUD_COMPONENTS}
+ )
diff --git a/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server.c b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server.c
new file mode 100644
index 000000000..14ae56542
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server.c
@@ -0,0 +1,564 @@
+/* WebSocket Echo Server Example
+
+ This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+ Unless required by applicable law or agreed to in writing, this
+ software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "../../build/config/sdkconfig.h"
+#include
+
+#include "ezlopi_util_trace.h"
+
+#include "ezlopi_cloud_constants.h"
+
+#include "ezlopi_core_wifi.h"
+#include "ezlopi_core_cjson_macros.h"
+#include "ezlopi_core_ezlopi_methods.h"
+#include "ezlopi_core_ezlopi_broadcast.h"
+
+#include "ezlopi_service_ws_server.h"
+#include "ezlopi_service_ws_server_clients.h"
+
+typedef enum e_trace_type
+{
+ TRACE_TYPE_NONE = 0,
+ TRACE_TYPE_W, // Warning (Orange)
+ TRACE_TYPE_B,
+ TRACE_TYPE_D, // debug (White)
+ TRACE_TYPE_I, // Info (Blue)
+ TRACE_TYPE_E // Error (Red)
+} e_trace_type_t;
+
+typedef struct s_async_resp_arg
+{
+ int fd;
+ httpd_handle_t hd;
+} s_async_resp_arg_t;
+
+static uint32_t message_counter = 0;
+static httpd_handle_t gs_ws_handle = NULL;
+static e_ws_status_t gs_ws_status = WS_STATUS_STOPPED;
+static SemaphoreHandle_t send_lock = NULL;
+
+static void __stop_server(void);
+static void __start_server(void);
+static void __wifi_connection_event(esp_event_base_t event, int32_t event_id, void* arg);
+
+static void __ws_async_send(void* arg);
+static esp_err_t __trigger_async_send(httpd_req_t* req);
+static int __respond_cjson(httpd_req_t* req, cJSON* cj_response);
+static int __ws_server_send(l_ws_server_client_conn_t* client, char* data, uint32_t len);
+
+static esp_err_t __msg_handler(httpd_req_t* req);
+static void __ws_api_handler(httpd_req_t* req, const char* payload, uint32_t payload_len);
+
+static void __print_sending_data(char* data_str, e_trace_type_t print_type);
+static cJSON* __method_execute(httpd_req_t* req, cJSON* cj_request, cJSON* cj_method, f_method_func_t method_func);
+
+e_ws_status_t ezlopi_service_ws_server_status(void)
+{
+ return gs_ws_status;
+}
+
+int ezlopi_service_ws_server_broadcast_cjson(cJSON* cj_data)
+{
+ int ret = 0;
+ if (cj_data)
+ {
+ char* data = cJSON_Print(cj_data);
+ if (data)
+ {
+ cJSON_Minify(data);
+ ezlopi_service_ws_server_broadcast(data);
+ free(data);
+ }
+ }
+
+ return ret;
+}
+
+int ezlopi_service_ws_server_broadcast(char* data)
+{
+ int ret = 0;
+
+ if (data)
+ {
+ l_ws_server_client_conn_t* curr_client = ezlopi_service_ws_server_clients_get_head();
+
+ while (curr_client)
+ {
+ ret = 1;
+ __ws_server_send(curr_client, data, strlen(data));
+ curr_client = curr_client->next;
+ }
+ }
+
+ return ret;
+}
+
+void ezlopi_service_ws_server_start(void)
+{
+ ezlopi_wifi_event_add(__wifi_connection_event, NULL);
+}
+
+void ezlopi_service_ws_server_stop(void)
+{
+ __stop_server();
+}
+
+static void __wifi_connection_event(esp_event_base_t event_base, int32_t event_id, void* arg)
+{
+ TRACE_D("event-base: %d, event-id: %d", (uint32_t)event_base, event_id);
+
+ if (IP_EVENT == event_base)
+ {
+ if (IP_EVENT_STA_GOT_IP == event_id)
+ {
+ __start_server();
+ }
+ else
+ {
+ __stop_server();
+ }
+ }
+ else if (WIFI_EVENT == event_base)
+ {
+ if (WIFI_EVENT_STA_DISCONNECTED == event_id)
+ {
+ __stop_server();
+ }
+ }
+}
+
+static void __ws_api_handler(httpd_req_t* req, const char* payload, uint32_t payload_len)
+{
+ if (payload && payload_len)
+ {
+ cJSON* cj_request = cJSON_ParseWithLength(payload, payload_len);
+ if (cj_request)
+ {
+ cJSON* cj_src = cJSON_AddObjectToObject(cj_request, ezlopi_source_str);
+ if (cj_src)
+ {
+ cJSON_AddNumberToObject(cj_src, ezlopi_type_str, 1);
+ cJSON_AddNumberToObject(cj_src, ezlopi_client_id_str, (uint32_t)req->handle);
+ }
+
+ cJSON* cj_error = cJSON_GetObjectItem(cj_request, ezlopi_error_str);
+ cJSON* cj_method = cJSON_GetObjectItem(cj_request, ezlopi_method_str);
+
+ if ((NULL == cj_error) || (cJSON_NULL == cj_error->type) || (NULL != cj_error->valuestring) ||
+ ((NULL != cj_error->valuestring) && (0 == strncmp(cj_error->valuestring, ezlopi_null_str, 4))))
+ {
+ if ((NULL != cj_method) && (NULL != cj_method->valuestring))
+ {
+ TRACE_S("## WS Rx <<<<<<<<<< '%s'\r\n%.*s", (cj_method->valuestring ? cj_method->valuestring : ezlopi__str), payload_len, payload);
+
+ uint32_t method_id = ezlopi_core_ezlopi_methods_search_in_list(cj_method);
+
+ if (UINT32_MAX != method_id)
+ {
+ f_method_func_t method = ezlopi_core_ezlopi_methods_get_by_id(method_id);
+
+ if (method)
+ {
+ cJSON* cj_response = __method_execute(req, cj_request, cj_method, method);
+ if (cj_response)
+ {
+ __respond_cjson(req, cj_response);
+ cJSON_Delete(cj_response);
+ }
+ }
+
+ f_method_func_t updater = ezlopi_core_ezlopi_methods_get_updater_by_id(method_id);
+
+ if (updater)
+ {
+ cJSON* cj_response = __method_execute(req, cj_request, cj_method, updater);
+ if (cj_response)
+ {
+ char* data = cJSON_Print(cj_response);
+ cJSON_Delete(cj_response);
+
+ if (data) {
+ if (0 == ezlopi_core_ezlopi_broadcast_methods_send_to_queue(data)) {
+ free(data);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ cJSON* cj_response = __method_execute(req, cj_request, cj_method, ezlopi_core_ezlopi_methods_rpc_method_notfound);
+ if (cj_response)
+ {
+ __respond_cjson(req, cj_response);
+ cJSON_Delete(cj_response);
+ }
+ }
+ }
+ }
+ else
+ {
+ TRACE_E("## WS Rx <<<<<<<<<< '%s'\r\n%.*s", (NULL != cj_method) ? (cj_method->valuestring ? cj_method->valuestring : ezlopi__str) : ezlopi__str, payload_len, payload);
+ TRACE_E("cj_error: %p, cj_error->type: %u, cj_error->value_string: %s", cj_error, cj_error->type, cj_error ? (cj_error->valuestring ? cj_error->valuestring : ezlopi_null_str) : ezlopi_null_str);
+ }
+
+ cJSON_Delete(cj_request);
+ }
+ else
+ {
+ TRACE_W("Invalid json packet!");
+ }
+ }
+}
+
+static void __ws_async_send(void* arg)
+{
+ static const char* data = "Async data";
+ s_async_resp_arg_t* resp_arg = (s_async_resp_arg_t*)arg;
+
+ if (resp_arg)
+ {
+ httpd_ws_frame_t ws_pkt;
+ memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
+
+ ws_pkt.len = strlen(data);
+ ws_pkt.payload = (uint8_t*)data;
+ ws_pkt.type = HTTPD_WS_TYPE_TEXT;
+
+ httpd_ws_send_frame_async(resp_arg->hd, resp_arg->fd, &ws_pkt);
+ free(resp_arg);
+ }
+}
+
+static esp_err_t __trigger_async_send(httpd_req_t* req)
+{
+ esp_err_t ret = ESP_OK;
+ s_async_resp_arg_t* resp_arg = malloc(sizeof(s_async_resp_arg_t));
+
+ if (resp_arg)
+ {
+ resp_arg->hd = req->handle;
+ resp_arg->fd = httpd_req_to_sockfd(req);
+ ret = httpd_queue_work(req->handle, __ws_async_send, resp_arg);
+ }
+
+ return ret;
+}
+
+static esp_err_t __msg_handler(httpd_req_t* req)
+{
+ esp_err_t ret = ESP_OK;
+
+ if (req->method == HTTP_GET)
+ {
+ TRACE_I("Handshake done, the new connection was opened, id: %p", req);
+ ezlopi_service_ws_server_clients_add((void*)req->handle, httpd_req_to_sockfd(req));
+ }
+ else
+ {
+ uint8_t* buf = NULL;
+ httpd_ws_frame_t ws_pkt;
+
+ memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
+ ws_pkt.type = HTTPD_WS_TYPE_TEXT;
+
+ ret = httpd_ws_recv_frame(req, &ws_pkt, 0);
+
+ if ((ESP_OK == ret) && (0 < ws_pkt.len))
+ {
+ TRACE_I("frame len is %d", ws_pkt.len);
+ buf = malloc(ws_pkt.len + 1);
+
+ if (NULL != buf)
+ {
+ ws_pkt.payload = buf;
+ ret = httpd_ws_recv_frame(req, &ws_pkt, ws_pkt.len);
+
+ if (ESP_OK == ret)
+ {
+ TRACE_D("Packet type: %d", ws_pkt.type);
+
+ if ((HTTPD_WS_TYPE_TEXT == ws_pkt.type) && (0 == strcmp((char*)ws_pkt.payload, "Trigger async")))
+ {
+ ret = __trigger_async_send(req);
+ }
+ else if (HTTPD_WS_TYPE_TEXT == ws_pkt.type)
+ {
+ __ws_api_handler(req, (char*)ws_pkt.payload, (uint32_t)ws_pkt.len);
+ }
+ else if (HTTPD_WS_TYPE_CLOSE == ws_pkt.type)
+ {
+ TRACE_D("closing connection!");
+ ezlopi_service_ws_server_clients_remove_by_handle(req);
+ }
+ else
+ {
+ TRACE_W("packet type un-handled!");
+ }
+ }
+ else
+ {
+ TRACE_E("httpd_ws_recv_frame failed with %d", ret);
+ }
+
+ free(buf);
+ }
+ else
+ {
+ TRACE_E("malloc failed!");
+ ret = ESP_ERR_NO_MEM;
+ }
+ }
+ else
+ {
+ TRACE_E("httpd_ws_recv_frame failed to get frame len with %d", ret);
+ }
+ }
+
+ return ret;
+}
+
+static void __start_server(void)
+{
+ send_lock = xSemaphoreCreateMutex();
+ if (send_lock)
+ {
+ static const httpd_uri_t ws = {
+ .uri = "/ws",
+ .method = HTTP_GET,
+ .handler = __msg_handler,
+ .user_ctx = NULL,
+ .is_websocket = true,
+ .handle_ws_control_frames = true,
+ };
+
+ httpd_config_t config = HTTPD_DEFAULT_CONFIG();
+ config.task_priority = 8;
+ config.stack_size = 1024 * 4;
+
+ TRACE_I("Starting ws-server on port: '%d'", config.server_port);
+
+ esp_err_t err = httpd_start(&gs_ws_handle, &config);
+
+ if (ESP_OK == err)
+ {
+ TRACE_I("Registering URI handlers");
+ if (ESP_OK == httpd_register_uri_handler(gs_ws_handle, &ws))
+ {
+ gs_ws_status = WS_STATUS_RUNNING;
+ }
+ }
+ else
+ {
+ TRACE_E("Error starting server!, err: %d", err);
+ }
+
+ ezlopi_core_ezlopi_broadcast_method_add(ezlopi_service_ws_server_broadcast, 2);
+ }
+}
+
+static void __stop_server(void)
+{
+ if (gs_ws_handle)
+ {
+ TRACE_E("stopping ws-server!");
+ httpd_stop(gs_ws_handle);
+ gs_ws_handle = NULL;
+ gs_ws_status = WS_STATUS_STOPPED;
+ }
+
+ if (send_lock)
+ {
+ vSemaphoreDelete(send_lock);
+ send_lock = NULL;
+ }
+
+ ezlopi_core_ezlopi_broadcast_remove_method(ezlopi_service_ws_server_broadcast);
+}
+
+static cJSON* __method_execute(httpd_req_t* req, cJSON* cj_request, cJSON* cj_method, f_method_func_t method_func)
+{
+ cJSON* cj_response = NULL;
+ if (method_func)
+ {
+ if (ezlopi_core_elzlopi_methods_check_method_register(method_func))
+ {
+ method_func(cj_request, NULL);
+ }
+ else
+ {
+ cj_response = cJSON_CreateObject();
+ if (NULL != cj_response)
+ {
+ cJSON_AddNumberToObject(cj_response, ezlopi_msg_id_str, message_counter);
+ cJSON_AddItemReferenceToObject(cj_response, ezlopi_sender_str, cJSON_GetObjectItem(cj_request, ezlopi_sender_str));
+ cJSON_AddNullToObject(cj_response, ezlopi_error_str);
+
+ method_func(cj_request, cj_response);
+ }
+ else
+ {
+ TRACE_E("Error - cj_response: %d", (uint32_t)cj_response);
+ }
+ }
+ }
+
+ return cj_response;
+}
+
+static int __respond_cjson(httpd_req_t* req, cJSON* cj_response)
+{
+ int ret = 0;
+ if (req && cj_response && send_lock)
+ {
+ if (xSemaphoreTake(send_lock, 2000 / portTICK_PERIOD_MS))
+ {
+ TRACE_S("ws-server send-lock acquired.");
+
+ char* data = cJSON_Print(cj_response);
+ if (data)
+ {
+ cJSON_Minify(data);
+
+ httpd_ws_frame_t data_frame = {
+ .final = false,
+ .fragmented = false,
+ .len = strlen(data),
+ .payload = (uint8_t*)data,
+ .type = HTTPD_WS_TYPE_TEXT,
+ };
+
+ ret = (ESP_OK == httpd_ws_send_frame(req, &data_frame)) ? true : false;
+
+ if (ret)
+ {
+ __print_sending_data(data, TRACE_TYPE_D);
+ }
+ else
+ {
+ __print_sending_data(data, TRACE_TYPE_E);
+ }
+
+ free(data);
+ }
+
+ xSemaphoreGive(send_lock);
+ TRACE_S("ws-server send-lock released.");
+ }
+ else
+ {
+ TRACE_E("send-lock acquired failed!");
+ }
+ }
+
+ return ret;
+}
+
+static int __ws_server_send(l_ws_server_client_conn_t* client, char* data, uint32_t len)
+{
+ int ret = 0;
+ if (data && len && client && client->http_handle && send_lock)
+ {
+ if (pdTRUE == xSemaphoreTake(send_lock, 2000 / portTICK_PERIOD_MS))
+ {
+ TRACE_S("ws-server send-lock acquired.");
+
+ httpd_ws_frame_t frm_pkt;
+ memset(&frm_pkt, 0, sizeof(httpd_ws_frame_t));
+
+ frm_pkt.len = strlen(data);
+ frm_pkt.payload = (uint8_t*)data;
+ frm_pkt.type = HTTPD_WS_TYPE_TEXT;
+
+ TRACE_D("client-handle: %p", client->http_handle);
+ TRACE_D("client-desc: %d", client->http_descriptor);
+ TRACE_D("data[%d]: %.*s", frm_pkt.len, frm_pkt.len, frm_pkt.payload);
+
+ if (ESP_OK == httpd_ws_send_data(client->http_handle, client->http_descriptor, &frm_pkt))
+ {
+ ret = 1;
+ client->fail_count = 0;
+
+ TRACE_S("Done");
+ __print_sending_data((char*)frm_pkt.payload, TRACE_TYPE_D);
+ }
+ else
+ {
+ TRACE_E("Failed!");
+
+ ret = 0;
+ client->fail_count += 1;
+ __print_sending_data((char*)frm_pkt.payload, TRACE_TYPE_E);
+
+ if (client->fail_count > 5)
+ {
+ ezlopi_service_ws_server_clients_remove_by_handle(client->http_handle);
+ }
+ }
+
+ xSemaphoreGive(send_lock);
+ TRACE_S("ws-server send-lock released.");
+ }
+ else
+ {
+ TRACE_E("ws-server send-lock failed!");
+ }
+ }
+
+ return ret;
+}
+
+static void __print_sending_data(char* data_str, e_trace_type_t print_type)
+{
+ switch (print_type)
+ {
+ case TRACE_TYPE_W:
+ {
+ TRACE_W("## WSS-SENDING >>>>>>>>>>>>>>>>>>>\r\n%s", data_str);
+ break;
+ }
+ case TRACE_TYPE_B:
+ {
+ TRACE_I("## WSS-SENDING >>>>>>>>>>>>>>>>>>>\r\n%s", data_str);
+ break;
+ }
+ case TRACE_TYPE_D:
+ {
+ TRACE_D("## WSS-SENDING >>>>>>>>>>>>>>>>>>>\r\n%s", data_str);
+ break;
+ }
+ case TRACE_TYPE_E:
+ {
+ TRACE_E("## WSS-SENDING >>>>>>>>>>>>>>>>>>>\r\n%s", data_str);
+ break;
+ }
+ case TRACE_TYPE_I:
+ {
+ TRACE_S("## WSS-SENDING >>>>>>>>>>\r\n%s", data_str);
+ break;
+ }
+ default:
+ {
+ TRACE_E("## WSS-SENDING >>>>>>>>>>\r\n%s", data_str);
+ break;
+ }
+ }
+}
diff --git a/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server.h b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server.h
new file mode 100644
index 000000000..d86b06875
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server.h
@@ -0,0 +1,23 @@
+#ifndef __EZLOPI_SERVICE_WS_SERVER_H__
+#define __EZLOPI_SERVICE_WS_SERVER_H__
+
+#include
+#include "ezlopi_service_ws_server_clients.h"
+
+typedef enum e_ws_status
+{
+ WS_STATUS_RUNNING = 0,
+ WS_STATUS_STOPPED,
+} e_ws_status_t;
+
+void ezlopi_service_ws_server_stop(void);
+void ezlopi_service_ws_server_start(void);
+
+e_ws_status_t ezlopi_service_ws_server_status(void);
+
+int ezlopi_service_ws_server_send_cjson(cJSON *cj_data);
+
+int ezlopi_service_ws_server_broadcast(char *data);
+int ezlopi_service_ws_server_broadcast_cjson(cJSON *cj_data);
+
+#endif // __EZLOPI_SERVICE_WS_SERVER_H__
\ No newline at end of file
diff --git a/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server_clients.c b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server_clients.c
new file mode 100644
index 000000000..55a6e03fd
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server_clients.c
@@ -0,0 +1,134 @@
+#include
+#include
+
+#include "ezlopi_service_ws_server.h"
+#include "ezlopi_service_ws_server_clients.h"
+
+static l_ws_server_client_conn_t *l_client_conn_head = NULL;
+
+static l_ws_server_client_conn_t *__create_client_conn(void);
+
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_get_head(void)
+{
+ return l_client_conn_head;
+}
+
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_get_by_handle(void *http_handle)
+{
+ l_ws_server_client_conn_t *curr_client = l_client_conn_head;
+ while (curr_client)
+ {
+ if (curr_client->http_handle == http_handle)
+ {
+ break;
+ }
+ curr_client = curr_client->next;
+ }
+
+ return curr_client;
+}
+
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_add(void *http_handle, int http_descriptor)
+{
+ l_ws_server_client_conn_t *ws_client_conn = NULL;
+ if (l_client_conn_head)
+ {
+ if (l_client_conn_head->http_handle != http_handle)
+ {
+ uint32_t dup_flag = 0;
+ l_ws_server_client_conn_t *curr_conn = l_client_conn_head;
+ while (curr_conn->next)
+ {
+ if (curr_conn->next->http_handle == http_handle)
+ {
+ dup_flag = 1;
+ break;
+ }
+ curr_conn = curr_conn->next;
+ }
+
+ if (0 == dup_flag)
+ {
+ ws_client_conn = __create_client_conn();
+ if (ws_client_conn)
+ {
+ curr_conn->next = ws_client_conn;
+ ws_client_conn->http_handle = http_handle;
+ ws_client_conn->http_descriptor = http_descriptor;
+ }
+ }
+ }
+ }
+ else
+ {
+ ws_client_conn = __create_client_conn();
+ if (ws_client_conn)
+ {
+ l_client_conn_head = ws_client_conn;
+ ws_client_conn->http_handle = http_handle;
+ ws_client_conn->http_descriptor = http_descriptor;
+ }
+ }
+
+ return ws_client_conn;
+}
+
+int ezlopi_service_ws_server_clients_remove_by_handle(void *http_handle)
+{
+ int ret = 0;
+
+ if (http_handle)
+ {
+ l_ws_server_client_conn_t *ws_popped_con = ezlopi_service_ws_server_clients_pop(http_handle);
+ if (ws_popped_con)
+ {
+ free(ws_popped_con);
+ }
+ }
+
+ return ret;
+}
+
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_pop(void *http_handle)
+{
+ l_ws_server_client_conn_t *pop_con = NULL;
+
+ if (http_handle == l_client_conn_head->http_handle)
+ {
+ pop_con = l_client_conn_head;
+ l_client_conn_head = l_client_conn_head->next;
+ pop_con->next = NULL;
+ }
+ else
+ {
+ l_ws_server_client_conn_t *curr_conn = l_client_conn_head;
+ while (curr_conn->next)
+ {
+ if (curr_conn->next->http_handle == http_handle)
+ {
+ pop_con = curr_conn->next;
+ curr_conn->next = curr_conn->next->next;
+ pop_con->next = NULL;
+ break;
+ }
+
+ curr_conn = curr_conn->next;
+ }
+ }
+
+ return pop_con;
+}
+
+static l_ws_server_client_conn_t *__create_client_conn(void)
+{
+ l_ws_server_client_conn_t *new_ws_conn = malloc(sizeof(l_ws_server_client_conn_t));
+ if (new_ws_conn)
+ {
+ new_ws_conn->fail_count = 0;
+ new_ws_conn->http_handle = NULL;
+ new_ws_conn->http_descriptor = 0;
+ new_ws_conn->next = NULL;
+ }
+
+ return new_ws_conn;
+}
diff --git a/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server_clients.h b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server_clients.h
new file mode 100644
index 000000000..bbda95223
--- /dev/null
+++ b/ezlopi-services/ezlopi-service-ws-server/ezlopi_service_ws_server_clients.h
@@ -0,0 +1,19 @@
+#ifndef __EZLOPI_SERVICE_WS_SERVER_CLIENTS_H__
+#define __EZLOPI_SERVICE_WS_SERVER_CLIENTS_H__
+
+typedef struct l_ws_server_client_conn
+{
+ void *http_handle;
+ int http_descriptor;
+ uint32_t fail_count;
+
+ struct l_ws_server_client_conn *next;
+} l_ws_server_client_conn_t;
+
+int ezlopi_service_ws_server_clients_remove_by_handle(void *http_handle);
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_get_head(void);
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_pop(void *http_handle);
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_get_by_handle(void *http_handle);
+l_ws_server_client_conn_t *ezlopi_service_ws_server_clients_add(void *http_handle, int http_desc);
+
+#endif // __EZLOPI_SERVICE_WS_SERVER_CLIENTS_H__
\ No newline at end of file
diff --git a/ezlopi-user-config/EZLOPI_USER_CONFIG.h b/ezlopi-user-config/EZLOPI_USER_CONFIG.h
index d6d674cf5..50aa50f06 100644
--- a/ezlopi-user-config/EZLOPI_USER_CONFIG.h
+++ b/ezlopi-user-config/EZLOPI_USER_CONFIG.h
@@ -8,7 +8,7 @@
// User Configs
#define EZPI_USR_CONFIG_ENABLE_HEARTBIT_LED
#define EZPI_USR_CONFIG_ENABLE_LOG
-#define EZPI_DEV_TYPE_GENERIC
+#define EZPI_DEV_TYPE_GENERIC 1
// Util
#define EZPI_UTIL_ENABLE_TRACE
@@ -31,6 +31,7 @@
#undef EZPI_USR_CONFIG_ENABLE_HEARTBIT_LED
#undef EZPI_CORE_ENABLE_ETH
+// #undef EZPI_DEV_TYPE_GENERIC
// #undef EZPI_SERV_ENABLE_MESHBOTS
// #undef EZPI_UTIL_ENABLE_TRACE
diff --git a/ezlopi-util/ezlopi-util-trace/ezlopi_util_trace.h b/ezlopi-util/ezlopi-util-trace/ezlopi_util_trace.h
index c4a4732d0..41b586b79 100644
--- a/ezlopi-util/ezlopi-util-trace/ezlopi_util_trace.h
+++ b/ezlopi-util/ezlopi-util-trace/ezlopi_util_trace.h
@@ -64,14 +64,14 @@ extern "C"
// printf("\x1B[34m %s[%d]:" X "\x1B[0m\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
// }
-#define trace_bg(bg, txt, X, reg...) \
+#define TRACE_Dg(bg, txt, X, reg...) \
{ \
printf("\x1B[%s;%sm %s[%d]:" X "\x1B[0m\r\n", txt, bg, __FILE__, __LINE__, ##reg); \
}
-#define trace_bw(X, reg...) trace_bg(COLOR_BG_BLACK, COLOR_FONT_WHITE, X, ##reg)
-#define trace_yw(X, reg...) trace_bg(COLOR_BG_YELLOW, COLOR_FONT_WHITE, X, ##reg)
-#define trace_wb(X, reg...) trace_bg(COLOR_BG_WHITE, COLOR_FONT_BLACK, X, ##reg)
+#define TRACE_Dw(X, reg...) TRACE_Dg(COLOR_BG_BLACK, COLOR_FONT_WHITE, X, ##reg)
+#define trace_yw(X, reg...) TRACE_Dg(COLOR_BG_YELLOW, COLOR_FONT_WHITE, X, ##reg)
+#define trace_wb(X, reg...) TRACE_Dg(COLOR_BG_WHITE, COLOR_FONT_BLACK, X, ##reg)
#define F(X) (flash_attr) X
diff --git a/ezlopi-util/ezlopi-util-uuid/CMakeLists.txt b/ezlopi-util/ezlopi-util-uuid/CMakeLists.txt
new file mode 100644
index 000000000..25bb8ac5f
--- /dev/null
+++ b/ezlopi-util/ezlopi-util-uuid/CMakeLists.txt
@@ -0,0 +1,7 @@
+# set(config_src "config.cpp")
+
+file(GLOB_RECURSE config_src "./*.c")
+
+idf_component_register(SRCS "ezlopi_util_uuid.c" "${config_src}"
+ INCLUDE_DIRS "."
+ REQUIRES )
\ No newline at end of file
diff --git a/ezlopi-util/ezlopi-util-uuid/component.mk b/ezlopi-util/ezlopi-util-uuid/component.mk
new file mode 100644
index 000000000..608de873e
--- /dev/null
+++ b/ezlopi-util/ezlopi-util-uuid/component.mk
@@ -0,0 +1,8 @@
+#
+# "main" pseudo-component makefile.
+#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
+
+
+COMPONENT_ADD_SRCDIRS := ..
+COMPONENT_ADD_INCLUDEDIRS := ..
\ No newline at end of file
diff --git a/ezlopi-util/ezlopi-util-uuid/ezlopi_util_uuid.c b/ezlopi-util/ezlopi-util-uuid/ezlopi_util_uuid.c
new file mode 100644
index 000000000..72db41483
--- /dev/null
+++ b/ezlopi-util/ezlopi-util-uuid/ezlopi_util_uuid.c
@@ -0,0 +1,110 @@
+#include
+#include
+
+// #include "config.h"
+#include "ezlopi_util_uuid.h"
+
+const unsigned char hex[16] = "0123456789abcdef";
+
+static int __hex2dec(char c);
+
+void ezlopi_util_uuid_generate_random(ezlopi_uuid_t out)
+{
+ int i, j, rnd;
+ static int seeded = 0;
+
+ if (!seeded)
+ {
+ srand(time(NULL));
+ seeded = 1;
+ }
+
+ for (i = 0; i < (16 / RAND_LENGTH); i++)
+ {
+ rnd = rand();
+
+ for (j = 0; j < RAND_LENGTH; j++)
+ {
+ out[i * RAND_LENGTH + j] = (0xff & rnd >> (8 * j));
+ }
+ }
+
+ // set the version to 4
+ out[6] = (out[6] & 0x0f) | 0x40;
+
+ // set the variant to 1 (a)
+ out[8] = (out[8] & 0x0f) | 0xa0;
+}
+
+void ezlopi_util_uuid_parse(const char* in, ezlopi_uuid_t uuid)
+{
+ int i, j;
+
+ i = j = 0;
+
+ do
+ {
+ switch (in[i])
+ {
+ case '-':
+ {
+ break;
+ }
+ default:
+ {
+ uuid[j++] = (__hex2dec(in[i]) << 4) | __hex2dec(in[i + 1]);
+ }
+ }
+
+ i += 2;
+
+ } while (j < 16 && i < 36);
+}
+
+void ezlopi_util_uuid_unparse(const ezlopi_uuid_t uuid, char* out)
+{
+ int i, j;
+
+ i = j = 0;
+
+ do
+ {
+ switch (j)
+ {
+ case 4:
+ case 6:
+ case 8:
+ case 10:
+ out[i++] = '-';
+ }
+
+ out[i++] = hex[(uuid[j] >> 4)];
+ out[i++] = hex[(0xf & uuid[j])];
+
+ j++;
+ } while (j < 16);
+
+ out[36] = 0;
+}
+
+void ezlopi_util_uuid_copy(ezlopi_uuid_t dst, const ezlopi_uuid_t src)
+{
+ int i;
+ for (i = 0; i < sizeof(ezlopi_uuid_t); i++)
+ {
+ dst[i] = src[i];
+ }
+}
+
+static int __hex2dec(char c)
+{
+ int i;
+
+ for (i = 0; i < 16; i++)
+ {
+ if (hex[i] == c)
+ return i;
+ }
+
+ return -1;
+}
diff --git a/ezlopi-util/ezlopi-util-uuid/ezlopi_util_uuid.h b/ezlopi-util/ezlopi-util-uuid/ezlopi_util_uuid.h
new file mode 100644
index 000000000..8205acb7d
--- /dev/null
+++ b/ezlopi-util/ezlopi-util-uuid/ezlopi_util_uuid.h
@@ -0,0 +1,15 @@
+#ifndef __EZLOPI_UTIL_UUID_H__
+#define __EZLOPI_UTIL_UUID_H__
+
+#define RAND_LENGTH 4
+
+typedef unsigned char ezlopi_uuid_t[16];
+
+#define uuid_generate(out) ezlopi_util_uuid_generate_random(out)
+
+void ezlopi_util_uuid_generate_random(ezlopi_uuid_t out);
+void ezlopi_util_uuid_unparse(const ezlopi_uuid_t uuid, char *out);
+void ezlopi_util_uuid_copy(ezlopi_uuid_t dst, const ezlopi_uuid_t src);
+void ezlopi_util_uuid_parse(const char *in, ezlopi_uuid_t uuid);
+
+#endif // __EZLOPI_UTIL_UUID_H__
\ No newline at end of file
diff --git a/ezlopi-util/ezlopi-util-version/CMakeLists.txt b/ezlopi-util/ezlopi-util-version/CMakeLists.txt
index 615e56a08..a92951b35 100644
--- a/ezlopi-util/ezlopi-util-version/CMakeLists.txt
+++ b/ezlopi-util/ezlopi-util-version/CMakeLists.txt
@@ -1,4 +1,4 @@
-file(GLOB_RECURSE config_src "src/*.c*")
+file(GLOB_RECURSE config_src "*.c*")
idf_component_register(SRCS "${config_src}"
INCLUDE_DIRS ".")
\ No newline at end of file
diff --git a/ezlopi-util/ezlopi-util-version/ezlopi_util_version.h b/ezlopi-util/ezlopi-util-version/ezlopi_util_version.h
index a7b103823..8319c7f5b 100644
--- a/ezlopi-util/ezlopi-util-version/ezlopi_util_version.h
+++ b/ezlopi-util/ezlopi-util-version/ezlopi_util_version.h
@@ -1,25 +1,27 @@
-#ifndef _EZLOPI_UTIL_VERSION_H_
-#define _EZLOPI_UTIL_VERSION_H_
+#ifndef __VERSION_H__
+#define __VERSION_H__
+
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
-#define V_TYPE 2
-#define BUILD_DATE 1704990285
+
+#define BUILD_DATE 1709103460
#define MAJOR 3
#define MINOR 2
-#define BATCH 4
-#define BUILD 181
-#define VERSION_STR "3.2.4"
+#define BATCH 6
+#define BUILD 185
+#define VERSION_STR "3.2.6"
#define DEVELOPER "lomas.subedi@ezlo.com"
-#define COMPILE_TIME "Thu 11 Jan 2024 10:09:36 PM +0545"
-#define CURRENT_BRANCH "dev_v3"
-#define COMMIT_HASH "fd190843f60c1e5a93c738b3b0757e58870a01c2"
+#define COMPILE_TIME "Wed 28 Feb 2024 12:42:40 PM +0545"
+#define CURRENT_BRANCH "development"
+#define COMMIT_HASH "52b6e535c25867579f2969358cc4232076d0e337"
+
#ifdef __cplusplus
}
#endif
-#endif // _EZLOPI_UTIL_VERSION_H_
+
+#endif // __VERSION_H__
diff --git a/ezlopi_partitions_v3_1_4_181_8mb.csv b/ezlopi_partitions_v3_1_4_181_8mb.csv
new file mode 100644
index 000000000..314c7c8ad
--- /dev/null
+++ b/ezlopi_partitions_v3_1_4_181_8mb.csv
@@ -0,0 +1,8 @@
+# ESP32 Partition Table
+# Name, Type, SubType, Offset, Size, Flags
+nvs, data, nvs, 0x9000, 0xC000,
+otadata, data, ota, 0x15000, 0x2000,
+phy_init, data, phy, 0x17000, 0x1000,
+prov_data, 0x40, 0, 0x18000, 0x8000,
+ota0, app, ota_0, 0x20000, 0x2EFC00,
+ota1, app, ota_1, , 0x2EFC00,
diff --git a/sdkconfig b/sdkconfig
index e7e5b16ac..0afa2696a 100644
--- a/sdkconfig
+++ b/sdkconfig
@@ -4,9 +4,9 @@
#
CONFIG_IDF_CMAKE=y
CONFIG_IDF_TARGET_ARCH_XTENSA=y
-CONFIG_IDF_TARGET="esp32s3"
-CONFIG_IDF_TARGET_ESP32S3=y
-CONFIG_IDF_FIRMWARE_CHIP_ID=0x0009
+CONFIG_IDF_TARGET="esp32"
+CONFIG_IDF_TARGET_ESP32=y
+CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000
#
# SDK tool configuration
@@ -38,7 +38,7 @@ CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
#
# Bootloader config
#
-CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x0
+CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x1000
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set
@@ -70,48 +70,36 @@ CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
#
# Security features
#
-CONFIG_SECURE_BOOT_SUPPORTS_RSA=y
-CONFIG_SECURE_TARGET_HAS_SECURE_ROM_DL_MODE=y
# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set
# CONFIG_SECURE_BOOT is not set
# CONFIG_SECURE_FLASH_ENC_ENABLED is not set
# end of Security features
-#
-# Boot ROM Behavior
-#
-CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y
-# CONFIG_BOOT_ROM_LOG_ALWAYS_OFF is not set
-# CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH is not set
-# CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW is not set
-# end of Boot ROM Behavior
-
#
# Serial flasher config
#
CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200
# CONFIG_ESPTOOLPY_NO_STUB is not set
-# CONFIG_ESPTOOLPY_OCT_FLASH is not set
# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set
# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set
CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y
CONFIG_ESPTOOLPY_FLASHMODE="dio"
-# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
+# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
-CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
-# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
+# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
+CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
-CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
+CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_BEFORE_RESET=y
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
@@ -202,81 +190,51 @@ CONFIG_APPTRACE_LOCK_ENABLE=y
# Bluetooth
#
CONFIG_BT_ENABLED=y
-CONFIG_BT_SOC_SUPPORT_5_0=y
#
# Bluetooth controller
#
-CONFIG_BT_CTRL_MODE_EFF=1
-CONFIG_BT_CTRL_BLE_MAX_ACT=10
-CONFIG_BT_CTRL_BLE_MAX_ACT_EFF=10
-CONFIG_BT_CTRL_BLE_STATIC_ACL_TX_BUF_NB=0
-CONFIG_BT_CTRL_PINNED_TO_CORE_0=y
-# CONFIG_BT_CTRL_PINNED_TO_CORE_1 is not set
-CONFIG_BT_CTRL_PINNED_TO_CORE=0
-CONFIG_BT_CTRL_HCI_MODE_VHCI=y
-# CONFIG_BT_CTRL_HCI_MODE_UART_H4 is not set
-CONFIG_BT_CTRL_HCI_TL=1
-CONFIG_BT_CTRL_ADV_DUP_FILT_MAX=30
-CONFIG_BT_BLE_CCA_MODE_NONE=y
-# CONFIG_BT_BLE_CCA_MODE_HW is not set
-# CONFIG_BT_BLE_CCA_MODE_SW is not set
-CONFIG_BT_BLE_CCA_MODE=0
-CONFIG_BT_CTRL_HW_CCA_VAL=20
-CONFIG_BT_CTRL_HW_CCA_EFF=0
-CONFIG_BT_CTRL_CE_LENGTH_TYPE_ORIG=y
-# CONFIG_BT_CTRL_CE_LENGTH_TYPE_CE is not set
-# CONFIG_BT_CTRL_CE_LENGTH_TYPE_SD is not set
-CONFIG_BT_CTRL_CE_LENGTH_TYPE_EFF=0
-CONFIG_BT_CTRL_TX_ANTENNA_INDEX_0=y
-# CONFIG_BT_CTRL_TX_ANTENNA_INDEX_1 is not set
-CONFIG_BT_CTRL_TX_ANTENNA_INDEX_EFF=0
-CONFIG_BT_CTRL_RX_ANTENNA_INDEX_0=y
-# CONFIG_BT_CTRL_RX_ANTENNA_INDEX_1 is not set
-CONFIG_BT_CTRL_RX_ANTENNA_INDEX_EFF=0
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N24 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N21 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N18 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N15 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N12 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N9 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N6 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N3 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N0 is not set
-CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P3=y
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P6 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P9 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P12 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P15 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P18 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P21 is not set
-CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_EFF=9
-CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
-CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
-CONFIG_BT_CTRL_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
-CONFIG_BT_CTRL_BLE_SCAN_DUPL=y
-CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DEVICE=y
-# CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DATA is not set
-# CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DATA_DEVICE is not set
-CONFIG_BT_CTRL_SCAN_DUPL_TYPE=0
-CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE=100
-CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD=0
-# CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN is not set
-# CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EN is not set
-CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_DIS=y
-CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF=0
+CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
+# CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY is not set
+# CONFIG_BTDM_CTRL_MODE_BTDM is not set
+CONFIG_BTDM_CTRL_BLE_MAX_CONN=3
+CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF=0
+CONFIG_BTDM_CTRL_PCM_ROLE_EFF=0
+CONFIG_BTDM_CTRL_PCM_POLAR_EFF=0
+CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=3
+CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF=0
+CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF=0
+CONFIG_BTDM_CTRL_PINNED_TO_CORE_0=y
+# CONFIG_BTDM_CTRL_PINNED_TO_CORE_1 is not set
+CONFIG_BTDM_CTRL_PINNED_TO_CORE=0
+CONFIG_BTDM_CTRL_HCI_MODE_VHCI=y
+# CONFIG_BTDM_CTRL_HCI_MODE_UART_H4 is not set
#
# MODEM SLEEP Options
#
-# CONFIG_BT_CTRL_MODEM_SLEEP is not set
+CONFIG_BTDM_CTRL_MODEM_SLEEP=y
+CONFIG_BTDM_CTRL_MODEM_SLEEP_MODE_ORIG=y
+# CONFIG_BTDM_CTRL_MODEM_SLEEP_MODE_EVED is not set
+CONFIG_BTDM_CTRL_LPCLK_SEL_MAIN_XTAL=y
# end of MODEM SLEEP Options
-CONFIG_BT_CTRL_SLEEP_MODE_EFF=0
-CONFIG_BT_CTRL_SLEEP_CLOCK_EFF=0
-CONFIG_BT_CTRL_HCI_TL_EFF=1
-# CONFIG_BT_CTRL_AGC_RECORRECT_EN is not set
-# CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX is not set
+CONFIG_BTDM_BLE_DEFAULT_SCA_250PPM=y
+CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF=1
+CONFIG_BTDM_BLE_SCAN_DUPL=y
+CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE=y
+# CONFIG_BTDM_SCAN_DUPL_TYPE_DATA is not set
+# CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE is not set
+CONFIG_BTDM_SCAN_DUPL_TYPE=0
+CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=100
+CONFIG_BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD=0
+# CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN is not set
+CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED=y
+CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
+CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
+CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
+CONFIG_BTDM_RESERVE_DRAM=0xdb5c
+CONFIG_BTDM_CTRL_HLI=y
# end of Bluetooth controller
CONFIG_BT_BLUEDROID_ENABLED=y
@@ -292,6 +250,7 @@ CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0=y
CONFIG_BT_BLUEDROID_PINNED_TO_CORE=0
CONFIG_BT_BTU_TASK_STACK_SIZE=4096
# CONFIG_BT_BLUEDROID_MEM_DEBUG is not set
+# CONFIG_BT_CLASSIC_ENABLED is not set
CONFIG_BT_BLE_ENABLED=y
CONFIG_BT_GATTS_ENABLE=y
# CONFIG_BT_GATTS_PPCP_CHAR_GAP is not set
@@ -306,7 +265,6 @@ CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set
CONFIG_BT_GATTC_ENABLE=y
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
-CONFIG_BT_GATTC_NOTIF_REG_MAX=5
# CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set
CONFIG_BT_GATTC_CONNECT_RETRY_COUNT=3
CONFIG_BT_BLE_SMP_ENABLE=y
@@ -488,16 +446,15 @@ CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=2
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BT_MULTI_CONNECTION_ENBALE=y
-# CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST is not set
+CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
# CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY is not set
# CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK is not set
CONFIG_BT_SMP_ENABLE=y
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
+# CONFIG_BT_BLE_RPA_SUPPORTED is not set
CONFIG_BT_BLE_RPA_TIMEOUT=900
-CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y
-CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
# CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL is not set
# end of Bluedroid Options
# end of Bluetooth
@@ -522,7 +479,6 @@ CONFIG_COAP_LOG_DEFAULT_LEVEL=0
#
# CONFIG_ADC_FORCE_XPD_FSM is not set
CONFIG_ADC_DISABLE_DAC=y
-# CONFIG_ADC_CONTINUOUS_FORCE_USE_ADC2_ON_C3_S3 is not set
# end of ADC configuration
#
@@ -544,15 +500,31 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
# TWAI configuration
#
# CONFIG_TWAI_ISR_IN_IRAM is not set
+# CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC is not set
+# CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST is not set
+# CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID is not set
+# CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT is not set
# CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM is not set
# end of TWAI configuration
#
# UART configuration
#
-# CONFIG_UART_ISR_IN_IRAM is not set
+CONFIG_UART_ISR_IN_IRAM=y
# end of UART configuration
+#
+# RTCIO configuration
+#
+# CONFIG_RTCIO_SUPPORT_RTC_GPIO_DESC is not set
+# end of RTCIO configuration
+
+#
+# GPIO Configuration
+#
+# CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL is not set
+# end of GPIO Configuration
+
#
# GDMA Configuration
#
@@ -566,14 +538,17 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
#
# CONFIG_EFUSE_CUSTOM_TABLE is not set
# CONFIG_EFUSE_VIRTUAL is not set
-CONFIG_EFUSE_MAX_BLK_LEN=256
+# CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE is not set
+CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4=y
+# CONFIG_EFUSE_CODE_SCHEME_COMPAT_REPEAT is not set
+CONFIG_EFUSE_MAX_BLK_LEN=192
# end of eFuse Bit Manager
#
# ESP-TLS
#
CONFIG_ESP_TLS_USING_MBEDTLS=y
-CONFIG_ESP_TLS_USE_DS_PERIPHERAL=y
+# CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set
# CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS is not set
# CONFIG_ESP_TLS_SERVER is not set
# CONFIG_ESP_TLS_PSK_VERIFICATION is not set
@@ -581,80 +556,68 @@ CONFIG_ESP_TLS_USE_DS_PERIPHERAL=y
# end of ESP-TLS
#
-# ESP32S3-Specific
+# ESP32-specific
#
-CONFIG_ESP32S3_REV_MIN_0=y
-# CONFIG_ESP32S3_REV_MIN_1 is not set
-# CONFIG_ESP32S3_REV_MIN_2 is not set
-CONFIG_ESP32S3_REV_MIN_FULL=0
+CONFIG_ESP32_REV_MIN_0=y
+# CONFIG_ESP32_REV_MIN_1 is not set
+# CONFIG_ESP32_REV_MIN_1_1 is not set
+# CONFIG_ESP32_REV_MIN_2 is not set
+# CONFIG_ESP32_REV_MIN_3 is not set
+# CONFIG_ESP32_REV_MIN_3_1 is not set
+CONFIG_ESP32_REV_MIN=0
+CONFIG_ESP32_REV_MIN_FULL=0
CONFIG_ESP_REV_MIN_FULL=0
-CONFIG_ESP32S3_REV_MAX_FULL_STR_OPT=y
-CONFIG_ESP32S3_REV_MAX_FULL=99
-CONFIG_ESP_REV_MAX_FULL=99
-# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_80 is not set
-# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160 is not set
-CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
-CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=240
-
-#
-# Cache config
-#
-CONFIG_ESP32S3_INSTRUCTION_CACHE_16KB=y
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB is not set
-CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE=0x4000
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_4WAYS is not set
-CONFIG_ESP32S3_INSTRUCTION_CACHE_8WAYS=y
-CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS=8
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_16B is not set
-CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_32B=y
-CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE=32
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_WRAP is not set
-# CONFIG_ESP32S3_DATA_CACHE_16KB is not set
-CONFIG_ESP32S3_DATA_CACHE_32KB=y
-# CONFIG_ESP32S3_DATA_CACHE_64KB is not set
-CONFIG_ESP32S3_DATA_CACHE_SIZE=0x8000
-# CONFIG_ESP32S3_DATA_CACHE_4WAYS is not set
-CONFIG_ESP32S3_DATA_CACHE_8WAYS=y
-CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS=8
-# CONFIG_ESP32S3_DATA_CACHE_LINE_16B is not set
-CONFIG_ESP32S3_DATA_CACHE_LINE_32B=y
-# CONFIG_ESP32S3_DATA_CACHE_LINE_64B is not set
-CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE=32
-# CONFIG_ESP32S3_DATA_CACHE_WRAP is not set
-# end of Cache config
-
-# CONFIG_ESP32S3_SPIRAM_SUPPORT is not set
-# CONFIG_ESP32S3_TRAX is not set
-CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM=0x0
-# CONFIG_ESP32S3_ULP_COPROC_ENABLED is not set
-CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=0
-CONFIG_ESP32S3_DEBUG_OCDAWARE=y
-CONFIG_ESP32S3_BROWNOUT_DET=y
-CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_7=y
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_6 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_5 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_4 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_3 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_2 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_1 is not set
-CONFIG_ESP32S3_BROWNOUT_DET_LVL=7
-CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC_FRC1=y
-# CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC is not set
-# CONFIG_ESP32S3_TIME_SYSCALL_USE_FRC1 is not set
-# CONFIG_ESP32S3_TIME_SYSCALL_USE_NONE is not set
-CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y
-# CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS is not set
-# CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC is not set
-# CONFIG_ESP32S3_RTC_CLK_SRC_INT_8MD256 is not set
-CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=1024
-CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000
-# CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM is not set
-# CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE is not set
-# end of ESP32S3-Specific
+CONFIG_ESP32_REV_MAX_FULL_STR_OPT=y
+CONFIG_ESP32_REV_MAX_FULL=399
+CONFIG_ESP_REV_MAX_FULL=399
+CONFIG_ESP32_DPORT_WORKAROUND=y
+# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set
+CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y
+# CONFIG_ESP32_DEFAULT_CPU_FREQ_240 is not set
+CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160
+# CONFIG_ESP32_SPIRAM_SUPPORT is not set
+# CONFIG_ESP32_TRAX is not set
+CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0
+# CONFIG_ESP32_ULP_COPROC_ENABLED is not set
+CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=0
+CONFIG_ESP32_DEBUG_OCDAWARE=y
+CONFIG_ESP32_BROWNOUT_DET=y
+CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_1 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_2 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_3 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_4 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_5 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_6 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set
+CONFIG_ESP32_BROWNOUT_DET_LVL=0
+CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
+# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
+# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
+# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set
+CONFIG_ESP32_RTC_CLK_SRC_INT_RC=y
+# CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS is not set
+# CONFIG_ESP32_RTC_CLK_SRC_EXT_OSC is not set
+# CONFIG_ESP32_RTC_CLK_SRC_INT_8MD256 is not set
+CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024
+CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000
+CONFIG_ESP32_XTAL_FREQ_40=y
+# CONFIG_ESP32_XTAL_FREQ_26 is not set
+# CONFIG_ESP32_XTAL_FREQ_AUTO is not set
+CONFIG_ESP32_XTAL_FREQ=40
+# CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE is not set
+# CONFIG_ESP32_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set
+# CONFIG_ESP32_COMPATIBLE_PRE_V3_1_BOOTLOADERS is not set
+# CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE is not set
+CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL=5
+# end of ESP32-specific
#
# ADC-Calibration
#
+CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y
+CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y
+CONFIG_ADC_CAL_LUT_ENABLE=y
# end of ADC-Calibration
#
@@ -667,6 +630,14 @@ CONFIG_ESP_ERR_TO_NAME_LOOKUP=y
# Ethernet
#
CONFIG_ETH_ENABLED=y
+CONFIG_ETH_USE_ESP32_EMAC=y
+CONFIG_ETH_PHY_INTERFACE_RMII=y
+CONFIG_ETH_RMII_CLK_INPUT=y
+# CONFIG_ETH_RMII_CLK_OUTPUT is not set
+CONFIG_ETH_RMII_CLK_IN_GPIO=0
+CONFIG_ETH_DMA_BUFFER_SIZE=512
+CONFIG_ETH_DMA_RX_BUFFER_NUM=10
+CONFIG_ETH_DMA_TX_BUFFER_NUM=10
CONFIG_ETH_USE_SPI_ETHERNET=y
# CONFIG_ETH_SPI_ETHERNET_DM9051 is not set
CONFIG_ETH_SPI_ETHERNET_W5500=y
@@ -703,7 +674,7 @@ CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
# CONFIG_HTTPD_LOG_PURGE_DATA is not set
-# CONFIG_HTTPD_WS_SUPPORT is not set
+CONFIG_HTTPD_WS_SUPPORT=y
# end of HTTP Server
#
@@ -729,9 +700,10 @@ CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y
-# CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO is not set
-CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_FOUR=y
-CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES=4
+# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set
+CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y
+CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4
+# CONFIG_ESP_MAC_IGNORE_MAC_CRC_ERROR is not set
# end of MAC Config
#
@@ -741,13 +713,11 @@ CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
# CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND is not set
-CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y
# end of Sleep Config
#
# RTC Clock Config
#
-CONFIG_RTC_CLOCK_BBPLL_POWER_ON_WITH_USB=y
# end of RTC Clock Config
# end of Hardware Settings
@@ -767,7 +737,6 @@ CONFIG_ESP_IPC_ISR_ENABLE=y
# LCD Peripheral Configuration
#
CONFIG_LCD_PANEL_IO_FORMAT_BUF_SIZE=32
-# CONFIG_LCD_RGB_ISR_IRAM_SAFE is not set
# end of LCD Peripheral Configuration
# end of LCD and Touch Panel
@@ -788,7 +757,6 @@ CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y
CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20
CONFIG_ESP_PHY_MAX_TX_POWER=20
# CONFIG_ESP_PHY_REDUCE_TX_POWER is not set
-CONFIG_ESP_PHY_ENABLE_USB=y
CONFIG_ESP_PHY_RF_CAL_PARTIAL=y
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
# CONFIG_ESP_PHY_RF_CAL_FULL is not set
@@ -799,8 +767,6 @@ CONFIG_ESP_PHY_CALIBRATION_MODE=0
# Power Management
#
# CONFIG_PM_ENABLE is not set
-CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
-CONFIG_PM_POWER_DOWN_TAGMEM_IN_LIGHT_SLEEP=y
# end of Power Management
#
@@ -818,8 +784,6 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y
# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set
# CONFIG_ESP_SYSTEM_PANIC_GDBSTUB is not set
# CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set
-CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK=y
-CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y
#
# Memory protection
@@ -835,12 +799,8 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
-# CONFIG_ESP_CONSOLE_USB_CDC is not set
-# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
# CONFIG_ESP_CONSOLE_NONE is not set
-# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set
-CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
CONFIG_ESP_CONSOLE_UART=y
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y
CONFIG_ESP_CONSOLE_UART_NUM=0
@@ -855,7 +815,7 @@ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_ESP_PANIC_HANDLER_IRAM is not set
# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set
-CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_4=y
+CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5=y
# end of ESP System Settings
#
@@ -867,7 +827,8 @@ CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER=y
CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584
CONFIG_ESP_TIMER_INTERRUPT_LEVEL=1
# CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD is not set
-CONFIG_ESP_TIMER_IMPL_SYSTIMER=y
+# CONFIG_ESP_TIMER_IMPL_FRC2 is not set
+CONFIG_ESP_TIMER_IMPL_TG0_LAC=y
# end of High resolution timer (esp_timer)
#
@@ -891,13 +852,11 @@ CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
-CONFIG_ESP32_WIFI_IRAM_OPT=y
-CONFIG_ESP32_WIFI_RX_IRAM_OPT=y
+# CONFIG_ESP32_WIFI_IRAM_OPT is not set
+# CONFIG_ESP32_WIFI_RX_IRAM_OPT is not set
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
# CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set
-# CONFIG_ESP_WIFI_FTM_ENABLE is not set
# CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is not set
-# CONFIG_ESP_WIFI_GCMP_SUPPORT is not set
# CONFIG_ESP_WIFI_GMAC_SUPPORT is not set
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y
# CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT is not set
@@ -983,10 +942,10 @@ CONFIG_FMB_EVENT_QUEUE_TIMEOUT=20
#
# CONFIG_FREERTOS_UNICORE is not set
CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF
-CONFIG_FREERTOS_TICK_SUPPORT_SYSTIMER=y
-CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL1=y
-# CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL3 is not set
-CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER=y
+CONFIG_FREERTOS_TICK_SUPPORT_CORETIMER=y
+CONFIG_FREERTOS_CORETIMER_0=y
+# CONFIG_FREERTOS_CORETIMER_1 is not set
+CONFIG_FREERTOS_SYSTICK_USES_CCOUNT=y
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set
@@ -1015,6 +974,7 @@ CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
CONFIG_FREERTOS_DEBUG_OCDAWARE=y
+# CONFIG_FREERTOS_FPU_IN_ISR is not set
CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT=y
# CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH is not set
# end of FreeRTOS
@@ -1080,12 +1040,11 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
#
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
# CONFIG_LWIP_NETIF_API is not set
-CONFIG_LWIP_TCPIP_TASK_PRIO=18
# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
# CONFIG_LWIP_L2_TO_L3_COPY is not set
-CONFIG_LWIP_IRAM_OPTIMIZATION=y
+# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
CONFIG_LWIP_TIMERS_ONDEMAND=y
CONFIG_LWIP_MAX_SOCKETS=10
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
@@ -1242,6 +1201,7 @@ CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y
# mbedTLS v2.28.x related
#
# CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set
+CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT=y
# CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set
# CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set
# end of mbedTLS v2.28.x related
@@ -1257,10 +1217,9 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=200
# end of Certificate Bundle
-# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
-# CONFIG_MBEDTLS_CMAC_C is not set
+CONFIG_MBEDTLS_ECP_RESTARTABLE=y
+CONFIG_MBEDTLS_CMAC_C=y
CONFIG_MBEDTLS_HARDWARE_AES=y
-CONFIG_MBEDTLS_AES_USE_INTERRUPT=y
CONFIG_MBEDTLS_HARDWARE_MPI=y
CONFIG_MBEDTLS_HARDWARE_SHA=y
CONFIG_MBEDTLS_ROM_MD5=y
@@ -1440,7 +1399,6 @@ CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
# CONFIG_SPI_FLASH_VERIFY_WRITE is not set
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
-# CONFIG_SPI_FLASH_ROM_IMPL is not set
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set
@@ -1464,7 +1422,6 @@ CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=y
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=y
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=y
-CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP=y
# end of Auto-detect flash chips
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=y
@@ -1518,12 +1475,6 @@ CONFIG_WS_BUFFER_SIZE=1024
# end of Websocket
# end of TCP Transport
-#
-# TinyUSB Stack
-#
-# CONFIG_TINYUSB is not set
-# end of TinyUSB Stack
-
#
# Unity unit testing library
#
@@ -1536,24 +1487,10 @@ CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y
# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set
# end of Unity unit testing library
-#
-# USB-OTG
-#
-CONFIG_USB_OTG_SUPPORTED=y
-CONFIG_USB_HOST_CONTROL_TRANSFER_MAX_SIZE=256
-CONFIG_USB_HOST_HW_BUFFER_BIAS_BALANCED=y
-# CONFIG_USB_HOST_HW_BUFFER_BIAS_IN is not set
-# CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT is not set
-
#
# Root Hub configuration
#
-CONFIG_USB_HOST_DEBOUNCE_DELAY_MS=250
-CONFIG_USB_HOST_RESET_HOLD_MS=30
-CONFIG_USB_HOST_RESET_RECOVERY_MS=30
-CONFIG_USB_HOST_SET_ADDR_RECOVERY_MS=10
# end of Root Hub configuration
-# end of USB-OTG
#
# Virtual file system
@@ -1665,6 +1602,28 @@ CONFIG_STACK_CHECK_NONE=y
# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set
CONFIG_ESP32_APPTRACE_DEST_NONE=y
CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
+CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=y
+# CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY is not set
+# CONFIG_BTDM_CONTROLLER_MODE_BTDM is not set
+CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN=3
+CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=3
+CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=0
+CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0
+CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0
+CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y
+# CONFIG_BTDM_CONTROLLER_HCI_MODE_UART_H4 is not set
+CONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y
+CONFIG_BLE_SCAN_DUPLICATE=y
+CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR=y
+# CONFIG_SCAN_DUPLICATE_BY_ADV_DATA is not set
+# CONFIG_SCAN_DUPLICATE_BY_ADV_DATA_AND_DEVICE_ADDR is not set
+CONFIG_SCAN_DUPLICATE_TYPE=0
+CONFIG_DUPLICATE_SCAN_CACHE_SIZE=100
+# CONFIG_BLE_MESH_SCAN_DUPLICATE_EN is not set
+CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
+CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
+CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM=100
+CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
CONFIG_BLUEDROID_ENABLED=y
# CONFIG_NIMBLE_ENABLED is not set
CONFIG_BTC_TASK_STACK_SIZE=3072
@@ -1673,6 +1632,7 @@ CONFIG_BLUEDROID_PINNED_TO_CORE_0=y
CONFIG_BLUEDROID_PINNED_TO_CORE=0
CONFIG_BTU_TASK_STACK_SIZE=4096
# CONFIG_BLUEDROID_MEM_DEBUG is not set
+# CONFIG_CLASSIC_BT_ENABLED is not set
CONFIG_GATTS_ENABLE=y
# CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set
CONFIG_GATTS_SEND_SERVICE_CHANGE_AUTO=y
@@ -1847,9 +1807,32 @@ CONFIG_SMP_ENABLE=y
# CONFIG_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY is not set
CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30
CONFIG_ADC2_DISABLE_DAC=y
+# CONFIG_SPIRAM_SUPPORT is not set
+CONFIG_TRACEMEM_RESERVE_DRAM=0x0
+# CONFIG_ULP_COPROC_ENABLED is not set
+CONFIG_ULP_COPROC_RESERVE_MEM=0
+CONFIG_BROWNOUT_DET=y
+CONFIG_BROWNOUT_DET_LVL_SEL_0=y
+# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set
+CONFIG_BROWNOUT_DET_LVL=0
+CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
+# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set
+# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC is not set
+# CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_8MD256 is not set
+# CONFIG_DISABLE_BASIC_ROM_CONSOLE is not set
+# CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set
# CONFIG_EVENT_LOOP_PROFILING is not set
CONFIG_POST_EVENTS_FROM_ISR=y
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
+# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
+CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
+CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
CONFIG_ESP_SYSTEM_PD_FLASH=y
CONFIG_ESP32C3_LIGHTSLEEP_GPIO_RESET_WORKAROUND=y
CONFIG_IPC_TASK_STACK_SIZE=1536
@@ -1858,12 +1841,10 @@ CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20
CONFIG_ESP32_PHY_MAX_TX_POWER=20
# CONFIG_ESP32_REDUCE_PHY_TX_POWER is not set
-CONFIG_ESP_SYSTEM_PM_POWER_DOWN_CPU=y
# CONFIG_ESP32S2_PANIC_PRINT_HALT is not set
CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y
# CONFIG_ESP32S2_PANIC_SILENT_REBOOT is not set
# CONFIG_ESP32S2_PANIC_GDBSTUB is not set
-CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP=y
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=3072
CONFIG_MAIN_TASK_STACK_SIZE=3584
@@ -1939,7 +1920,6 @@ CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread"
CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y
# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS is not set
# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED is not set
-# CONFIG_USB_ENABLED is not set
CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y
CONFIG_SUPPORT_TERMIOS=y
CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS=1
diff --git a/sdkconfig.esp32.4mb b/sdkconfig.esp32.4mb
index 73c136805..fd6cbed81 100644
--- a/sdkconfig.esp32.4mb
+++ b/sdkconfig.esp32.4mb
@@ -434,8 +434,8 @@ CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=2
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BT_MULTI_CONNECTION_ENBALE=y
-# CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST is not set
-CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
+CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
+# CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY is not set
# CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK is not set
CONFIG_BT_SMP_ENABLE=y
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
@@ -498,7 +498,7 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
#
# UART configuration
#
-# CONFIG_UART_ISR_IN_IRAM is not set
+CONFIG_UART_ISR_IN_IRAM=y
# end of UART configuration
#
@@ -662,7 +662,7 @@ CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
# CONFIG_HTTPD_LOG_PURGE_DATA is not set
-# CONFIG_HTTPD_WS_SUPPORT is not set
+CONFIG_HTTPD_WS_SUPPORT=y
# end of HTTP Server
#
@@ -825,7 +825,7 @@ CONFIG_ESP_TIMER_IMPL_TG0_LAC=y
CONFIG_ESP32_WIFI_ENABLED=y
CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=4
-CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16
+CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=8
# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
@@ -839,7 +839,7 @@ CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
-CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=16
+CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
# CONFIG_ESP32_WIFI_IRAM_OPT is not set
# CONFIG_ESP32_WIFI_RX_IRAM_OPT is not set
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
@@ -1052,7 +1052,7 @@ CONFIG_LWIP_ESP_GRATUITOUS_ARP=y
CONFIG_LWIP_GARP_TMR_INTERVAL=60
CONFIG_LWIP_ESP_MLDV6_REPORT=y
CONFIG_LWIP_MLDV6_TMR_INTERVAL=40
-CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=8
+CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=16
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
@@ -1177,7 +1177,7 @@ CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y
# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
-CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=2048
+CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=2048
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y
@@ -1189,6 +1189,7 @@ CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y
# mbedTLS v2.28.x related
#
# CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set
+CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT=y
# CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set
# CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set
# end of mbedTLS v2.28.x related
@@ -1204,8 +1205,8 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=200
# end of Certificate Bundle
-# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
-# CONFIG_MBEDTLS_CMAC_C is not set
+CONFIG_MBEDTLS_ECP_RESTARTABLE=y
+CONFIG_MBEDTLS_CMAC_C=y
CONFIG_MBEDTLS_HARDWARE_AES=y
CONFIG_MBEDTLS_HARDWARE_MPI=y
CONFIG_MBEDTLS_HARDWARE_SHA=y
@@ -1613,11 +1614,11 @@ CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM=100
CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
CONFIG_BLUEDROID_ENABLED=y
# CONFIG_NIMBLE_ENABLED is not set
-CONFIG_BTC_TASK_STACK_SIZE=2048
+CONFIG_BTC_TASK_STACK_SIZE=3072
CONFIG_BLUEDROID_PINNED_TO_CORE_0=y
# CONFIG_BLUEDROID_PINNED_TO_CORE_1 is not set
CONFIG_BLUEDROID_PINNED_TO_CORE=0
-CONFIG_BTU_TASK_STACK_SIZE=2048
+CONFIG_BTU_TASK_STACK_SIZE=4096
# CONFIG_BLUEDROID_MEM_DEBUG is not set
# CONFIG_CLASSIC_BT_ENABLED is not set
CONFIG_GATTS_ENABLE=y
@@ -1876,7 +1877,7 @@ CONFIG_TIMER_QUEUE_LENGTH=10
# CONFIG_USE_ONLY_LWIP_SELECT is not set
CONFIG_ESP_GRATUITOUS_ARP=y
CONFIG_GARP_TMR_INTERVAL=60
-CONFIG_TCPIP_RECVMBOX_SIZE=8
+CONFIG_TCPIP_RECVMBOX_SIZE=16
CONFIG_TCP_MAXRTX=12
CONFIG_TCP_SYNMAXRTX=12
CONFIG_TCP_MSS=1440
diff --git a/sdkconfig.esp32c3.4mb b/sdkconfig.esp32c3.4mb
index 1da1021f0..e2343561a 100644
--- a/sdkconfig.esp32c3.4mb
+++ b/sdkconfig.esp32c3.4mb
@@ -50,6 +50,14 @@ CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set
# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set
CONFIG_BOOTLOADER_LOG_LEVEL=0
+
+#
+# Serial Flash Configurations
+#
+# CONFIG_BOOTLOADER_FLASH_DC_AWARE is not set
+CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
+# end of Serial Flash Configurations
+
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
# CONFIG_BOOTLOADER_FACTORY_RESET is not set
# CONFIG_BOOTLOADER_APP_TEST is not set
@@ -63,7 +71,6 @@ CONFIG_BOOTLOADER_WDT_TIME_MS=9000
# CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set
CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0
# CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set
-CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
# end of Bootloader config
#
@@ -262,6 +269,7 @@ CONFIG_BT_CTRL_SLEEP_CLOCK_EFF=0
CONFIG_BT_CTRL_HCI_TL_EFF=1
# CONFIG_BT_CTRL_AGC_RECORRECT_EN is not set
# CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX is not set
+# CONFIG_BT_BLE_ADV_DATA_LENGTH_ZERO_AUX is not set
# end of Bluetooth controller
CONFIG_BT_BLUEDROID_ENABLED=y
@@ -289,6 +297,7 @@ CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set
CONFIG_BT_GATTC_ENABLE=y
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
+CONFIG_BT_GATTC_NOTIF_REG_MAX=5
# CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set
CONFIG_BT_GATTC_CONNECT_RETRY_COUNT=3
CONFIG_BT_BLE_SMP_ENABLE=y
@@ -474,6 +483,7 @@ CONFIG_BT_MULTI_CONNECTION_ENBALE=y
# CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY is not set
# CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK is not set
CONFIG_BT_SMP_ENABLE=y
+CONFIG_BT_SMP_MAX_BONDS=15
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
@@ -574,12 +584,13 @@ CONFIG_ESP32C3_DEFAULT_CPU_FREQ_MHZ=160
# CONFIG_ESP32C3_REV_MIN_2 is not set
CONFIG_ESP32C3_REV_MIN_3=y
# CONFIG_ESP32C3_REV_MIN_4 is not set
+# CONFIG_ESP32C3_REV_MIN_101 is not set
CONFIG_ESP32C3_REV_MIN=3
CONFIG_ESP32C3_REV_MIN_FULL=3
CONFIG_ESP_REV_MIN_FULL=3
CONFIG_ESP32C3_REV_MAX_FULL_STR_OPT=y
-CONFIG_ESP32C3_REV_MAX_FULL=99
-CONFIG_ESP_REV_MAX_FULL=99
+CONFIG_ESP32C3_REV_MAX_FULL=199
+CONFIG_ESP_REV_MAX_FULL=199
CONFIG_ESP32C3_DEBUG_OCDAWARE=y
CONFIG_ESP32C3_BROWNOUT_DET=y
CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_7=y
@@ -651,7 +662,7 @@ CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
# CONFIG_HTTPD_LOG_PURGE_DATA is not set
-# CONFIG_HTTPD_WS_SUPPORT is not set
+CONFIG_HTTPD_WS_SUPPORT=y
# end of HTTP Server
#
@@ -688,6 +699,7 @@ CONFIG_ESP32C3_UNIVERSAL_MAC_ADDRESSES=4
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
# CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND is not set
+CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y
# end of Sleep Config
CONFIG_ESP_SLEEP_SYSTIMER_STALL_WORKAROUND=y
@@ -709,6 +721,10 @@ CONFIG_ESP_IPC_TASK_STACK_SIZE=1536
# LCD and Touch Panel
#
+#
+# LCD Touch Drivers are maintained in the IDF Component Registry
+#
+
#
# LCD Peripheral Configuration
#
@@ -827,6 +843,10 @@ CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16
+CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y
+# CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set
+CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0
+CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF=5
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_TX_BA_WIN=6
@@ -1022,6 +1042,7 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
#
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
# CONFIG_LWIP_NETIF_API is not set
+CONFIG_LWIP_TCPIP_TASK_PRIO=18
# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
@@ -1035,6 +1056,7 @@ CONFIG_LWIP_SO_REUSE=y
CONFIG_LWIP_SO_REUSE_RXTOALL=y
# CONFIG_LWIP_SO_RCVBUF is not set
# CONFIG_LWIP_NETBUF_RECVINFO is not set
+CONFIG_LWIP_IP_DEFAULT_TTL=64
CONFIG_LWIP_IP4_FRAG=y
CONFIG_LWIP_IP6_FRAG=y
# CONFIG_LWIP_IP4_REASSEMBLY is not set
@@ -1087,6 +1109,8 @@ CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
CONFIG_LWIP_TCP_WND_DEFAULT=5744
CONFIG_LWIP_TCP_RECVMBOX_SIZE=6
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
+CONFIG_LWIP_TCP_OOSEQ_TIMEOUT=6
+CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=4
# CONFIG_LWIP_TCP_SACK_OUT is not set
# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
CONFIG_LWIP_TCP_OVERSIZE_MSS=y
@@ -1141,6 +1165,13 @@ CONFIG_LWIP_SNTP_MAX_SERVERS=1
CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000
# end of SNTP
+#
+# DNS
+#
+CONFIG_LWIP_DNS_MAX_SERVERS=3
+# CONFIG_LWIP_FALLBACK_DNS_SERVER_SUPPORT is not set
+# end of DNS
+
CONFIG_LWIP_ESP_LWIP_ASSERT=y
#
@@ -1370,6 +1401,21 @@ CONFIG_PTHREAD_TASK_CORE_DEFAULT=-1
CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
# end of PThreads
+#
+# Main Flash configuration
+#
+
+#
+# Optional and Experimental Features (READ DOCS FIRST)
+#
+
+#
+# Features here require specific hardware (READ DOCS FIRST!)
+#
+# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set
+# end of Optional and Experimental Features (READ DOCS FIRST)
+# end of Main Flash configuration
+
#
# SPI Flash driver
#
@@ -1386,7 +1432,6 @@ CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y
CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20
CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1
-# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set
CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE=8192
# CONFIG_SPI_FLASH_SIZE_OVERRIDE is not set
# CONFIG_SPI_FLASH_CHECK_ERASE_TIMEOUT_DISABLED is not set
diff --git a/sdkconfig.esp32s3.4mb b/sdkconfig.esp32s3.4mb
index 093e6436a..01763ce59 100644
--- a/sdkconfig.esp32s3.4mb
+++ b/sdkconfig.esp32s3.4mb
@@ -50,6 +50,14 @@ CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set
# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set
CONFIG_BOOTLOADER_LOG_LEVEL=0
+
+#
+# Serial Flash Configurations
+#
+# CONFIG_BOOTLOADER_FLASH_DC_AWARE is not set
+CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
+# end of Serial Flash Configurations
+
# CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V is not set
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
# CONFIG_BOOTLOADER_FACTORY_RESET is not set
@@ -64,7 +72,6 @@ CONFIG_BOOTLOADER_WDT_TIME_MS=9000
# CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set
CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0
# CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set
-CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
# end of Bootloader config
#
@@ -98,6 +105,7 @@ CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set
CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y
CONFIG_ESPTOOLPY_FLASHMODE="dio"
+CONFIG_ESPTOOLPY_S3_STR=y
# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
@@ -231,14 +239,14 @@ CONFIG_BT_CTRL_RX_ANTENNA_INDEX_EFF=0
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N6 is not set
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N3 is not set
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N0 is not set
-CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P3=y
+# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P3 is not set
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P6 is not set
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P9 is not set
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P12 is not set
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P15 is not set
# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P18 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P21 is not set
-CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_EFF=9
+CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P21=y
+CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_EFF=15
CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
CONFIG_BT_CTRL_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
@@ -265,6 +273,7 @@ CONFIG_BT_CTRL_SLEEP_CLOCK_EFF=0
CONFIG_BT_CTRL_HCI_TL_EFF=1
# CONFIG_BT_CTRL_AGC_RECORRECT_EN is not set
# CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX is not set
+# CONFIG_BT_BLE_ADV_DATA_LENGTH_ZERO_AUX is not set
# end of Bluetooth controller
CONFIG_BT_BLUEDROID_ENABLED=y
@@ -294,6 +303,7 @@ CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set
CONFIG_BT_GATTC_ENABLE=y
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
+CONFIG_BT_GATTC_NOTIF_REG_MAX=5
# CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set
CONFIG_BT_GATTC_CONNECT_RETRY_COUNT=3
CONFIG_BT_BLE_SMP_ENABLE=y
@@ -475,15 +485,16 @@ CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=2
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BT_MULTI_CONNECTION_ENBALE=y
-# CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST is not set
+CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
# CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY is not set
# CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK is not set
CONFIG_BT_SMP_ENABLE=y
+CONFIG_BT_SMP_MAX_BONDS=15
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
CONFIG_BT_BLE_RPA_TIMEOUT=900
-CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y
+# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
# CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL is not set
# end of Bluedroid Options
@@ -537,7 +548,7 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
#
# UART configuration
#
-# CONFIG_UART_ISR_IN_IRAM is not set
+CONFIG_UART_ISR_IN_IRAM=y
# end of UART configuration
#
@@ -690,7 +701,7 @@ CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
# CONFIG_HTTPD_LOG_PURGE_DATA is not set
-# CONFIG_HTTPD_WS_SUPPORT is not set
+CONFIG_HTTPD_WS_SUPPORT=y
# end of HTTP Server
#
@@ -728,6 +739,7 @@ CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
# CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND is not set
+CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y
# end of Sleep Config
#
@@ -749,6 +761,10 @@ CONFIG_ESP_IPC_ISR_ENABLE=y
# LCD and Touch Panel
#
+#
+# LCD Touch Drivers are maintained in the IDF Component Registry
+#
+
#
# LCD Peripheral Configuration
#
@@ -842,6 +858,7 @@ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_ESP_PANIC_HANDLER_IRAM is not set
# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set
CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_4=y
+CONFIG_ESP_SYSTEM_BBPLL_RECALIB=y
# end of ESP System Settings
#
@@ -867,6 +884,10 @@ CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=8
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16
+CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y
+# CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set
+CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0
+CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF=5
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_TX_BA_WIN=6
@@ -1066,6 +1087,7 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
#
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
# CONFIG_LWIP_NETIF_API is not set
+CONFIG_LWIP_TCPIP_TASK_PRIO=18
# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
@@ -1079,6 +1101,7 @@ CONFIG_LWIP_SO_REUSE=y
CONFIG_LWIP_SO_REUSE_RXTOALL=y
# CONFIG_LWIP_SO_RCVBUF is not set
# CONFIG_LWIP_NETBUF_RECVINFO is not set
+CONFIG_LWIP_IP_DEFAULT_TTL=64
CONFIG_LWIP_IP4_FRAG=y
CONFIG_LWIP_IP6_FRAG=y
# CONFIG_LWIP_IP4_REASSEMBLY is not set
@@ -1131,6 +1154,8 @@ CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
CONFIG_LWIP_TCP_WND_DEFAULT=5744
CONFIG_LWIP_TCP_RECVMBOX_SIZE=6
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
+CONFIG_LWIP_TCP_OOSEQ_TIMEOUT=6
+CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=4
# CONFIG_LWIP_TCP_SACK_OUT is not set
# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
CONFIG_LWIP_TCP_OVERSIZE_MSS=y
@@ -1186,6 +1211,13 @@ CONFIG_LWIP_SNTP_MAX_SERVERS=1
CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000
# end of SNTP
+#
+# DNS
+#
+CONFIG_LWIP_DNS_MAX_SERVERS=3
+# CONFIG_LWIP_FALLBACK_DNS_SERVER_SUPPORT is not set
+# end of DNS
+
CONFIG_LWIP_ESP_LWIP_ASSERT=y
#
@@ -1227,6 +1259,7 @@ CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y
# mbedTLS v2.28.x related
#
# CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set
+CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT=y
# CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set
# CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set
# end of mbedTLS v2.28.x related
@@ -1242,8 +1275,8 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=200
# end of Certificate Bundle
-# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
-# CONFIG_MBEDTLS_CMAC_C is not set
+CONFIG_MBEDTLS_ECP_RESTARTABLE=y
+CONFIG_MBEDTLS_CMAC_C=y
CONFIG_MBEDTLS_HARDWARE_AES=y
CONFIG_MBEDTLS_AES_USE_INTERRUPT=y
CONFIG_MBEDTLS_HARDWARE_MPI=y
@@ -1419,6 +1452,26 @@ CONFIG_PTHREAD_TASK_CORE_DEFAULT=-1
CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
# end of PThreads
+#
+# Main Flash configuration
+#
+
+#
+# Optional and Experimental Features (READ DOCS FIRST)
+#
+
+#
+# Features here require specific hardware (READ DOCS FIRST!)
+#
+# CONFIG_SPI_FLASH_HPM_ENA is not set
+CONFIG_SPI_FLASH_HPM_AUTO=y
+# CONFIG_SPI_FLASH_HPM_DIS is not set
+CONFIG_SPI_FLASH_HPM_ON=y
+CONFIG_SPI_FLASH_HPM_DC_AUTO=y
+# CONFIG_SPI_FLASH_HPM_DC_DISABLE is not set
+# end of Optional and Experimental Features (READ DOCS FIRST)
+# end of Main Flash configuration
+
#
# SPI Flash driver
#
@@ -1652,7 +1705,7 @@ CONFIG_ESP32_APPTRACE_DEST_NONE=y
CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
CONFIG_BLUEDROID_ENABLED=y
# CONFIG_NIMBLE_ENABLED is not set
-CONFIG_BTC_TASK_STACK_SIZE=4096
+CONFIG_BTC_TASK_STACK_SIZE=3072
CONFIG_BLUEDROID_PINNED_TO_CORE_0=y
# CONFIG_BLUEDROID_PINNED_TO_CORE_1 is not set
CONFIG_BLUEDROID_PINNED_TO_CORE=0
diff --git a/sdkconfig.esp32s3.8mb b/sdkconfig.esp32s3.8mb
index 11a4697db..571ea575c 100644
--- a/sdkconfig.esp32s3.8mb
+++ b/sdkconfig.esp32s3.8mb
@@ -50,6 +50,14 @@ CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set
# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set
CONFIG_BOOTLOADER_LOG_LEVEL=0
+
+#
+# Serial Flash Configurations
+#
+# CONFIG_BOOTLOADER_FLASH_DC_AWARE is not set
+CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
+# end of Serial Flash Configurations
+
# CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V is not set
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
# CONFIG_BOOTLOADER_FACTORY_RESET is not set
@@ -64,7 +72,6 @@ CONFIG_BOOTLOADER_WDT_TIME_MS=9000
# CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set
CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0
# CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set
-CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
# end of Bootloader config
#
@@ -98,6 +105,7 @@ CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set
CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y
CONFIG_ESPTOOLPY_FLASHMODE="dio"
+CONFIG_ESPTOOLPY_S3_STR=y
# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
@@ -265,6 +273,7 @@ CONFIG_BT_CTRL_SLEEP_CLOCK_EFF=0
CONFIG_BT_CTRL_HCI_TL_EFF=1
# CONFIG_BT_CTRL_AGC_RECORRECT_EN is not set
# CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX is not set
+# CONFIG_BT_BLE_ADV_DATA_LENGTH_ZERO_AUX is not set
# end of Bluetooth controller
CONFIG_BT_BLUEDROID_ENABLED=y
@@ -294,6 +303,7 @@ CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set
CONFIG_BT_GATTC_ENABLE=y
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
+CONFIG_BT_GATTC_NOTIF_REG_MAX=5
# CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set
CONFIG_BT_GATTC_CONNECT_RETRY_COUNT=3
CONFIG_BT_BLE_SMP_ENABLE=y
@@ -479,6 +489,7 @@ CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
# CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY is not set
# CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK is not set
CONFIG_BT_SMP_ENABLE=y
+CONFIG_BT_SMP_MAX_BONDS=15
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
@@ -690,7 +701,7 @@ CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
# CONFIG_HTTPD_LOG_PURGE_DATA is not set
-# CONFIG_HTTPD_WS_SUPPORT is not set
+CONFIG_HTTPD_WS_SUPPORT=y
# end of HTTP Server
#
@@ -728,6 +739,7 @@ CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
# CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND is not set
+CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y
# end of Sleep Config
#
@@ -749,6 +761,10 @@ CONFIG_ESP_IPC_ISR_ENABLE=y
# LCD and Touch Panel
#
+#
+# LCD Touch Drivers are maintained in the IDF Component Registry
+#
+
#
# LCD Peripheral Configuration
#
@@ -842,6 +858,7 @@ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_ESP_PANIC_HANDLER_IRAM is not set
# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set
CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_4=y
+CONFIG_ESP_SYSTEM_BBPLL_RECALIB=y
# end of ESP System Settings
#
@@ -867,6 +884,10 @@ CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=8
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16
+CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y
+# CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set
+CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0
+CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF=5
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_TX_BA_WIN=6
@@ -1066,6 +1087,7 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
#
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
# CONFIG_LWIP_NETIF_API is not set
+CONFIG_LWIP_TCPIP_TASK_PRIO=18
# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
@@ -1079,6 +1101,7 @@ CONFIG_LWIP_SO_REUSE=y
CONFIG_LWIP_SO_REUSE_RXTOALL=y
# CONFIG_LWIP_SO_RCVBUF is not set
# CONFIG_LWIP_NETBUF_RECVINFO is not set
+CONFIG_LWIP_IP_DEFAULT_TTL=64
CONFIG_LWIP_IP4_FRAG=y
CONFIG_LWIP_IP6_FRAG=y
# CONFIG_LWIP_IP4_REASSEMBLY is not set
@@ -1131,6 +1154,8 @@ CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
CONFIG_LWIP_TCP_WND_DEFAULT=5744
CONFIG_LWIP_TCP_RECVMBOX_SIZE=6
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
+CONFIG_LWIP_TCP_OOSEQ_TIMEOUT=6
+CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=4
# CONFIG_LWIP_TCP_SACK_OUT is not set
# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
CONFIG_LWIP_TCP_OVERSIZE_MSS=y
@@ -1186,6 +1211,13 @@ CONFIG_LWIP_SNTP_MAX_SERVERS=1
CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000
# end of SNTP
+#
+# DNS
+#
+CONFIG_LWIP_DNS_MAX_SERVERS=3
+# CONFIG_LWIP_FALLBACK_DNS_SERVER_SUPPORT is not set
+# end of DNS
+
CONFIG_LWIP_ESP_LWIP_ASSERT=y
#
@@ -1420,6 +1452,26 @@ CONFIG_PTHREAD_TASK_CORE_DEFAULT=-1
CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
# end of PThreads
+#
+# Main Flash configuration
+#
+
+#
+# Optional and Experimental Features (READ DOCS FIRST)
+#
+
+#
+# Features here require specific hardware (READ DOCS FIRST!)
+#
+# CONFIG_SPI_FLASH_HPM_ENA is not set
+CONFIG_SPI_FLASH_HPM_AUTO=y
+# CONFIG_SPI_FLASH_HPM_DIS is not set
+CONFIG_SPI_FLASH_HPM_ON=y
+CONFIG_SPI_FLASH_HPM_DC_AUTO=y
+# CONFIG_SPI_FLASH_HPM_DC_DISABLE is not set
+# end of Optional and Experimental Features (READ DOCS FIRST)
+# end of Main Flash configuration
+
#
# SPI Flash driver
#
@@ -1653,7 +1705,7 @@ CONFIG_ESP32_APPTRACE_DEST_NONE=y
CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
CONFIG_BLUEDROID_ENABLED=y
# CONFIG_NIMBLE_ENABLED is not set
-CONFIG_BTC_TASK_STACK_SIZE=4096
+CONFIG_BTC_TASK_STACK_SIZE=3072
CONFIG_BLUEDROID_PINNED_TO_CORE_0=y
# CONFIG_BLUEDROID_PINNED_TO_CORE_1 is not set
CONFIG_BLUEDROID_PINNED_TO_CORE=0
diff --git a/sdkconfig.old b/sdkconfig.old
index 3e8de980c..d650d8ed4 100644
--- a/sdkconfig.old
+++ b/sdkconfig.old
@@ -4,9 +4,9 @@
#
CONFIG_IDF_CMAKE=y
CONFIG_IDF_TARGET_ARCH_XTENSA=y
-CONFIG_IDF_TARGET="esp32s3"
-CONFIG_IDF_TARGET_ESP32S3=y
-CONFIG_IDF_FIRMWARE_CHIP_ID=0x0009
+CONFIG_IDF_TARGET="esp32"
+CONFIG_IDF_TARGET_ESP32=y
+CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000
#
# SDK tool configuration
@@ -38,7 +38,7 @@ CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
#
# Bootloader config
#
-CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x0
+CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x1000
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set
@@ -70,48 +70,36 @@ CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
#
# Security features
#
-CONFIG_SECURE_BOOT_SUPPORTS_RSA=y
-CONFIG_SECURE_TARGET_HAS_SECURE_ROM_DL_MODE=y
# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set
# CONFIG_SECURE_BOOT is not set
# CONFIG_SECURE_FLASH_ENC_ENABLED is not set
# end of Security features
-#
-# Boot ROM Behavior
-#
-CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y
-# CONFIG_BOOT_ROM_LOG_ALWAYS_OFF is not set
-# CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH is not set
-# CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW is not set
-# end of Boot ROM Behavior
-
#
# Serial flasher config
#
CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200
# CONFIG_ESPTOOLPY_NO_STUB is not set
-# CONFIG_ESPTOOLPY_OCT_FLASH is not set
# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set
# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set
CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y
CONFIG_ESPTOOLPY_FLASHMODE="dio"
-# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
+# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
-CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
-# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
+# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
+CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
-CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
+CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_BEFORE_RESET=y
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
@@ -200,81 +188,51 @@ CONFIG_APPTRACE_LOCK_ENABLE=y
# Bluetooth
#
CONFIG_BT_ENABLED=y
-CONFIG_BT_SOC_SUPPORT_5_0=y
#
# Bluetooth controller
#
-CONFIG_BT_CTRL_MODE_EFF=1
-CONFIG_BT_CTRL_BLE_MAX_ACT=10
-CONFIG_BT_CTRL_BLE_MAX_ACT_EFF=10
-CONFIG_BT_CTRL_BLE_STATIC_ACL_TX_BUF_NB=0
-CONFIG_BT_CTRL_PINNED_TO_CORE_0=y
-# CONFIG_BT_CTRL_PINNED_TO_CORE_1 is not set
-CONFIG_BT_CTRL_PINNED_TO_CORE=0
-CONFIG_BT_CTRL_HCI_MODE_VHCI=y
-# CONFIG_BT_CTRL_HCI_MODE_UART_H4 is not set
-CONFIG_BT_CTRL_HCI_TL=1
-CONFIG_BT_CTRL_ADV_DUP_FILT_MAX=30
-CONFIG_BT_BLE_CCA_MODE_NONE=y
-# CONFIG_BT_BLE_CCA_MODE_HW is not set
-# CONFIG_BT_BLE_CCA_MODE_SW is not set
-CONFIG_BT_BLE_CCA_MODE=0
-CONFIG_BT_CTRL_HW_CCA_VAL=20
-CONFIG_BT_CTRL_HW_CCA_EFF=0
-CONFIG_BT_CTRL_CE_LENGTH_TYPE_ORIG=y
-# CONFIG_BT_CTRL_CE_LENGTH_TYPE_CE is not set
-# CONFIG_BT_CTRL_CE_LENGTH_TYPE_SD is not set
-CONFIG_BT_CTRL_CE_LENGTH_TYPE_EFF=0
-CONFIG_BT_CTRL_TX_ANTENNA_INDEX_0=y
-# CONFIG_BT_CTRL_TX_ANTENNA_INDEX_1 is not set
-CONFIG_BT_CTRL_TX_ANTENNA_INDEX_EFF=0
-CONFIG_BT_CTRL_RX_ANTENNA_INDEX_0=y
-# CONFIG_BT_CTRL_RX_ANTENNA_INDEX_1 is not set
-CONFIG_BT_CTRL_RX_ANTENNA_INDEX_EFF=0
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N24 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N21 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N18 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N15 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N12 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N9 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N6 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N3 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_N0 is not set
-CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P3=y
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P6 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P9 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P12 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P15 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P18 is not set
-# CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_P21 is not set
-CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_EFF=9
-CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
-CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
-CONFIG_BT_CTRL_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
-CONFIG_BT_CTRL_BLE_SCAN_DUPL=y
-CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DEVICE=y
-# CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DATA is not set
-# CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DATA_DEVICE is not set
-CONFIG_BT_CTRL_SCAN_DUPL_TYPE=0
-CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE=100
-CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD=0
-# CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN is not set
-# CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EN is not set
-CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_DIS=y
-CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF=0
+CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
+# CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY is not set
+# CONFIG_BTDM_CTRL_MODE_BTDM is not set
+CONFIG_BTDM_CTRL_BLE_MAX_CONN=3
+CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF=0
+CONFIG_BTDM_CTRL_PCM_ROLE_EFF=0
+CONFIG_BTDM_CTRL_PCM_POLAR_EFF=0
+CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=3
+CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF=0
+CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF=0
+CONFIG_BTDM_CTRL_PINNED_TO_CORE_0=y
+# CONFIG_BTDM_CTRL_PINNED_TO_CORE_1 is not set
+CONFIG_BTDM_CTRL_PINNED_TO_CORE=0
+CONFIG_BTDM_CTRL_HCI_MODE_VHCI=y
+# CONFIG_BTDM_CTRL_HCI_MODE_UART_H4 is not set
#
# MODEM SLEEP Options
#
-# CONFIG_BT_CTRL_MODEM_SLEEP is not set
+CONFIG_BTDM_CTRL_MODEM_SLEEP=y
+CONFIG_BTDM_CTRL_MODEM_SLEEP_MODE_ORIG=y
+# CONFIG_BTDM_CTRL_MODEM_SLEEP_MODE_EVED is not set
+CONFIG_BTDM_CTRL_LPCLK_SEL_MAIN_XTAL=y
# end of MODEM SLEEP Options
-CONFIG_BT_CTRL_SLEEP_MODE_EFF=0
-CONFIG_BT_CTRL_SLEEP_CLOCK_EFF=0
-CONFIG_BT_CTRL_HCI_TL_EFF=1
-# CONFIG_BT_CTRL_AGC_RECORRECT_EN is not set
-# CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX is not set
+CONFIG_BTDM_BLE_DEFAULT_SCA_250PPM=y
+CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF=1
+CONFIG_BTDM_BLE_SCAN_DUPL=y
+CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE=y
+# CONFIG_BTDM_SCAN_DUPL_TYPE_DATA is not set
+# CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE is not set
+CONFIG_BTDM_SCAN_DUPL_TYPE=0
+CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=100
+CONFIG_BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD=0
+# CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN is not set
+CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED=y
+CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
+CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
+CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
+CONFIG_BTDM_RESERVE_DRAM=0xdb5c
+CONFIG_BTDM_CTRL_HLI=y
# end of Bluetooth controller
CONFIG_BT_BLUEDROID_ENABLED=y
@@ -290,6 +248,7 @@ CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0=y
CONFIG_BT_BLUEDROID_PINNED_TO_CORE=0
CONFIG_BT_BTU_TASK_STACK_SIZE=4096
# CONFIG_BT_BLUEDROID_MEM_DEBUG is not set
+# CONFIG_BT_CLASSIC_ENABLED is not set
CONFIG_BT_BLE_ENABLED=y
CONFIG_BT_GATTS_ENABLE=y
# CONFIG_BT_GATTS_PPCP_CHAR_GAP is not set
@@ -486,16 +445,15 @@ CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=2
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BT_MULTI_CONNECTION_ENBALE=y
-# CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST is not set
+CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
# CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY is not set
# CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK is not set
CONFIG_BT_SMP_ENABLE=y
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
+# CONFIG_BT_BLE_RPA_SUPPORTED is not set
CONFIG_BT_BLE_RPA_TIMEOUT=900
-CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y
-CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
# CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL is not set
# end of Bluedroid Options
# end of Bluetooth
@@ -520,7 +478,6 @@ CONFIG_COAP_LOG_DEFAULT_LEVEL=0
#
# CONFIG_ADC_FORCE_XPD_FSM is not set
CONFIG_ADC_DISABLE_DAC=y
-# CONFIG_ADC_CONTINUOUS_FORCE_USE_ADC2_ON_C3_S3 is not set
# end of ADC configuration
#
@@ -542,15 +499,31 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
# TWAI configuration
#
# CONFIG_TWAI_ISR_IN_IRAM is not set
+# CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC is not set
+# CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST is not set
+# CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID is not set
+# CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT is not set
# CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM is not set
# end of TWAI configuration
#
# UART configuration
#
-# CONFIG_UART_ISR_IN_IRAM is not set
+CONFIG_UART_ISR_IN_IRAM=y
# end of UART configuration
+#
+# RTCIO configuration
+#
+# CONFIG_RTCIO_SUPPORT_RTC_GPIO_DESC is not set
+# end of RTCIO configuration
+
+#
+# GPIO Configuration
+#
+# CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL is not set
+# end of GPIO Configuration
+
#
# GDMA Configuration
#
@@ -564,14 +537,17 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
#
# CONFIG_EFUSE_CUSTOM_TABLE is not set
# CONFIG_EFUSE_VIRTUAL is not set
-CONFIG_EFUSE_MAX_BLK_LEN=256
+# CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE is not set
+CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4=y
+# CONFIG_EFUSE_CODE_SCHEME_COMPAT_REPEAT is not set
+CONFIG_EFUSE_MAX_BLK_LEN=192
# end of eFuse Bit Manager
#
# ESP-TLS
#
CONFIG_ESP_TLS_USING_MBEDTLS=y
-CONFIG_ESP_TLS_USE_DS_PERIPHERAL=y
+# CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set
# CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS is not set
# CONFIG_ESP_TLS_SERVER is not set
# CONFIG_ESP_TLS_PSK_VERIFICATION is not set
@@ -579,80 +555,68 @@ CONFIG_ESP_TLS_USE_DS_PERIPHERAL=y
# end of ESP-TLS
#
-# ESP32S3-Specific
+# ESP32-specific
#
-CONFIG_ESP32S3_REV_MIN_0=y
-# CONFIG_ESP32S3_REV_MIN_1 is not set
-# CONFIG_ESP32S3_REV_MIN_2 is not set
-CONFIG_ESP32S3_REV_MIN_FULL=0
+CONFIG_ESP32_REV_MIN_0=y
+# CONFIG_ESP32_REV_MIN_1 is not set
+# CONFIG_ESP32_REV_MIN_1_1 is not set
+# CONFIG_ESP32_REV_MIN_2 is not set
+# CONFIG_ESP32_REV_MIN_3 is not set
+# CONFIG_ESP32_REV_MIN_3_1 is not set
+CONFIG_ESP32_REV_MIN=0
+CONFIG_ESP32_REV_MIN_FULL=0
CONFIG_ESP_REV_MIN_FULL=0
-CONFIG_ESP32S3_REV_MAX_FULL_STR_OPT=y
-CONFIG_ESP32S3_REV_MAX_FULL=99
-CONFIG_ESP_REV_MAX_FULL=99
-# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_80 is not set
-# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160 is not set
-CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
-CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=240
-
-#
-# Cache config
-#
-CONFIG_ESP32S3_INSTRUCTION_CACHE_16KB=y
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB is not set
-CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE=0x4000
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_4WAYS is not set
-CONFIG_ESP32S3_INSTRUCTION_CACHE_8WAYS=y
-CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS=8
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_16B is not set
-CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_32B=y
-CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE=32
-# CONFIG_ESP32S3_INSTRUCTION_CACHE_WRAP is not set
-# CONFIG_ESP32S3_DATA_CACHE_16KB is not set
-CONFIG_ESP32S3_DATA_CACHE_32KB=y
-# CONFIG_ESP32S3_DATA_CACHE_64KB is not set
-CONFIG_ESP32S3_DATA_CACHE_SIZE=0x8000
-# CONFIG_ESP32S3_DATA_CACHE_4WAYS is not set
-CONFIG_ESP32S3_DATA_CACHE_8WAYS=y
-CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS=8
-# CONFIG_ESP32S3_DATA_CACHE_LINE_16B is not set
-CONFIG_ESP32S3_DATA_CACHE_LINE_32B=y
-# CONFIG_ESP32S3_DATA_CACHE_LINE_64B is not set
-CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE=32
-# CONFIG_ESP32S3_DATA_CACHE_WRAP is not set
-# end of Cache config
-
-# CONFIG_ESP32S3_SPIRAM_SUPPORT is not set
-# CONFIG_ESP32S3_TRAX is not set
-CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM=0x0
-# CONFIG_ESP32S3_ULP_COPROC_ENABLED is not set
-CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=0
-CONFIG_ESP32S3_DEBUG_OCDAWARE=y
-CONFIG_ESP32S3_BROWNOUT_DET=y
-CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_7=y
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_6 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_5 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_4 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_3 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_2 is not set
-# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_1 is not set
-CONFIG_ESP32S3_BROWNOUT_DET_LVL=7
-CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC_FRC1=y
-# CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC is not set
-# CONFIG_ESP32S3_TIME_SYSCALL_USE_FRC1 is not set
-# CONFIG_ESP32S3_TIME_SYSCALL_USE_NONE is not set
-CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y
-# CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS is not set
-# CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC is not set
-# CONFIG_ESP32S3_RTC_CLK_SRC_INT_8MD256 is not set
-CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=1024
-CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000
-# CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM is not set
-# CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE is not set
-# end of ESP32S3-Specific
+CONFIG_ESP32_REV_MAX_FULL_STR_OPT=y
+CONFIG_ESP32_REV_MAX_FULL=399
+CONFIG_ESP_REV_MAX_FULL=399
+CONFIG_ESP32_DPORT_WORKAROUND=y
+# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set
+CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y
+# CONFIG_ESP32_DEFAULT_CPU_FREQ_240 is not set
+CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160
+# CONFIG_ESP32_SPIRAM_SUPPORT is not set
+# CONFIG_ESP32_TRAX is not set
+CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0
+# CONFIG_ESP32_ULP_COPROC_ENABLED is not set
+CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=0
+CONFIG_ESP32_DEBUG_OCDAWARE=y
+CONFIG_ESP32_BROWNOUT_DET=y
+CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_1 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_2 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_3 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_4 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_5 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_6 is not set
+# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set
+CONFIG_ESP32_BROWNOUT_DET_LVL=0
+CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
+# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
+# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
+# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set
+CONFIG_ESP32_RTC_CLK_SRC_INT_RC=y
+# CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS is not set
+# CONFIG_ESP32_RTC_CLK_SRC_EXT_OSC is not set
+# CONFIG_ESP32_RTC_CLK_SRC_INT_8MD256 is not set
+CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024
+CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000
+CONFIG_ESP32_XTAL_FREQ_40=y
+# CONFIG_ESP32_XTAL_FREQ_26 is not set
+# CONFIG_ESP32_XTAL_FREQ_AUTO is not set
+CONFIG_ESP32_XTAL_FREQ=40
+# CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE is not set
+# CONFIG_ESP32_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set
+# CONFIG_ESP32_COMPATIBLE_PRE_V3_1_BOOTLOADERS is not set
+# CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE is not set
+CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL=5
+# end of ESP32-specific
#
# ADC-Calibration
#
+CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y
+CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y
+CONFIG_ADC_CAL_LUT_ENABLE=y
# end of ADC-Calibration
#
@@ -665,6 +629,14 @@ CONFIG_ESP_ERR_TO_NAME_LOOKUP=y
# Ethernet
#
CONFIG_ETH_ENABLED=y
+CONFIG_ETH_USE_ESP32_EMAC=y
+CONFIG_ETH_PHY_INTERFACE_RMII=y
+CONFIG_ETH_RMII_CLK_INPUT=y
+# CONFIG_ETH_RMII_CLK_OUTPUT is not set
+CONFIG_ETH_RMII_CLK_IN_GPIO=0
+CONFIG_ETH_DMA_BUFFER_SIZE=512
+CONFIG_ETH_DMA_RX_BUFFER_NUM=10
+CONFIG_ETH_DMA_TX_BUFFER_NUM=10
CONFIG_ETH_USE_SPI_ETHERNET=y
# CONFIG_ETH_SPI_ETHERNET_DM9051 is not set
CONFIG_ETH_SPI_ETHERNET_W5500=y
@@ -701,7 +673,7 @@ CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
# CONFIG_HTTPD_LOG_PURGE_DATA is not set
-# CONFIG_HTTPD_WS_SUPPORT is not set
+CONFIG_HTTPD_WS_SUPPORT=y
# end of HTTP Server
#
@@ -727,9 +699,10 @@ CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y
-# CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO is not set
-CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_FOUR=y
-CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES=4
+# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set
+CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y
+CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4
+# CONFIG_ESP_MAC_IGNORE_MAC_CRC_ERROR is not set
# end of MAC Config
#
@@ -745,7 +718,6 @@ CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y
#
# RTC Clock Config
#
-CONFIG_RTC_CLOCK_BBPLL_POWER_ON_WITH_USB=y
# end of RTC Clock Config
# end of Hardware Settings
@@ -765,7 +737,6 @@ CONFIG_ESP_IPC_ISR_ENABLE=y
# LCD Peripheral Configuration
#
CONFIG_LCD_PANEL_IO_FORMAT_BUF_SIZE=32
-# CONFIG_LCD_RGB_ISR_IRAM_SAFE is not set
# end of LCD Peripheral Configuration
# end of LCD and Touch Panel
@@ -786,7 +757,6 @@ CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y
CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20
CONFIG_ESP_PHY_MAX_TX_POWER=20
# CONFIG_ESP_PHY_REDUCE_TX_POWER is not set
-CONFIG_ESP_PHY_ENABLE_USB=y
CONFIG_ESP_PHY_RF_CAL_PARTIAL=y
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
# CONFIG_ESP_PHY_RF_CAL_FULL is not set
@@ -797,8 +767,6 @@ CONFIG_ESP_PHY_CALIBRATION_MODE=0
# Power Management
#
# CONFIG_PM_ENABLE is not set
-CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
-CONFIG_PM_POWER_DOWN_TAGMEM_IN_LIGHT_SLEEP=y
# end of Power Management
#
@@ -816,8 +784,6 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y
# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set
# CONFIG_ESP_SYSTEM_PANIC_GDBSTUB is not set
# CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set
-CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK=y
-CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y
#
# Memory protection
@@ -833,12 +799,8 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
-# CONFIG_ESP_CONSOLE_USB_CDC is not set
-# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
# CONFIG_ESP_CONSOLE_NONE is not set
-# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set
-CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
CONFIG_ESP_CONSOLE_UART=y
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y
CONFIG_ESP_CONSOLE_UART_NUM=0
@@ -853,7 +815,7 @@ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_ESP_PANIC_HANDLER_IRAM is not set
# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set
-CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_4=y
+CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5=y
# end of ESP System Settings
#
@@ -865,7 +827,8 @@ CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER=y
CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584
CONFIG_ESP_TIMER_INTERRUPT_LEVEL=1
# CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD is not set
-CONFIG_ESP_TIMER_IMPL_SYSTIMER=y
+# CONFIG_ESP_TIMER_IMPL_FRC2 is not set
+CONFIG_ESP_TIMER_IMPL_TG0_LAC=y
# end of High resolution timer (esp_timer)
#
@@ -889,13 +852,11 @@ CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
-CONFIG_ESP32_WIFI_IRAM_OPT=y
+# CONFIG_ESP32_WIFI_IRAM_OPT is not set
CONFIG_ESP32_WIFI_RX_IRAM_OPT=y
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
# CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set
-# CONFIG_ESP_WIFI_FTM_ENABLE is not set
# CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is not set
-# CONFIG_ESP_WIFI_GCMP_SUPPORT is not set
# CONFIG_ESP_WIFI_GMAC_SUPPORT is not set
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y
# CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT is not set
@@ -981,10 +942,10 @@ CONFIG_FMB_EVENT_QUEUE_TIMEOUT=20
#
# CONFIG_FREERTOS_UNICORE is not set
CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF
-CONFIG_FREERTOS_TICK_SUPPORT_SYSTIMER=y
-CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL1=y
-# CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL3 is not set
-CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER=y
+CONFIG_FREERTOS_TICK_SUPPORT_CORETIMER=y
+CONFIG_FREERTOS_CORETIMER_0=y
+# CONFIG_FREERTOS_CORETIMER_1 is not set
+CONFIG_FREERTOS_SYSTICK_USES_CCOUNT=y
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set
@@ -1013,6 +974,7 @@ CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
CONFIG_FREERTOS_DEBUG_OCDAWARE=y
+# CONFIG_FREERTOS_FPU_IN_ISR is not set
CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT=y
# CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH is not set
# end of FreeRTOS
@@ -1083,7 +1045,7 @@ CONFIG_LWIP_TCPIP_TASK_PRIO=18
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
# CONFIG_LWIP_L2_TO_L3_COPY is not set
-CONFIG_LWIP_IRAM_OPTIMIZATION=y
+# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
CONFIG_LWIP_TIMERS_ONDEMAND=y
CONFIG_LWIP_MAX_SOCKETS=10
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
@@ -1240,6 +1202,7 @@ CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y
# mbedTLS v2.28.x related
#
# CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set
+CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT=y
# CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set
# CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set
# end of mbedTLS v2.28.x related
@@ -1255,10 +1218,9 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=200
# end of Certificate Bundle
-# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
-# CONFIG_MBEDTLS_CMAC_C is not set
+CONFIG_MBEDTLS_ECP_RESTARTABLE=y
+CONFIG_MBEDTLS_CMAC_C=y
CONFIG_MBEDTLS_HARDWARE_AES=y
-CONFIG_MBEDTLS_AES_USE_INTERRUPT=y
CONFIG_MBEDTLS_HARDWARE_MPI=y
CONFIG_MBEDTLS_HARDWARE_SHA=y
CONFIG_MBEDTLS_ROM_MD5=y
@@ -1438,7 +1400,6 @@ CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
# CONFIG_SPI_FLASH_VERIFY_WRITE is not set
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
-# CONFIG_SPI_FLASH_ROM_IMPL is not set
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set
@@ -1462,7 +1423,6 @@ CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=y
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=y
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=y
-CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP=y
# end of Auto-detect flash chips
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=y
@@ -1516,12 +1476,6 @@ CONFIG_WS_BUFFER_SIZE=1024
# end of Websocket
# end of TCP Transport
-#
-# TinyUSB Stack
-#
-# CONFIG_TINYUSB is not set
-# end of TinyUSB Stack
-
#
# Unity unit testing library
#
@@ -1534,24 +1488,10 @@ CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y
# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set
# end of Unity unit testing library
-#
-# USB-OTG
-#
-CONFIG_USB_OTG_SUPPORTED=y
-CONFIG_USB_HOST_CONTROL_TRANSFER_MAX_SIZE=256
-CONFIG_USB_HOST_HW_BUFFER_BIAS_BALANCED=y
-# CONFIG_USB_HOST_HW_BUFFER_BIAS_IN is not set
-# CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT is not set
-
#
# Root Hub configuration
#
-CONFIG_USB_HOST_DEBOUNCE_DELAY_MS=250
-CONFIG_USB_HOST_RESET_HOLD_MS=30
-CONFIG_USB_HOST_RESET_RECOVERY_MS=30
-CONFIG_USB_HOST_SET_ADDR_RECOVERY_MS=10
# end of Root Hub configuration
-# end of USB-OTG
#
# Virtual file system
@@ -1622,3 +1562,366 @@ CONFIG_LUA_ROOT="/lua"
#
# CONFIG_LEGACY_INCLUDE_COMMON_HEADERS is not set
# end of Compatibility options
+
+# Deprecated options for backward compatibility
+CONFIG_TOOLPREFIX="xtensa-esp32s3-elf-"
+CONFIG_LOG_BOOTLOADER_LEVEL_NONE=y
+# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
+# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set
+# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set
+# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
+# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
+CONFIG_LOG_BOOTLOADER_LEVEL=0
+# CONFIG_APP_ROLLBACK_ENABLE is not set
+# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
+# CONFIG_FLASHMODE_QIO is not set
+# CONFIG_FLASHMODE_QOUT is not set
+CONFIG_FLASHMODE_DIO=y
+# CONFIG_FLASHMODE_DOUT is not set
+# CONFIG_MONITOR_BAUD_9600B is not set
+# CONFIG_MONITOR_BAUD_57600B is not set
+CONFIG_MONITOR_BAUD_115200B=y
+# CONFIG_MONITOR_BAUD_230400B is not set
+# CONFIG_MONITOR_BAUD_921600B is not set
+# CONFIG_MONITOR_BAUD_2MB is not set
+# CONFIG_MONITOR_BAUD_OTHER is not set
+CONFIG_MONITOR_BAUD_OTHER_VAL=115200
+CONFIG_MONITOR_BAUD=115200
+CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y
+# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set
+CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
+# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set
+# CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set
+CONFIG_OPTIMIZATION_ASSERTION_LEVEL=2
+# CONFIG_CXX_EXCEPTIONS is not set
+CONFIG_STACK_CHECK_NONE=y
+# CONFIG_STACK_CHECK_NORM is not set
+# CONFIG_STACK_CHECK_STRONG is not set
+# CONFIG_STACK_CHECK_ALL is not set
+# CONFIG_WARN_WRITE_STRINGS is not set
+# CONFIG_DISABLE_GCC8_WARNINGS is not set
+# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set
+CONFIG_ESP32_APPTRACE_DEST_NONE=y
+CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
+CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=y
+# CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY is not set
+# CONFIG_BTDM_CONTROLLER_MODE_BTDM is not set
+CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN=3
+CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=3
+CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=0
+CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0
+CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0
+CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y
+# CONFIG_BTDM_CONTROLLER_HCI_MODE_UART_H4 is not set
+CONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y
+CONFIG_BLE_SCAN_DUPLICATE=y
+CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR=y
+# CONFIG_SCAN_DUPLICATE_BY_ADV_DATA is not set
+# CONFIG_SCAN_DUPLICATE_BY_ADV_DATA_AND_DEVICE_ADDR is not set
+CONFIG_SCAN_DUPLICATE_TYPE=0
+CONFIG_DUPLICATE_SCAN_CACHE_SIZE=100
+# CONFIG_BLE_MESH_SCAN_DUPLICATE_EN is not set
+CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
+CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
+CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM=100
+CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
+CONFIG_BLUEDROID_ENABLED=y
+# CONFIG_NIMBLE_ENABLED is not set
+CONFIG_BTC_TASK_STACK_SIZE=3072
+CONFIG_BLUEDROID_PINNED_TO_CORE_0=y
+# CONFIG_BLUEDROID_PINNED_TO_CORE_1 is not set
+CONFIG_BLUEDROID_PINNED_TO_CORE=0
+CONFIG_BTU_TASK_STACK_SIZE=4096
+# CONFIG_BLUEDROID_MEM_DEBUG is not set
+# CONFIG_CLASSIC_BT_ENABLED is not set
+CONFIG_GATTS_ENABLE=y
+# CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set
+CONFIG_GATTS_SEND_SERVICE_CHANGE_AUTO=y
+CONFIG_GATTS_SEND_SERVICE_CHANGE_MODE=0
+CONFIG_GATTC_ENABLE=y
+# CONFIG_GATTC_CACHE_NVS_FLASH is not set
+CONFIG_BLE_SMP_ENABLE=y
+# CONFIG_SMP_SLAVE_CON_PARAMS_UPD_ENABLE is not set
+# CONFIG_HCI_TRACE_LEVEL_NONE is not set
+# CONFIG_HCI_TRACE_LEVEL_ERROR is not set
+CONFIG_HCI_TRACE_LEVEL_WARNING=y
+# CONFIG_HCI_TRACE_LEVEL_API is not set
+# CONFIG_HCI_TRACE_LEVEL_EVENT is not set
+# CONFIG_HCI_TRACE_LEVEL_DEBUG is not set
+# CONFIG_HCI_TRACE_LEVEL_VERBOSE is not set
+CONFIG_HCI_INITIAL_TRACE_LEVEL=2
+# CONFIG_BTM_TRACE_LEVEL_NONE is not set
+# CONFIG_BTM_TRACE_LEVEL_ERROR is not set
+CONFIG_BTM_TRACE_LEVEL_WARNING=y
+# CONFIG_BTM_TRACE_LEVEL_API is not set
+# CONFIG_BTM_TRACE_LEVEL_EVENT is not set
+# CONFIG_BTM_TRACE_LEVEL_DEBUG is not set
+# CONFIG_BTM_TRACE_LEVEL_VERBOSE is not set
+CONFIG_BTM_INITIAL_TRACE_LEVEL=2
+# CONFIG_L2CAP_TRACE_LEVEL_NONE is not set
+# CONFIG_L2CAP_TRACE_LEVEL_ERROR is not set
+CONFIG_L2CAP_TRACE_LEVEL_WARNING=y
+# CONFIG_L2CAP_TRACE_LEVEL_API is not set
+# CONFIG_L2CAP_TRACE_LEVEL_EVENT is not set
+# CONFIG_L2CAP_TRACE_LEVEL_DEBUG is not set
+# CONFIG_L2CAP_TRACE_LEVEL_VERBOSE is not set
+CONFIG_L2CAP_INITIAL_TRACE_LEVEL=2
+# CONFIG_RFCOMM_TRACE_LEVEL_NONE is not set
+# CONFIG_RFCOMM_TRACE_LEVEL_ERROR is not set
+CONFIG_RFCOMM_TRACE_LEVEL_WARNING=y
+# CONFIG_RFCOMM_TRACE_LEVEL_API is not set
+# CONFIG_RFCOMM_TRACE_LEVEL_EVENT is not set
+# CONFIG_RFCOMM_TRACE_LEVEL_DEBUG is not set
+# CONFIG_RFCOMM_TRACE_LEVEL_VERBOSE is not set
+CONFIG_RFCOMM_INITIAL_TRACE_LEVEL=2
+# CONFIG_SDP_TRACE_LEVEL_NONE is not set
+# CONFIG_SDP_TRACE_LEVEL_ERROR is not set
+CONFIG_SDP_TRACE_LEVEL_WARNING=y
+# CONFIG_SDP_TRACE_LEVEL_API is not set
+# CONFIG_SDP_TRACE_LEVEL_EVENT is not set
+# CONFIG_SDP_TRACE_LEVEL_DEBUG is not set
+# CONFIG_SDP_TRACE_LEVEL_VERBOSE is not set
+CONFIG_BTH_LOG_SDP_INITIAL_TRACE_LEVEL=2
+# CONFIG_GAP_TRACE_LEVEL_NONE is not set
+# CONFIG_GAP_TRACE_LEVEL_ERROR is not set
+CONFIG_GAP_TRACE_LEVEL_WARNING=y
+# CONFIG_GAP_TRACE_LEVEL_API is not set
+# CONFIG_GAP_TRACE_LEVEL_EVENT is not set
+# CONFIG_GAP_TRACE_LEVEL_DEBUG is not set
+# CONFIG_GAP_TRACE_LEVEL_VERBOSE is not set
+CONFIG_GAP_INITIAL_TRACE_LEVEL=2
+CONFIG_BNEP_INITIAL_TRACE_LEVEL=2
+# CONFIG_PAN_TRACE_LEVEL_NONE is not set
+# CONFIG_PAN_TRACE_LEVEL_ERROR is not set
+CONFIG_PAN_TRACE_LEVEL_WARNING=y
+# CONFIG_PAN_TRACE_LEVEL_API is not set
+# CONFIG_PAN_TRACE_LEVEL_EVENT is not set
+# CONFIG_PAN_TRACE_LEVEL_DEBUG is not set
+# CONFIG_PAN_TRACE_LEVEL_VERBOSE is not set
+CONFIG_PAN_INITIAL_TRACE_LEVEL=2
+# CONFIG_A2D_TRACE_LEVEL_NONE is not set
+# CONFIG_A2D_TRACE_LEVEL_ERROR is not set
+CONFIG_A2D_TRACE_LEVEL_WARNING=y
+# CONFIG_A2D_TRACE_LEVEL_API is not set
+# CONFIG_A2D_TRACE_LEVEL_EVENT is not set
+# CONFIG_A2D_TRACE_LEVEL_DEBUG is not set
+# CONFIG_A2D_TRACE_LEVEL_VERBOSE is not set
+CONFIG_A2D_INITIAL_TRACE_LEVEL=2
+# CONFIG_AVDT_TRACE_LEVEL_NONE is not set
+# CONFIG_AVDT_TRACE_LEVEL_ERROR is not set
+CONFIG_AVDT_TRACE_LEVEL_WARNING=y
+# CONFIG_AVDT_TRACE_LEVEL_API is not set
+# CONFIG_AVDT_TRACE_LEVEL_EVENT is not set
+# CONFIG_AVDT_TRACE_LEVEL_DEBUG is not set
+# CONFIG_AVDT_TRACE_LEVEL_VERBOSE is not set
+CONFIG_AVDT_INITIAL_TRACE_LEVEL=2
+# CONFIG_AVCT_TRACE_LEVEL_NONE is not set
+# CONFIG_AVCT_TRACE_LEVEL_ERROR is not set
+CONFIG_AVCT_TRACE_LEVEL_WARNING=y
+# CONFIG_AVCT_TRACE_LEVEL_API is not set
+# CONFIG_AVCT_TRACE_LEVEL_EVENT is not set
+# CONFIG_AVCT_TRACE_LEVEL_DEBUG is not set
+# CONFIG_AVCT_TRACE_LEVEL_VERBOSE is not set
+CONFIG_AVCT_INITIAL_TRACE_LEVEL=2
+# CONFIG_AVRC_TRACE_LEVEL_NONE is not set
+# CONFIG_AVRC_TRACE_LEVEL_ERROR is not set
+CONFIG_AVRC_TRACE_LEVEL_WARNING=y
+# CONFIG_AVRC_TRACE_LEVEL_API is not set
+# CONFIG_AVRC_TRACE_LEVEL_EVENT is not set
+# CONFIG_AVRC_TRACE_LEVEL_DEBUG is not set
+# CONFIG_AVRC_TRACE_LEVEL_VERBOSE is not set
+CONFIG_AVRC_INITIAL_TRACE_LEVEL=2
+# CONFIG_MCA_TRACE_LEVEL_NONE is not set
+# CONFIG_MCA_TRACE_LEVEL_ERROR is not set
+CONFIG_MCA_TRACE_LEVEL_WARNING=y
+# CONFIG_MCA_TRACE_LEVEL_API is not set
+# CONFIG_MCA_TRACE_LEVEL_EVENT is not set
+# CONFIG_MCA_TRACE_LEVEL_DEBUG is not set
+# CONFIG_MCA_TRACE_LEVEL_VERBOSE is not set
+CONFIG_MCA_INITIAL_TRACE_LEVEL=2
+# CONFIG_HID_TRACE_LEVEL_NONE is not set
+# CONFIG_HID_TRACE_LEVEL_ERROR is not set
+CONFIG_HID_TRACE_LEVEL_WARNING=y
+# CONFIG_HID_TRACE_LEVEL_API is not set
+# CONFIG_HID_TRACE_LEVEL_EVENT is not set
+# CONFIG_HID_TRACE_LEVEL_DEBUG is not set
+# CONFIG_HID_TRACE_LEVEL_VERBOSE is not set
+CONFIG_HID_INITIAL_TRACE_LEVEL=2
+# CONFIG_APPL_TRACE_LEVEL_NONE is not set
+# CONFIG_APPL_TRACE_LEVEL_ERROR is not set
+CONFIG_APPL_TRACE_LEVEL_WARNING=y
+# CONFIG_APPL_TRACE_LEVEL_API is not set
+# CONFIG_APPL_TRACE_LEVEL_EVENT is not set
+# CONFIG_APPL_TRACE_LEVEL_DEBUG is not set
+# CONFIG_APPL_TRACE_LEVEL_VERBOSE is not set
+CONFIG_APPL_INITIAL_TRACE_LEVEL=2
+# CONFIG_GATT_TRACE_LEVEL_NONE is not set
+# CONFIG_GATT_TRACE_LEVEL_ERROR is not set
+CONFIG_GATT_TRACE_LEVEL_WARNING=y
+# CONFIG_GATT_TRACE_LEVEL_API is not set
+# CONFIG_GATT_TRACE_LEVEL_EVENT is not set
+# CONFIG_GATT_TRACE_LEVEL_DEBUG is not set
+# CONFIG_GATT_TRACE_LEVEL_VERBOSE is not set
+CONFIG_GATT_INITIAL_TRACE_LEVEL=2
+# CONFIG_SMP_TRACE_LEVEL_NONE is not set
+# CONFIG_SMP_TRACE_LEVEL_ERROR is not set
+CONFIG_SMP_TRACE_LEVEL_WARNING=y
+# CONFIG_SMP_TRACE_LEVEL_API is not set
+# CONFIG_SMP_TRACE_LEVEL_EVENT is not set
+# CONFIG_SMP_TRACE_LEVEL_DEBUG is not set
+# CONFIG_SMP_TRACE_LEVEL_VERBOSE is not set
+CONFIG_SMP_INITIAL_TRACE_LEVEL=2
+# CONFIG_BTIF_TRACE_LEVEL_NONE is not set
+# CONFIG_BTIF_TRACE_LEVEL_ERROR is not set
+CONFIG_BTIF_TRACE_LEVEL_WARNING=y
+# CONFIG_BTIF_TRACE_LEVEL_API is not set
+# CONFIG_BTIF_TRACE_LEVEL_EVENT is not set
+# CONFIG_BTIF_TRACE_LEVEL_DEBUG is not set
+# CONFIG_BTIF_TRACE_LEVEL_VERBOSE is not set
+CONFIG_BTIF_INITIAL_TRACE_LEVEL=2
+# CONFIG_BTC_TRACE_LEVEL_NONE is not set
+# CONFIG_BTC_TRACE_LEVEL_ERROR is not set
+CONFIG_BTC_TRACE_LEVEL_WARNING=y
+# CONFIG_BTC_TRACE_LEVEL_API is not set
+# CONFIG_BTC_TRACE_LEVEL_EVENT is not set
+# CONFIG_BTC_TRACE_LEVEL_DEBUG is not set
+# CONFIG_BTC_TRACE_LEVEL_VERBOSE is not set
+CONFIG_BTC_INITIAL_TRACE_LEVEL=2
+# CONFIG_OSI_TRACE_LEVEL_NONE is not set
+# CONFIG_OSI_TRACE_LEVEL_ERROR is not set
+CONFIG_OSI_TRACE_LEVEL_WARNING=y
+# CONFIG_OSI_TRACE_LEVEL_API is not set
+# CONFIG_OSI_TRACE_LEVEL_EVENT is not set
+# CONFIG_OSI_TRACE_LEVEL_DEBUG is not set
+# CONFIG_OSI_TRACE_LEVEL_VERBOSE is not set
+CONFIG_OSI_INITIAL_TRACE_LEVEL=2
+# CONFIG_BLUFI_TRACE_LEVEL_NONE is not set
+# CONFIG_BLUFI_TRACE_LEVEL_ERROR is not set
+CONFIG_BLUFI_TRACE_LEVEL_WARNING=y
+# CONFIG_BLUFI_TRACE_LEVEL_API is not set
+# CONFIG_BLUFI_TRACE_LEVEL_EVENT is not set
+# CONFIG_BLUFI_TRACE_LEVEL_DEBUG is not set
+# CONFIG_BLUFI_TRACE_LEVEL_VERBOSE is not set
+CONFIG_BLUFI_INITIAL_TRACE_LEVEL=2
+# CONFIG_BLE_HOST_QUEUE_CONGESTION_CHECK is not set
+CONFIG_SMP_ENABLE=y
+# CONFIG_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY is not set
+CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30
+CONFIG_ADC2_DISABLE_DAC=y
+# CONFIG_SPIRAM_SUPPORT is not set
+CONFIG_TRACEMEM_RESERVE_DRAM=0x0
+# CONFIG_ULP_COPROC_ENABLED is not set
+CONFIG_ULP_COPROC_RESERVE_MEM=0
+CONFIG_BROWNOUT_DET=y
+CONFIG_BROWNOUT_DET_LVL_SEL_0=y
+# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set
+# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set
+CONFIG_BROWNOUT_DET_LVL=0
+CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
+# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set
+# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC is not set
+# CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_8MD256 is not set
+# CONFIG_DISABLE_BASIC_ROM_CONSOLE is not set
+# CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set
+# CONFIG_EVENT_LOOP_PROFILING is not set
+CONFIG_POST_EVENTS_FROM_ISR=y
+CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
+# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
+CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
+CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
+CONFIG_ESP_SYSTEM_PD_FLASH=y
+CONFIG_ESP32C3_LIGHTSLEEP_GPIO_RESET_WORKAROUND=y
+CONFIG_IPC_TASK_STACK_SIZE=1536
+CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
+# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set
+CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20
+CONFIG_ESP32_PHY_MAX_TX_POWER=20
+# CONFIG_ESP32_REDUCE_PHY_TX_POWER is not set
+# CONFIG_ESP32S2_PANIC_PRINT_HALT is not set
+CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y
+# CONFIG_ESP32S2_PANIC_SILENT_REBOOT is not set
+# CONFIG_ESP32S2_PANIC_GDBSTUB is not set
+CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
+CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=3072
+CONFIG_MAIN_TASK_STACK_SIZE=3584
+CONFIG_CONSOLE_UART_DEFAULT=y
+# CONFIG_CONSOLE_UART_CUSTOM is not set
+# CONFIG_ESP_CONSOLE_UART_NONE is not set
+CONFIG_CONSOLE_UART=y
+CONFIG_CONSOLE_UART_NUM=0
+CONFIG_CONSOLE_UART_BAUDRATE=115200
+CONFIG_INT_WDT=y
+CONFIG_INT_WDT_TIMEOUT_MS=300
+CONFIG_INT_WDT_CHECK_CPU1=y
+CONFIG_TASK_WDT=y
+# CONFIG_TASK_WDT_PANIC is not set
+CONFIG_TASK_WDT_TIMEOUT_S=5
+CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
+CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
+# CONFIG_ESP32_DEBUG_STUBS_ENABLE is not set
+CONFIG_TIMER_TASK_STACK_SIZE=3584
+CONFIG_SW_COEXIST_ENABLE=y
+# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
+# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
+CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
+CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND=150
+CONFIG_MB_MASTER_DELAY_MS_CONVERT=200
+CONFIG_MB_QUEUE_LENGTH=20
+CONFIG_MB_SERIAL_TASK_STACK_SIZE=4096
+CONFIG_MB_SERIAL_BUF_SIZE=256
+CONFIG_MB_SERIAL_TASK_PRIO=10
+CONFIG_MB_CONTROLLER_SLAVE_ID_SUPPORT=y
+CONFIG_MB_CONTROLLER_SLAVE_ID=0x00112233
+CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT=20
+CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE=20
+CONFIG_MB_CONTROLLER_STACK_SIZE=4096
+CONFIG_MB_EVENT_QUEUE_TIMEOUT=20
+# CONFIG_MB_TIMER_PORT_ENABLED is not set
+# CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK is not set
+CONFIG_TIMER_TASK_PRIORITY=1
+CONFIG_TIMER_TASK_STACK_DEPTH=2048
+CONFIG_TIMER_QUEUE_LENGTH=10
+# CONFIG_L2_TO_L3_COPY is not set
+# CONFIG_USE_ONLY_LWIP_SELECT is not set
+CONFIG_ESP_GRATUITOUS_ARP=y
+CONFIG_GARP_TMR_INTERVAL=60
+CONFIG_TCPIP_RECVMBOX_SIZE=16
+CONFIG_TCP_MAXRTX=12
+CONFIG_TCP_SYNMAXRTX=12
+CONFIG_TCP_MSS=1440
+CONFIG_TCP_MSL=60000
+CONFIG_TCP_SND_BUF_DEFAULT=5744
+CONFIG_TCP_WND_DEFAULT=5744
+CONFIG_TCP_RECVMBOX_SIZE=6
+CONFIG_TCP_QUEUE_OOSEQ=y
+# CONFIG_ESP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
+CONFIG_TCP_OVERSIZE_MSS=y
+# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set
+# CONFIG_TCP_OVERSIZE_DISABLE is not set
+CONFIG_UDP_RECVMBOX_SIZE=6
+CONFIG_TCPIP_TASK_STACK_SIZE=3072
+CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY=y
+# CONFIG_TCPIP_TASK_AFFINITY_CPU0 is not set
+# CONFIG_TCPIP_TASK_AFFINITY_CPU1 is not set
+CONFIG_TCPIP_TASK_AFFINITY=0x7FFFFFFF
+# CONFIG_PPP_SUPPORT is not set
+CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5
+CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072
+CONFIG_ESP32_PTHREAD_STACK_MIN=768
+CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=y
+# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0 is not set
+# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1 is not set
+CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=-1
+CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread"
+CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y
+# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS is not set
+# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED is not set
+CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y
+CONFIG_SUPPORT_TERMIOS=y
+CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS=1
+# End of deprecated options