Refactoring multi thread program on raspberry pi with sensors

0 votes
I am doing a IoT experiment with raspberry pis and sensors aiming to monitor temperature change. Each raspberry pi is connected to multiple sensors. My goal is to have one reading per sensor per second, store the data in a buffer(real buffer or a csv file) and publish the data to a broker. The program now is doing all things in queue. It turns out some delay. I have tested and it turns out the delay comes from reading process. Is there any way to reduce reading delay? Will multi threading solve this problem? If so, what I think is to create 3 thread. Sensor thread read the data and store in a buffer. Communicator thread connect to the broker, read the data in buffer and send it to the broker. Main thread will manage sensor thread and communicator thread. If I refactor the program in this way, do I write one sensor thread for each sensor or one sensor thread for all sensors?

Any suggestions will be greatly appreciated.
Sep 11, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
1,869 views

1 answer to this question.

0 votes

Before re-engineering your application, you should narrow down where the bottleneck is. To diagnose this, I would try logging the start and end of each read from your sensors to a string buffer you keep in memory. Do this for 30 seconds or so. Then, stop reading from the sensors and write the buffer to a log file. If the log file shows delays between the start and end of each of the sensor reads, then that's where the bottleneck is. If it doesn't, then the bottleneck is probably in continually writing your CSV file to disk.

answered Sep 11, 2018 by Upasana
• 8,620 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Integrating ultrasonic sensors with Raspberry pi using c#

DateTime is the problem You should use the ...READ MORE

answered Oct 3, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
2,291 views
0 votes
1 answer

Firewall issue with Webserver in UWP on Raspberry Pi 3

Here's what could be happenning: You port hasn't ...READ MORE

answered Oct 12, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,095 views
0 votes
1 answer

Issue with connection on Watson IoT Out node on Raspberry Pi

The frequent disconnects could be due to ...READ MORE

answered Dec 20, 2018 in IoT (Internet of Things) by Shubham
• 13,490 points
953 views
0 votes
1 answer
0 votes
1 answer

Setting-up a RFID RC522 chip in Raspberry Pi?

First, let me congratulate you on buying ...READ MORE

answered Jul 10, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,643 views
0 votes
1 answer

Autostart published Application on Windows 10 IoT

It can be done by making changes ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,774 views
0 votes
1 answer

How to deploy Windows 10 IoT (Rasp Pi image) as a Virtual Machine

The easiest way I found is downloading ...READ MORE

answered Sep 10, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
3,153 views
0 votes
1 answer

Error when connecting Azure IoT Suite with Raspberry Pi

down vote I've verified the tutorial works on ...READ MORE

answered Sep 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
879 views
0 votes
1 answer
0 votes
1 answer

How to trigger Python script on Raspberry Pi from Node-Red

Node-RED supplies an exec node as part ...READ MORE

answered Sep 14, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
3,258 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP