ThermoMan / Thermostat-Tracking

Code to track and chart data from the 3M-50 WiFi enabled thermostat
8 stars 10 forks source link

DD-WRT #1

Closed unlstorm closed 12 years ago

unlstorm commented 12 years ago

Like what I see in the graphs. Curious if this design would easily port to a DD-WRT router or Synology NAS? Reason being that it appears to continuously monitor and report on frequent intervals. This would lend itself well for lower power devices with HTTP/PHP capabilities.

ThermoMan commented 12 years ago

It might. I've no experience with those. It queries temperature once each 30 minutes and on/off status once each minute. Both take only seconds from start to end. The key is the data storage. You need a database somewhere. I'm using MySQL, but there is no reason it couldn't be sqlite on some NAS. The server side is all PHP with a cron task for the two data lookups.

I have not updated the screenshots recently, I've made some improvements after looking at these charts for a few months I've figured out how to combine some to make them more useful. When I push the next set of code up, I'll update the screenshots. Something I did recently broke the website for Android devices and I really want that to work.

The charting package I'm using has a built in limiter. When it takes more than 30 seconds to render it aborts. So some of the charts that have more than 90 days fail depending on what background tasks the server is chewing on.

On another project I'm using a client side JavaScript charting package (that never worked on Android) but it might unload a low power server.

ThermoMan commented 12 years ago

I went ahead and updated the graphics in the wiki.

I don't even have a DD-WRT router, but if you want to go ahead and tackle the conversion, I can offer some support. For step 1 I might look for a more lightweight charting package. pChart2 is full of bells and whistles and I'm not taking advantage of them, so using a smaller software package is feasible.

unlstorm commented 12 years ago

Thanks for the screenshot updates. I think I'll start by installing the package on my windows machine with WAMP and see if I can get things going smoothly in my LAN. I see you migrated to a hosting service which is what I have tried to avoid. I use dynamic DNS (zoneedit) for my DNS to IP management, Synology NAS (ds211j) for my webserver needs, and Netgear WNDR3700 (reprogrammed with DD-WRT firmware) for my home LAN/WiFi needs.

I unfortunately don't work with web-programming in my career and only dabble with it at home in my spare time. I'll start experimenting based on what you've started and see where this leads.

Have you only used this setup for tracking or are you merging a control system with the tracking system? I seen you mentioned you broke the website for Android devices (which I use as well - BIONIC awaiting ICS). Are you only referring to being able to cleanly render the charts and monitor your thermostat with your phone?

ThermoMan commented 12 years ago

The new rendering works like this. It displays a placekeeper graphic inside an tag and uses JavaScript to change the image source to an URL that includes the parameters. For some reason on Android it doesn't update.

I was using 4.0.4 from CyanogenMOD 9.1 and I just upgraded to CM 10 hoping that Android 4.1 would fix the issue. It has not. Now this is with the default browser (where I was hoping to maintain compatibility) so I'll go install Firefox again and see if it works there.

So far all I am doing is tracking. The official Android app just added programming so I don't have to yet. But I am working on a password system so that settings could be done safely in a web (public) environment.

unlstorm commented 12 years ago

I'm now looking at setting this up on my NAS now. Does the database get created automatically, manually, or through the items in the "install" directory?

Nevermind... Looks like install/index.php handles this...

ThermoMan commented 12 years ago

OK, works in Firefox for Android. Yaay.

