HTTPS Enabled!

I am now using HTTPS instead of HTTP. I even have self-signed certificates generate automatically if they are not present in the ssl_files folder. This allows 3 things.

  1. If you don’t have your own certificates, it creates them when the program launches, creating a user-friendly experience. If they are already in the folder, it simply loads them.
  2. You can replace the certificate files in the ssl_files folder with your own to get the nice green bar in your browser.
  3. Simply delete all the files in the ssl_files folder, reboot the sensor and you have new certificates that are good for 5 years.

Initially, I thought that incorrect time on the sensor would not allow you to connect to the sensor through SSL, but I modified the time by 17 hours and it still connected just fine. So that’s good, as I was worried when the Pi’s reboot or shut down for a bit, the time would drift without internet and you would be unable to configure it after that. I’m glad I was wrong!

Now the sensors are actually decently secure! With HTTP authentication and unique SSL generation per sensor, you can rest assured your commands and logins will not be ‘sniffed’ off the network.

One last thing I wanted to do is redirect any HTTP traffic to HTTPS, but I’m not sure how to make that happen with the webserver module I’m using in Python (gevent’s pywsgi).

I have now started to work on updating documentation since a lot has changed. Once that’s done, I’ll probably release another version.

On another note, I used chromes developer console to see the difference of page delivery sizes with gzip enabled. It really helped on the plotly graph’s, as it cut the download size to 1/4 and since they are usually about 4MBs, it makes a difference.

Tweaking Installer Scripts

Since the sensor software is working fairly well, I’m making sure the installer scripts are where they should be. I want to be able to flash Raspbian, download the installer script, run it and have everything just work. So to that end, I made the following changes.

To start, I added in the CLI commands to enable SPI and i2c in the installer script, along with the rfkill unblock wifi to enable wifi on the Pi Zeros (Didn’t seem necessary on the Pi3B+, just the country code allowed it to work). I have also added a function in the Enviro+ sensor module to enable the serial connection for the PSM5003, if it is enabled. The only downfall of the PSM5003 settings is the system has to reboot before it takes effect. So if you enable the PSM5003, you need to allow the program to start up, then reboot the system. It also leaves a warning message in the primary log to reboot.

Thanks to the above-mentioned additions, you can just flash a fresh Raspbian image, download and run the Sensor installer script and everything starts to work! If you have the desktop version of Raspbian installed, there is even a shortcut to the web config in the menu that points to localhost. If you use the lite version of Raspbian without a desktop, you’ll need to access the web configuration from another device (computer, phone, tablet, etc) through its actual IP address OR run the edit-config script locally (Although the script to edit configurations just opens the text files, so it’s not as nice as the web interface).

Development Updates

I have been spending some time working on the web interface for my sensors. I’m pretty happy with the configuration section now, which no longer has any text editors for updating the configuration, it is all web checkboxes, textboxes, radios, and buttons, which all have validation checks in place to make sure user entries are valid (for the most part).

I have also updated the underlying networking configuration to use dhcpcd.conf instead of interfaces. This has the advantage of being able to set static entries per network interface while allowing the use of any other installed adapters. AKA you can still plug in the Ethernet cord into the Pi3b+ for example and get a DHCP address, even if the wireless is configured with static entries. I had to remove the dual wireless network connections in wpa_supplicant.conf, as certain configurations would kill networking altogether, so… better safe than sorry. I might go back and figure it out later, but it’s not really necessary, so it’s on the back burner.

I fixed a few bugs, like the graphing showing incorrect datestamp correlations if a sensor was added later or disabled temporarily. This was caused by my attempt to re-use the datetime recording column for all sensors because they all use the same column, but if a sensor was added later, there would be a big NULL gap, so the first datetime columns would line up with the first actual data of a sensor column. To fix it, I grab the datetime column based on the presence of each sensor reading. Luckily it didn’t seem to add TOO much extra time to render the graphs.

I also added gzip page compression to Flask, which downs the page transfer sizes decently. This will help if I set up some 900Mhz long-distance transmitters since their data rates are not great.

