application for alarm project collect data

mohasrj
Posts: 33
Joined: Mon Jan 20, 2020 9:38 am

application for alarm project collect data

Postby mohasrj » Thu Jul 16, 2020 12:37 pm

hi,

iam working on application for alarm with esp32 and esp idf framework with i2c sensor using i2cdev driver (https://github.com/UncleRus/esp-idf-lib)

so i want to develop esp32 board with i can connect until 8 i2c sensor and i can connect the same device with the same adresse at the same time so iam using software i2c for each socket i have BUS i2c with different pin SCL/SDA .

so all work well try to connect 8 bme280 at same time i can print all data and i can detect type of sensor witch is connected to socket that work with i2cscanner and i can create table of sensor found .

the problem is i need to collect data with one file json for all sensor to send it with mqtt (mqtt send work)
how i can do that from table of sensor found bcs this table change (one sensor ,5 sensor,3sensor,..max 8 and the same sensor or not)


some one can can help me to find the best method to create json file depend table of device found , how i can change json in terms of number and type of sensor connect and i want send data each 10s and when the value change with 5 unity (dont wait 10s to send data i need send it immediately )
Attachments
Capture.PNG
Capture.PNG (382.85 KiB) Viewed 6649 times
Last edited by mohasrj on Fri Jul 17, 2020 4:01 pm, edited 2 times in total.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: application for alarm project collect data

Postby chegewara » Thu Jul 16, 2020 2:24 pm

mohasrj wrote:
Thu Jul 16, 2020 12:37 pm
so i want to develop esp32 board with i can connect until 8 i2c sensor and i can connect the same device with the same adresse at the same time
There is something like I2C expander. You can connect more than one i2c slave on the same line:
https://www.ti.com/lit/ds/symlink/tca95 ... e.com%252F

It is popular IC, so you will find a lot materials.

mohasrj
Posts: 33
Joined: Mon Jan 20, 2020 9:38 am

Re: application for alarm project collect data

Postby mohasrj » Thu Jul 16, 2020 2:45 pm

yes i try with it it work but its more difficult to manage it but u select one device at the same time ... so is not that the problem whit software i2c that work well , but how i can collect data dynamically (if i have one sensor i send data for one sensor if i have 5,3 or 8 ...)

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: application for alarm project collect data

Postby chegewara » Thu Jul 16, 2020 3:02 pm

With software i2c you can read 1 device at the time too. Eventually 2 devices if you use 2 cores, but you have 2 hardware i2c on esp32.
For sure you cant read 8 devices at the same very moment.

It was just suggestion, nothing more.

mohasrj
Posts: 33
Joined: Mon Jan 20, 2020 9:38 am

Re: application for alarm project collect data

Postby mohasrj » Thu Jul 16, 2020 4:11 pm

yes but iam using FreeRTOS library and software i2c with i2cdev driver i start 8 task at the same time in one core u think is the same if i use one task to read them ? that not take more time , but i work with alarm project i need detect quickly any change value ?

http://www.chibios.com/forum/viewtopic. ... a&start=10

https://microcontrollerslab.com/arduino ... resources/

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: application for alarm project collect data

Postby chegewara » Thu Jul 16, 2020 5:41 pm

esp32 has only 2 cores, that means you can run at most 2 tasks at the same time, other tasks are awaiting to resume.
They will be switching in round robin, assuming that all tasks are with the same priority (i2c tasks).

You are only complicating your code and life, because its easier to maintain 1 task (or 2) if you cant run more than 2 tasks simultaneously.
Now, is another thing. If you want to run 2 tasks on 2 cores in exactly the same time you will have to synchronize with semaphores or tasknotify.

You can do a simple test with 8 tasks blinking 8 leds and use logic analyzer to see results.

Scott.Bonomi
Posts: 73
Joined: Mon Mar 09, 2020 7:36 pm

Re: application for alarm project collect data

Postby Scott.Bonomi » Thu Jul 16, 2020 7:31 pm

All of your requirements are not clear. I think I would design this as two tasks, one to collect information from all sensors at the rate that works best. The second task would be reporting, so send every report period unless change greater than trigger_level happened since last report. You should manage semaphores between the collection for sensor(A) and evaluating or reporting Sensor(A).
You can have mailboxes that contain a new reading and the reporter reads the mail. You could have interrupts if the new reading is more than trigger_level different than last reported. Questions like that get into what your real requirements are. an interrupt to say report Sensor(C) which is now above trigger_level difference, might well be interrupting the scheduled report of Sensor(C) and the last reported value has not made it back to the measuring side so it sets an interrupt.
If reporter is scanning last measurements twice as fast as the measuring task, and you are not dealing with a time critical issue, You should be able to have a relatively simple reporter.

mohasrj
Posts: 33
Joined: Mon Jan 20, 2020 9:38 am

Re: application for alarm project collect data

Postby mohasrj » Fri Jul 17, 2020 8:53 am

in my application i have 4 sensor (maybe i will add another type ) (bme280,bh1750,mcp3428,and pcf8574 ) using (UncleRus/esp-idf-lib) and the customer can plugin what he want in 8 socket (same type or different type) and my code can adapt automatic with device connecting and initialize and start read those device detected (if one or more are Unplug the code send error in topic and stop to read )

Who is online

Users browsing this forum: No registered users and 92 guests