Sadly the install.php is one of the things that is not up to snuff. There are SQL statements to build the DB. If you are using xampp then get into phpMyAdmin and ruin the SQLs there. Oh, in the SQL that inserts date stamps, there is a "24:00" that is no longer needed (just 00:00 to 23:30 is enough) so take that one line out of the install SQL (I don't recall if I did that or not)

Reading the install.php file will show you the order in which things ought to be built. Actually having you step through the install process will help me make sure that all the pieces are there. That is the next step towards automating it.

unlstorm commented 12 years ago

I'm not using xampp but I'll step through the install stuff and make notes for what I find. First step says it can't find the directories which is strange... The directories are there. But the draw_r*.php and README files are not.

This script will install 3M-50 Thermostat Tracking software version v2.1 You are on 10 of 10 The directory ../images is missing, please check your download for completeness. The directory ../install is missing, please check your download for completeness. The directory ../scripts is missing, please check your download for completeness. The directory ../lib is missing, please check your download for completeness. The directory ../resources is missing, please check your download for completeness. The file ../draw_range.php is missing, please check your download for completeness. The file ../draw_runtimes.php is missing, please check your download for completeness. The file ../README is missing, please check your download for completeness.

ThermoMan commented 12 years ago

Hang on a few minutes. I've got some small updates that I'm tidying up and pushing to the hub.

A lot of those draw_* files are now unneeded - the functions have been combined into fewer files. And so I see I need to update that installer.php too.

ThermoMan commented 12 years ago

OK, they are committed and pushed. No change to that install.php file for now though.

ThermoMan commented 12 years ago

The "upgrade_partial.php" file is another way to run SQL. Copy the parts you need into there and replace the existing code and then hit it with your browser and it will run things for you.

unlstorm commented 12 years ago

Is this the best method of communication/collaboration method github has to offer? I've not used this before. If you prefer another method such as IM/gtalk/email/etc let me know.

ThermoMan commented 12 years ago

No real idea, I'm not a github expert. But this does create a permanent record that can be referenced later

When you get to this part of the install SQL that wants you to insert a thermostat record, th eonly part that is really important is the IP address of your thermostat. You CAN substitute a domain name and port number if you want - letting your router do port forwarding to the device for you. INSERT INTO thermo2__thermostats (ip,name,model) VALUES ('192.168.1.171','Downstairs','CT30'); That's how I do it - it lets me use my router as a firewall to block stuff other than my app on the host.

ThermoMan commented 12 years ago

If I drop out, it's the local windstorm killing my power...

unlstorm commented 12 years ago

Ok... I have the database created manually. Going to start looking at PHP issues now.

unlstorm commented 12 years ago

Failed database connection: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:3306' (3)' in /volume1/web/thermostat/common.php:28 Stack trace: #0 /volume1/web/thermostat/common.php(28): PDO->__construct('mysql:host=loca...', 'thermo', 'stat') #1 /volume1/web/thermostat/index.php(3): require_once('/volume1/web/th...') #2 {main} thrown in /volume1/web/thermostat/common.php on line 28

Running this on my NAS which is unix based. From what I'm reading I need to tell it how to find the default unix socket. Looks like I can do this in php.ini or directly such as "mysql:unix_socket=/var/run/mysqld/mysqld.sock".

I went ahead and gave the database a default username of "thermo" and password of "stat" to not open up my "default":"user" configuration permissions.

Update: worked around that php issue by removing the :3306 after localhost. Now moving onto the rest of the issues.

unlstorm commented 12 years ago

Ok, my next issue is surrounding time zones. The MySQL installation procedures creates time_zone tables but does not load them. I'm going to look into populating the timezone tables with "mysql_tzinfo_to_sql" or another method.

My Synology NAS don't seem to have that "mysql_tzinfo_to_sql" tool, so I changed $timezone in config.php to "$timezone = 'SYSTEM';" and now I'm rendering the web pages for the tabbed interface.

Will wait a while for the database to get populated with some information from my thermostat...

unlstorm commented 12 years ago

Ok, I've got the database populating with manual running of the temps and status scripts. I'm going to setup a crontab on my NAS server to kick these off in the 30 minute and once a minute windows you described above. One question I have is if I setup the crontabs to run on same boundaries will things be ok on the 30 minute window when both cron jobs wake up to run (i.e. do they simultaneously hit the thermostat and/or database causing possible problems)?

ThermoMan commented 12 years ago

There is a locking mechanism to prevent the two scripts from hitting at the same time. Also there is a 1 second delay built into the library so that repeated calls to the thermostat (in one thread) do not overload the device. I have heard (from phaerus) that if you overload the stat it will be incommunicado for about 20 to 30 minutes. I also subscribe to a program from e5 that monitors my thermostat also on a per minute basis and so far no collisions. AND I have a TED5000 that talks to the thermostat, but probably much less frequently.

unlstorm commented 12 years ago

Interesting.... I've never seen something like that TED5000 before. How do you like it? Was it easy to install on your own? Do you find it makes it easy to narrow down your homes power drawing components?

unlstorm commented 12 years ago

Got everything working now on my synology NAS. I'm going to give my database some time to populate. I may start documenting everything I learned during my setup process on your wiki. I may even try to help code something if I can find some spare time in the future (hard to do with career and kids). I am thrown off by some of the reasons behind multi-thermostat and multi-location support. I can see a case where an owner may have something like rental properties and have one of these for each property. What's driving you to support multiple thermostats in one interface package?

ThermoMan commented 12 years ago

The motivation for multiple location thing is a little weak and is mostly for completeness. Your example of a rent house if pretty much the only one I've come up with so far.

The multiple thermostat one though is much more common. I only have one A/C unit in my house, but pretty much everyone I know with a two story house has two units with one stat for each of them.

The other reason for supporting multiple locations is in case I every try to generate revenue from this - or if I simply let my friends and family use my one web installation. The users of this would not need to ever know how to install software or use SQL. They'd simply type in their zip code and the web page already knows what IP address they have come from. They might have to configure a router, but probably not.

Once I start collecting more data from multiple units, I can provide additional data. For instance the indoor start temperature and ending temperature and the elapsed time tells me how many minutes per degree of change is needed. I can ell each user how their A/C differs from the average. This way if your own performance starts to drop then you may need to service your unit. If the temperature rises quickly after the A/C shuts off, then there might be a need for more insulation.

Your additions to the wiki will be great too. I'm looking at everything from the point of view of being a developer and so things that may seem obvious to me may be obtuse and vice-versa. Thanks for your help!

ThermoMan commented 12 years ago

On the TED5000, yes, it was easy to install. It sort of creeped me out when I saw just how easy it was to watch a power profile. When my garage door opens and closes it has a very distinct pattern - so think about this with a smart meter. Anyone with access to that utility company data can tell when I leave my house. You can watch the heating elements in your oven come on and see how it maintains heat. When your A/C kicks on there is a spike and the compressor is the single biggest hog of the whole thing. Then when the compressor turns off and the fan stays on a bit longer you can see that. And the vampire power that everything uses when you have everything turned "off" is interesting to see too. I use the microwave a lot more now and the main oven a lot less. It does use more power while it's on, but it's only on for 5 minutes tops and the regular oven is only barely up to heat in 5 minutes. I guess I need to put some screen shots up on the other wiki... https://github.com/ThermoMan/TED-5000-Electricity-Tracking/wiki (presently it is empty)

ThermoMan commented 12 years ago

Since your NAS is local to your house I think you're going to be OK with $timezone = 'SYSTEM''; as your solution.

I didn't even discover the timezone issues until I moved the code to a hosted web service. When I did, I ran into the issue that Apache, MySQL, and PHP each had their own idea of what the timezone was. So the PHP code that ran i Apache had one concept of time, and the PHP that ran from cron had a different concept of time.

I'm going to try to store all the data in the timezone of the thermostat (touch it one time and be done with it). If for some reason that fails, I'll store it all in either the server timezone or GMT and then apply an offset to the observer in the reporting part of the tool. But that is the least ideal solution.

I'm making a note of your solution in the config.php file that will get pushed to Git the next time I do a push.

ThermoMan commented 12 years ago

There were several issues identified here

  1. Suggestion for alternative storage locations - added to roadmap
  2. MySQL connection string issues (will note this in config.php) I had the default DSN as 'mysql:host=localhost:3306;dbname=thermo' and it should have been 'mysql:host=localhost:port=3306;dbname=thermo'
  3. Timezone support for some systems doesn't know the names, uses 'SYSTEM' instead (noted in config.php)

This thread can serve as documentation for some of the install issues.

I'll mark this as closed.