Other changes in no particular order include

  • Refactoring aspects of the web interface, such as using HTML tabs to go through configurations and log entries (This makes it a lot easier to look over things quickly, instead of having to bounce back to the management page to choose another configuration or log.
  • Adjusted plotly graphs to use a dark theme
  • Created file for cached variables to lessen disk reads
  • Updated Ohms Gas resistance to K Ohms for easier human readability
  • Standardized HTML element colors
  • Added links to many sections to help explain what it is (Sensor readings, for example, take you to the Wiki page for what it is)
  • Other misc. refactoring and bug fixes

I’m getting closer to releasing a beta version, as a lot of the core parts are pretty stable. The networking was also problematic since it used to disable all other networks and was not easily adjustable. Now it works well and allows it to be configured in such a way that the device can still be used online in other ways besides being a sensor.

The web app is coming along nicely, which will eventually overtake the PC Control Center App (I pretty much just have to add the ability to manage multiple sensors from the web app).

That’s it for today’s update.

New Release Ver. Alpha.25.252

Another release! I actually released this one awhile ago, and am already on development version Alpha.26.140, of which I have changed a fair amount again but I should probably start by saying whats new in 25.252.

To start, I have been spending a fair amount of time researching and implementing CSS with a framework called “MUI“. It has some great looking functions to create buttons, tabs, dropdown menus, etc. I’m also slowly figuring out how to adjust multiple HTML components by using style to target classes, names, ids, etc. So that’s coming along nicely and the web interface looks a lot nicer thanks to it. I actually don’t have any sensors running the previous version, so I kinda forget a bunch of what I did, but I’m pretty sure I added a bunch of functions, such as updating to standard or development editions, edit configuration files, reboot/shutdown/restart services and view, download and even clear logs.

In my Development build, I have added the following in no particular order.

  1. New CSS side menu
  2. New Log Viewer page
  3. New Configuration adjustment page
  4. Ability to create and view Plotly graphs from the local sensor webpage
  5. Other visual adjustments, enhancements & bug fixes

I’m still working on improving the look, feel and functionality of the web interface and to that end I’ll be putting in an option for different themes since I know not everyone is a fan of the dark theme I have going.

Another thing I have been working on for a few days is getting the Particulate Matter and GAS sensors working properly for recording and it’s now working fairly well. Since the PM and GAS need to “warm-up”, I created threads to constantly pull data every second to keep it alive for more accurate recordings. It seems to be working and I’m now gathering Air Quality data for both inside my house and out. Unfortunately, I did not have it working in time to get readings before and after a good smoke session came through from local forest fires, but Its recording now for future events.

The last thing I’ll say, is I’m planning on adding a link to a demo unit on my website, so people can check it out without installing it (not that it’s hard to install if you have a raspberry pi).

Until next time!

HTTP Improvements

I have decided to improve my Flask app itself, in order to standardize the HTML pages. Before starting these changes, Kootnet Sensors used python functions to add HTML code around the Sensor data and put that into an HTML page, which was returned through a flask route. However, I learned a few months ago about the flask render_template() function, which simply put, works much better and is clearer to understand what it’s doing. It also makes customizing the HTML templates really easy! AKA you can move things around in the .html template files and have it look completely different yet maintain all the sensor data retrieval (Especially nice since my HTML and CSS skills are lacking).
I have already converted my home page (index.html) and my quick links page that shows all the sensor info and links. I also added a bit of mui CSS to get the main menu bar and have the mui loaded from the local sensor, so it still works when not connected online.
Long story short, this is setting an awesome foundation for my flask App.

Once I’m mostly done with the flask render templates, I’ll start looking at HTML and CSS in more depth to improve the look and feel of the HTML pages. Once that’s done, I’ll actually have a half-decent web app! In between these other improvements, I’ll slowly add more function to the pages like configuration updates, display access and even using the local database to create an HTML Plotly graph.

HTTP Authentication!

I finally got around to putting in a bit of security. Now people can’t just go around rebooting, shutting down or changing the settings on my Sensors. I have worked Basic HTTP Authorization into the programs. However, due to myself wanting to keep more information open, I have only added required authentication on things that could change what the sensors doing at the time. AKA you can get all sensor readings without logging in and even most configurations, but you can’t change any configurations or see the WiFi settings without logging in.
The Control Center program also now supports the Authentication and uses it by default in any commands sent. The user and password can be changed in both programs.
To make the program communication actually secure, I would have to enable HTTPS as well, because the password is sent in clear text over HTTP … but that’s where a problem occurs because if the DateTime is wrong on the sensor (by default they don’t keep track of time when powered off), the HTTPS won’t work… I’ll probably add it later anyway, but I’ll have to see if I can at least get the Control Center to ignore invalid certificate’s so one can at least sync the time correctly… I’ll have to think a bit more about that… Maybe I can just do 3rd party encryption on the password before sending it … yeah, I’ll have to think about that one more.

In other news, I had to make a few changes with the new Plotly 4.0 out as well as a new matplotlib module. The Plotly one was fairly easy but the matplotlib seems to freeze up my program now when doing plots (plot works fine, but can’t do anything else while it plots). I’ll have to do a bit more research and play around with it to get that proper again since it was nice being able to check other aspects and sensors during a live graph.

Since I do a lot of sensor reports, I re-worked the main screen to have a drop-down selector for the reports and database download. I don’t like the layout but I do like the convenience. I also changed the sensor commands to drop-down menu’s as well to help with the cluttered button arrangement. I’m still not sure I super like the overall look and feel … so I guess I’ll have to add GUI design to my research “ToDo” list.

I suppose my next bit of poking will be to bring some of the control center features into the web app itself, so more can be done without the control center. A few cool things to add would be a web-based SSH terminal to the local unit, the ability to edit the local configuration files and creating an offline Plotly graph right from the sensor.

Until next time!

Enhancements and fixes!

So, I have actually done a fair bit since my last post. I won’t list it all today, but I’ll mention a few recent highlights.

For starters, apparently, my Windows Control Center python virtual environment wasn’t actually working on other computers! Among other things, the Python3 virtual environments get tied into the username of where it was created. So when I went to test it on my other computer, it worked (Same username)! but when I tried to put it on someone else’s computer, it did not… So after a fair amount of searching, I found something better then what I was doing (on a few levels), called pynsist. Before I basically created a virtual environment and used Inno Setup to put it all together into an installer. All needing a windows machine to do it on. Pynsist, on the other hand, is all done in Linux creating an installer with an embedded Python3 and required files! Very nice for consistency, especially when you provide the pip packages.

It took a bit to get it working, especially around pip (PyPi) packages, since it doesn’t install the pip requirements of the package you install. AKA Plotly and matplotlib were missing a lot of required 3rd party modules! Long story short, it was easier to install Python on windows, use pip to get the packages, then copy them into an include packages folder for pynsist. Worked very well after that.

Because the previous installer is not working, I uploaded a not fully finished version for the Windows control center program, but it SHOULD only be minor visual glitches, such as window sizes and a not so great looking “Sensor Display” section to have the sensors show things like sensor readings, assuming it has a supported display installed.

Anywho, I’m going on a trip tomorrow for a few days, so I don’t want to stay up too late, but a few of the enhancements include the following.

  • Display functions added for mini LCD / LED displays attached to the sensor.
  • New sensor support (I Think I added 7 or 8 new sensors).
  • Re-worked services so everything runs from a single program. The first program launches threads of other required programs like trigger variance checks and the HTTP server for remote access.
  • Added button in CC for Upgrading to the latest Development version.
  • Added new sensor types: Altitude, Distance, GAS, PM, Ultra Violet.
  • Added more Sensor Commands in CC: Check/install missing dependencies, Clear Logs on Sensor.
  • Refactored file names for clarity.

All in all, I’m pretty happy I have made more progress. Programing is also starting to make more sense and I’m finding it easier to figure out how to do things. Whether it’s the best way to do things or not is another story. There are definitely some structural improvements that could be made now.

Until next time!

Mild progress

After going for a bit of a hike and camp trip with my brother, I got a slight bit more motivation to poke at the sensor programs. This time I improved the installers and uninstallers. I’m pretty sure the Control Center HTTP installer now works with other Linux distributions decently. Works on my Pi’s and Ubuntu 18.04 just fine, as well as the uninstallers.

The Sensors program now offers to install the Control Center at the start, and makes installing a lot faster if you choose not to include it. If you do have the Control Center installed as well, uninstalling the sensors program will ask if you also want to remove the Control Center program.

I’m pretty happy with the HTTP installers now and will most likely convert the SMB installers to use a zip file like HTTP, instead of rsync’ing the folders and files. Although it will take an extra step when pushing a test, it will be a lot cleaner and quicker. I’ll probably create a script to auto zip the files into the right areas, taking only as long as it takes to type in the bash alias in a terminal.

I also want to look into making a .deb installer so it can integrate with the primary package manager and creates a normal spot for removal.

That’s it for now.

Bit of a break

So I fell off the productive train. Looks like I’ll probably take a bit of a break from programming but I’m hoping to take a bit of a “learning” trip. Go somewhere to concentrate on a good stint of learning. I still think the 100 days of python web programming is the way to go as it will definitely take my programming to the next level.

The weather is getting hot already and it is not even summer yet. was about 30c in the shade yesterday, so I’m somewhat dreading what the summer heat will be like. I’m going to have to figure out how to convince myself to get up at 5 AM for my morning walk or bike ride in order to beat the heat.

Although I have done very little programming, I have added a few extra neat things. For one, a port number can be added to the IP or DNS name of the sensor in the control center program. If you leave it blank, it defaults to the primary port, but if add a “:12345” or whatever number at the end, it will use that as the port. This is handy for getting through custom port forwarding on the router. I can now put in server.dragonwarz.net:6970 to access my one sensor that’s on the web.

I’ll probably clean up the latest release a bit but won’t add anything major until I either A) go through the python web course, or B) get inspiration.

That’s it for today. Until next time.

Web Code Day

#100DaysOfCode on Day 4 / 5.

I missed my post on Day 4, so here’s a double. I have now watched the HTML videos and was surprised at how simple HTML was and still kinda is. I guess I was under the impression it would be a big section kinda like Python itself. It’s nice to know the web design part won’t be super hard, although I still have not seen the extent of what CSS is and can do, so I’ll see when that comes up.

I do like how the course is layed out. Not only can you pretty much jump around to the subject you want but it gives it to you in practical ways so you really understand them! I’m going to do it from start to finish, but I’m happy its flexible enough it will be easy to jump back and get a refresher. WELL worth the cost!