{"id":186,"date":"2018-07-09T21:22:50","date_gmt":"2018-07-10T04:22:50","guid":{"rendered":"http:\/\/dragonwarz.net\/?p=186"},"modified":"2018-07-09T21:37:03","modified_gmt":"2018-07-10T04:37:03","slug":"using-python3-to-collect-and-manipulate-sensehat-sensor-data","status":"publish","type":"post","link":"https:\/\/dragonwarz.net\/?p=186","title":{"rendered":"Using Python3 to collect and manipulate SenseHAT Sensor data"},"content":{"rendered":"<p>So, as I said in my last post, I want to digitize the world around me, starting with the sensors on my Raspberry Pi 3B+ and SenseHAT attachment.&nbsp;&nbsp;<\/p>\n<p>After much thinking, writing down ideas and generally trying things out, I finally got things working the&nbsp;way I wanted for the most part.&nbsp; Here&#39;s what I have so far.<\/p>\n<p>1.&nbsp; Sensor Units: These are the Pi&#39;s with the SenseHAT and have the following programs running to enable the features I want (Only the HTTP server is not done by me, I just installed one).&nbsp;<\/p>\n<ul>\n<li>Sensor Readings to File: A simple program that reads &quot;all&quot; the sensors and writes the results as a string, each value separated by a &quot;,&quot;. It creates one line each time its run.&nbsp; It auto runs every 5 min through cron (Linux scheduler).&nbsp; You could also do something similar with Windows &quot;Task Scheduler&quot;.<\/li>\n<li>HTTP Server:&nbsp; The HTTP&nbsp;server just lists and allows downloads of the sensor data files.&nbsp;<\/li>\n<li>SenseHAT Joystick Controls: A small program auto runs with the pi and allows you to use the 5 &quot;button&quot; joystick to run commands and display info on the 8&#215;8 LED grid.&nbsp; It currently does the following, which helps a great deal when there is nothing attached but the SenseHAT and power.&nbsp; I also have VNC \/ SSH enabled on the Pi&#39;s to connect remotely.&nbsp;&nbsp;\n<ul>\n<li>1. Display IP<\/li>\n<li>2.&nbsp;Display CPU Temp<\/li>\n<li>3.&nbsp;Display SenseHAT Temp<\/li>\n<li>4.&nbsp;Shutdown<\/li>\n<\/ul>\n<\/li>\n<li>Sensor Data over WiFi: Another small program runs automatically and listens on the network for my client app to request data.&nbsp;&nbsp;<\/li>\n<\/ul>\n<p>2.&nbsp; Portable Sensor Data Display and File Downloader:&nbsp; This is a PI with a 2.7&quot; E-Ink display with 4 buttons.&nbsp; It simply runs one program on boot to&nbsp;do the following.<\/p>\n<ul>\n<li>Show it&#39;s own system information, including IP<\/li>\n<li>Display Current Sensor Readings<\/li>\n<li>Download Sensor Data Files<\/li>\n<li>Shutdown<\/li>\n<\/ul>\n<p>3.&nbsp; PC: I made a more in depth GUI app for the PC, that can connect remotely to the units to gather information.&nbsp; It has a lot more options, and is a bit easier to show a picture.&nbsp;<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/dragonwarz.net\/wp-content\/uploads\/2018\/07\/Program1.png\" rel=\"\" style=\"\" target=\"_blank\" title=\"\"><div id=\"attachment_188\" style=\"width: 630px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-188\" alt=\"\" class=\"size-large wp-image-188 aligncenter\" height=\"458\" src=\"http:\/\/dragonwarz.net\/wp-content\/uploads\/2018\/07\/Program1-1024x757.png\" style=\"\" title=\"Python3 Sensor App\" width=\"620\" srcset=\"https:\/\/dragonwarz.net\/wp-content\/uploads\/2018\/07\/Program1-1024x757.png 1024w, https:\/\/dragonwarz.net\/wp-content\/uploads\/2018\/07\/Program1-300x222.png 300w, https:\/\/dragonwarz.net\/wp-content\/uploads\/2018\/07\/Program1-768x568.png 768w, https:\/\/dragonwarz.net\/wp-content\/uploads\/2018\/07\/Program1.png 1294w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><p id=\"caption-attachment-188\" class=\"wp-caption-text\">Python3 Sensor App<\/p><\/div><\/a><\/p>\n<p>Its still a work in progress, but as you can see, I can already compare Sensor readings over time.&nbsp; I can also specify how many entries to skip when graphing the data files, as there should be about 288 entries for a day, after which, the program creates a new file for that day.&nbsp; Plotting 288 points can not only take a bit of resources, but also isn&#39;t needed for most things being looked at. So I set it at 12 by default, so it shows a reading every hour.&nbsp;&nbsp;<\/p>\n<p>All these separate systems, apps and scripts connect through a mini router I got for $35 that&#39;s powered by USB.&nbsp; This enables me to take the E-Ink pi and the mini router, power them both up off a USB battery Bank and&nbsp;wait about 2 min for the Units to boot and the Sensor Units to&nbsp;auto connect to WiFi, and I can then pull data remotely from the units, up to however far the router&#39;s and pi&#39;s range are (50-100 meters?).&nbsp; Great for putting Sensors on tree&#39;s, in water, down a hole, etc, etc.&nbsp;&nbsp;<\/p>\n<p>I also enabled a OpenVPN server on the router itself, allowing me to connect through the internet and grab the sensor data with my PC program.&nbsp; This can be done, even from remote sites through 3G or 4G connectivity (AKA cell phone service). Simply add a USB dongle for 3G \/ 4G to the router, and BAM, I can suddenly connect a lot of units, within a decent range to the internet for remote monitoring and maintenance!&nbsp;&nbsp;<\/p>\n<p>That&#39;s pretty much were I am at now.&nbsp; I&#39;m also working on other aspects like Pi Cases for weather proofing or even water and underwater deployment.&nbsp; High altitude balloons are also in the future.&nbsp;&nbsp;<\/p>\n<p>I think that about does it for this post.&nbsp; I&#39;ll eventually post my Python code too, but I wanted to clean it up and add some comments to explain things first (being my first Python project and all).&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, as I said in my last post, I want to digitize the world around me, starting with the sensors on my Raspberry Pi 3B+ and SenseHAT attachment.&nbsp;&nbsp; After much thinking, writing down ideas and generally trying things out, I &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/dragonwarz.net\/?p=186\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,26,3],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-project","category-python","category-random"],"_links":{"self":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186"}],"version-history":[{"count":15,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":202,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions\/202"}],"wp:attachment":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}