Monthly Archives: July 2019

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!