ThermoMan / Thermostat-Tracking

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

Getting error to open thermo.php and install.php #40

Closed tingweil closed 6 years ago

tingweil commented 10 years ago

Hi, i'm very new... I can't install on my localhost, can some help me.. thanks in advance.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'user'@'localhost' (using password: YES)' in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\common.php:121 Stack trace: #0 C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\common.php(121): PDO->__construct('mysql:host=loca...', 'user', 'password')

1 C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\thermo.php(2): require_once('C:\Program File...')

2 {main} thrown in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\common.php on line 121

EDIT: Removed the hash marks in front of numbers because that forces a link to an "issue number" --ThermoMan

ThermoMan commented 10 years ago

Do you have phpmyadmin or some other admin tool for your database?

It seems like the user name does not have permission to the database. See if you can manually log in using the username and password you've specified in your config.php file.

That is the line of code that makes the connection, so sometimes the specification of where the database is can be tricky. Although "localhost" is about as basic it can be. But if you can log in with the username and password, then the "naming" of your database connection is the tricky part.

tingweil commented 10 years ago

I used XAMPP AND EASYPHP platform with 2 different computer to make sure it wasn't the computer's problem. But still get same error message, I think I'm missing some steps. here is another error message when I access INSTALL FOLDER:

This script will install 3M-50 Thermostat Tracking software version v2.1.1 You are on 10 of 10 The directory ../images is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 32

The directory ../install is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 32

The directory ../backup is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 32

The directory ../scripts is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 32

The directory ../lib is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 32

The directory ../logs is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 32

The directory ../resources is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 32

The file ../README is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 40

Notice: Undefined variable: db_name in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 101

Notice: Undefined variable: db_object_prefix in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 103

The file ../install/create_tables.sql is missing, please check your download for completeness. Notice: Undefined variable: fatal_error in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 40

Fatal error: Call to undefined function run_sql() in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\projects\thermo2\install\index.php on line 118

ThermoMan commented 10 years ago

Yeah, the installer is not that good. It's more of an outline really. Have to pretty much do all that by hand.

tingweil commented 10 years ago

thanks that save me some time to figure it out, now i can get in to the interface.

can you explain how to set the timezone in step 4 and execute script in step 7?

ThermoMan commented 10 years ago

For timezone there are sometimes two halves to the task.

On the client side there is this... There is a list of official names. http://www.php.net/manual/en/timezones.america.php Find the line in the config.php that says $timezone = 'America/Los_Angeles'; And replace the thing in the single quotes with the appropriate one from the list.

The server side piece may include telling MySQL about timezones. And with xampp that may be all you need, they do a very good job of setting things up and when I was using xampp I didn't have to do this step.
Here is the MySQL help page about that: http://dev.mysql.com/doc/refman/4.1/en/mysql-tzinfo-to-sql.html I've not had to do this step myself. I did have a problem one time - my hosting service did some upgrade and they omitted the TZ setup and I got them to fix it by sending them an email. Which means I don't know what they did, but it abruptly magically worked.

Looking ahead at the next steps, for the outside temperature, you'll need an "api key" from these guys http://www.wunderground.com/weather/api/d/pricing.html I use the free "Developer" one... I forget if it was an email or a web page with the magic number on it, but copy that down and put it in the config.php too.

ThermoMan commented 10 years ago

Is it up yet?
Your description of your experience with manual installation will help me make automatic installation better.

tingweil commented 10 years ago

I temporary set up in a website space, I dont know yet how to attach my zoned 3x ct-80 thermostats to the database

for the timezone setting in config.php, i put SYSTEM to make it work.

currently the interface is ok, but nothing else work. Honestly I'm stuck here.. dont know what to do next.

ThermoMan commented 10 years ago

OK, to connect to the thermostat you need web access from your web server to the thermostat. You can manually check that it is working with an URL something like this. http://192.168.0.193/tstat

This should give you a result that looks something like this. {"temp":67.50,"tmode":1,"fmode":0,"override":0,"hold":1,"t_heat":66.00,"tstate":0,"fstate":0,"time":{"day":3,"hour":14,"minute":55},"t_type_post":0}

The IP address I use there is the DHCP assigned address to my thermostat by my router (I have told it to always give the same address to that device just to stop it getting random).

If you get that result, then your access is up and working and if your web server is inside your network, then all is good.

If your web server is outside your LAN, then you need to be able to see your thermostat from the Internet and that means two things.

  1. Determine your public IP address
  2. Configure your router to permit access.

For item number 1 (don't say # 1 because gut will use that as a link to issue 1) go to this website from INSIDE your network http://whatismyipaddress.com/

For item number 2 the configuration will depend upon your brand of router. But on mine it is called "port forwarding". Pick some large random numbered port and create a relationship between external_ip:big_port_num and internal_ip:80 (because the thermostat uses port 80 for it's web services)

Then you can test your access like this http://external_ip:big_port_num/tstat

You might have to try that on a cell phone because some routers get weird if you try to talk to an interior device from inside the network, using the exterior address of it.

Once you can get that response from your thermostat in a web browser, use that info in phpMyAdmin to put a record into thermo2__thermostats table. In the column named "ip" put your external_ip:big_port_num and I think that is all you need to do. When the code first queries your thermostat it will get the firmware data and the uuid and such.

You're using xampp so I'm assuming you're on Windows? You'll need to set up two task scheduler tasks to run in the background to collect this information. But in the mean time you can run them manually to test. Get a DOS command line and run thermo_update_status.bat and thermo_update_temps.bat from the scripts directory. Look in the log directory for messages that don't just display in the DOS window.

In the install directory is a file named create_schedule.bat and at least on my old Windows box those command worked. You need to edit the batch file for 3 pieces of information. number 1 is the file PATH to your scripts. Number 2 is the Windows user ID that you want to own the task of updating the thermostat. And number 3 is the appropriate password for that ID. (I did a bad bad thing when I was running this at home and used my Administrator ID. Really should have set up an alternate low privilege ID for that. I moved off to a unix server before I had any problems from it though)

ThermoMan commented 10 years ago

I see your three entries named "upstairs". Starting with just one will make debugging the install problems easier.

tingweil commented 10 years ago

thank you Thermo, I'm in office right now, I will try when I get home, I didnt customize the thermostat info yet, I leave everything by default as possible to test the interface. I will try to use my Router (ASUS RT66U) to do the port forward tonight. I can't wait to make this work. I'm assume when the thermostat is set correctly, the chart will start to work? what is the use for registe an user? I try to registe but it does nothing.

ThermoMan commented 10 years ago

Oh hey, same brand of router here. That will make instructions easier the share.

On my hosting service I have a sub-domain that points to a server inside my LAN. I use that name instead of my actual IP address. That saves me from continuously having to update the connection info in the database.

tingweil commented 10 years ago

do you have a separate pc to setup your server? how do you set up a sub domain? (no-ip?) Do you think is a good idea to set a server with a USB attach to RT66U (planing to flash the firmware with RMerlin), or any better suggestion .

ThermoMan commented 10 years ago

You will need a computer that is always on in order to collect data, the thermostat has no facility to store history to reference later.

I have home media server http://www.newegg.com/Product/Product.aspx?Item=N82E16859105563 - this product is now discontinued, but is in a category that has many alternatives) that I used when I was using xampp, but now I use a remote hosting service (http://www.dreamhost.com/ again with many alternatives. These guys are inexpensive and that is my primary requirement, my secondary requirement is that they are on unix and not Windows - because I'm not very admin savvy on Windows, but I am on unix).

Setting up a subdomain is both easy and complicated at the same time (and is not a requirement for the thermostat software). My hosting domain lets me have a website available always without running a server at home. http://www.theinscrutable.us/i_made_this/ So "www" is technically a subdomain of theinscrutable.us although it's the main domain by convention. I have a "home.theinscrutable.us" (subdomain = "home") set up that using the config tool provided by the hosting company to create/maintain an "A" record ( http://en.wikipedia.org/wiki/List_of_DNS_record_types ) that points to my home network. When I said both easy and complicated I meant that the config tool provided by my host makes the task easy. The complicated part was figuring out I needed it.

It is in that same menu area though that you'll set up the "Virtual Server / Port Forwarding"

Use something like http://dnsdynamic.org/ and you're pretty golden too - again they make it easy. There are a whole series of providers that will help here (look up "dynamic dns servers")

I totally forgot. With your ASUS router there are some built in choices for this.. Open up your router config web page. Click on WAN under Advanced Settings. Look at the tab called DDNS. Mine is disabled because I have an old manual method still going, but it's in there. But this is only for later after you're up and going.

ThermoMan commented 10 years ago

I'll have to look into that RMerlin. I didn't even know it existed until now. Thanks!

ThermoMan commented 10 years ago

If you don't have an always on computer, at least one of the other users here has figured out how to run this on his router! I'll have to dig through the previous issues messages to find who (not had enough coffee to remember that today)

tingweil commented 10 years ago

I'm using my home pc now, still stuck in time zone... If i put 'SYSTEM', the interface is working, but the scrips will have error. If i put 'America/New_York', then the web interface will have a error message: and nothing appear.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1298 Unknown or incorrect time zone: 'America/New_York'' in C:\xampp\htdocs\thermo2\common.php:125 Stack trace: # 0 C:\xampp\htdocs\thermo2\common.php(125): PDO->exec('SET time_zone =...') # 1 C:\xampp\htdocs\thermo2\thermo.php(2): require_once('C:\xampp\htdocs...') # 2 {main} thrown in C:\xampp\htdocs\thermo2\common.php on line 125

ThermoMan commented 10 years ago

Comment out the lines that use the timezone.

In common.php that is the following lines.

date_default_timezone_set( $timezone ); and $pdo->exec( "SET time_zone = '$timezone'" );

Since you're on one system that is local you may not need it. I need it because the web server is in some other city (I have no idea where) and the computer is set to GMT (maybe) but I want it to default to my local timezone.

unlstorm commented 10 years ago

Confused by his last comment. It says he put SYSTEM and the interface is working but the scripts have error. What's the script error with SYSTEM defined for the timezone? SYSTEM definition for timezone should work I would think.

ThermoMan commented 10 years ago

Likewise confused and glad to have another pair of eyes on the issue. I only suggested deleting based on his home network usage - I didn't add the timezone until after I migrated to a hosted server, so this is a regression that might make sense in his case. A right answer though would be better.

Lerrissirrel commented 10 years ago

It's been a while since I first set this up, but this situation sounds vaguely familiar. I'll poke around tonight, after work, and see if I can refresh my memory.

tingweil commented 10 years ago

How to run script to update temperature and status on a webhosting service? I'm using 1and1 hosting.

unlstorm commented 10 years ago

You need access to a cron or task scheduler to schedule those scripts on 30 minute and 1 minute intervals. I believe the project had some examples in one of the files for windows or crown scheduling configuration parameters. On Jan 10, 2014 3:01 PM, "tingweil" notifications@github.com wrote:

How to run script to update temperature and status on a webhosting service? I'm using 1and1 hosting.

— Reply to this email directly or view it on GitHubhttps://github.com/ThermoMan/Thermostat-Tracking/issues/40#issuecomment-32065601 .

ThermoMan commented 10 years ago

http://help.1and1.com/hosting-c37630/windows-c85099/pythoncgis-c85128/create-a-cron-job-a792367.html

Some hosts give you a GUI and others let you edit directly. Mine does both. Through the GUI you cannot create a task that runs EVERY minute though, so you may see something similar and that requires manually editing the crontab. The help link I found says that your host DOES let you edit from the command line.

I use WinSCP and PuTTY for my connecting.

Here are the two lines you need to add. You have to use the literal path and not the ~ because the cron daemon does not expand variables like a shell does.

0,30 * * * * /PATH TO YOUR HOME DIRECTORY/thermo2/scripts/thermo_update_temps.ksh > /dev/null
* * * * * /PATH TO YOUR HOME DIRECTORYthermo2/scripts/thermo_update_status.ksh > /dev/null

The top line will start a process when the minute is 0 or 30 and ANY other condition is met. So it runs every half hour. The second line runs every minute.

Here is a good header block to paste in the top of your crontab for reference (because even long time unix guys forget)

delete the leading ' (single quote character) on every line in the following block which is in there because the stupid markup in here uses a leading # to mean bold face.

'# .---------------- minute (0 - 59)
'# |  .------------- hour (0 - 23)
'# |  |  .---------- day of month (1 - 31)
'# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
'# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
'# |  |  |  |  |
'# *  *  *  *  * command to be executed
'#

The charts don't really work right until there are a couple of data points in the table.

tingweil commented 10 years ago

Thanks all for helps, but I almost gave up for 2days, there are still error when i run manually the 2 update files in scripts.. i think this is the last part... i dont know why it give this error

C:\xampp\php>php c:\xampp\htdocs\thermo2\scripts\thermo_update_temps.php

Notice: Undefined variable: logDir in C:\xampp\htdocs\thermo2\common.php on line 102

Warning: mkdir(): Invalid path in C:\xampp\htdocs\thermo2\lib\KLogger.php on line 175

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\common.php on line 123

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\common.php on line 123

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\common.php on line 123

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\common.php on line 123

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\common.php on line 123

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\common.php on line 134

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\scripts\thermo_update_temps.php on line 14

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\scripts\thermo_update_temps.php on line 17

Notice: Undefined variable: dbConfig in C:\xampp\htdocs\thermo2\scripts\thermo_update_temps.php on line 20

Notice: Undefined variable: weatherConfig in C:\xampp\htdocs\thermo2\scripts\thermo_update_temps.php on line 33

Notice: Undefined variable: ZIP in C:\xampp\htdocs\thermo2\scripts\thermo_update_temps.php on line 34

Notice: Undefined variable: ZIP in C:\xampp\htdocs\thermo2\scripts\thermo_update_temps.php on line 37

ThermoMan commented 10 years ago

$logDir is defined in config.php at the very top and that file is included in common.php, so that error doesn't make sense to me. In fact ALL of the errors look like common.php has failed to include config.php somehow.

Are you physically in the scripts directory when you execute your command?

Instead of using the php directly, try the batch file - although that ought not change anything, but it does use a change directory command before it starts.

ThermoMan commented 10 years ago

Any luck?

tingweil commented 10 years ago

still stuck in those 2 updates scripts.

first: C:\xampp\htdocs\thermo2>C:\xampp\php\php C:\xampp\htdocs\thermo2\scripts\thermo_update_status.php

Fatal error: Call to undefined function error() in C:\xampp\htdocs\thermo2\scripts\thermo_update_status.php on line 69


second: the update_temp.bat seems no error when runing, but the log file has error: (I have 3 thermostats)

2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Outside Weather for xxxxx: Temp 1.0 Humidity 77 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock2 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock5 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock3 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock6 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock1 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock4

dont know what to do now. I ask a friend to try it out, he got the same error too.

unlstorm commented 10 years ago

I had similar problems with the lockfile. You can do a chmod 777 manually on the top lockfile. I added a umask to my config file to fix it through reboots. I can't remember the exact umask value. Will try to remember and publish later tonight when I get home and look at what I did specifically in my config file. You likely need to do the chmod 777 on the current tmp lockfile regardless. On Jan 15, 2014 9:22 AM, "tingweil" notifications@github.com wrote:

still stuck in those 2 updates scripts.

first: C:\xampp\htdocs\thermo2>C:\xampp\php\php C:\xampp\htdocs\thermo2\scripts\thermo_update_status.php

Fatal error: Call to undefined function error() in

C:\xampp\htdocs\thermo2\scripts\thermo_update_status.php on line 69

second: the update_temp.bat seems no error when runing, but the log file has error: (I have 3 thermostats)

2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Outside Weather for xxxxx: Temp 1.0 Humidity 77 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock2 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock5 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock3 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock6 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock1 2014-01-15 16:18:00 - INFO --> WRAPPER: temps: Could not write to lock file /tmp/thermo.lock4

dont know what to do now. I ask a friend to try it out, he got the same error too.

— Reply to this email directly or view it on GitHubhttps://github.com/ThermoMan/Thermostat-Tracking/issues/40#issuecomment-32370580 .

tingweil commented 10 years ago

I use Windows 7 pro, for chmod 777 equivalent in windows I add grant Full Control to "Everyone". for whole folder. still got the lockfile.

ThermoMan commented 10 years ago

OK the /tmp path is expressed as a Unix path. In config.php. find where it is defined and change it to c:\temp (or wherever it is that windows hides the temp file dire directory)

tingweil commented 10 years ago

it's weird, i dont find any "tmp" in any of file.

ThermoMan commented 10 years ago

In config.php

$lockFile = '/tmp/thermo.lock';

Change that to a valid path. check out the value of %TMP% or %TEMP% in Windows and use that same directory.

tingweil commented 10 years ago

i create a tmp folder, and the log file seems to work. with these message: (you can connect to the thermostat directly, its online). and the status.php still has error.

Fatal error: Call to undefined function error() in C:\xampp\htdocs\thermo2\scripts\thermo_update_status.php on line 69

log file: 2014-01-15 13:57:02 - INFO --> WRAPPER: temps: Outside Weather for xxxxx: Temp 1.8 Humidity 76 2014-01-15 13:57:02 - INFO --> WRAPPER: temps: Connecting to 2 http://tingweil.asuscomm.com:2002 Downstairs 2014-01-15 13:57:05 - INFO --> WRAPPER: temps: UUID IT OT 1.8 IH -1 OH 76 2014-01-15 13:57:05 - INFO --> WRAPPER: temps: Thermostat Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tstat_uuid' cannot be null 2014-01-15 13:57:05 - INFO --> WRAPPER: temps: Connecting to 3 http://tingweil.asuscomm.com:2003 LivingRoom 2014-01-15 13:57:08 - INFO --> WRAPPER: temps: UUID IT OT 1.8 IH -1 OH 76 2014-01-15 13:57:08 - INFO --> WRAPPER: temps: Thermostat Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tstat_uuid' cannot be null 2014-01-15 13:57:08 - INFO --> WRAPPER: temps: Connecting to 1 http://tingweil.asuscomm.com:2001 Upstairs 2014-01-15 13:57:11 - INFO --> WRAPPER: temps: UUID IT OT 1.8 IH -1 OH 76 2014-01-15 13:57:11 - INFO --> WRAPPER: temps: Thermostat Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tstat_uuid' cannot be null 2014-01-15 13:57:31 - INFO --> get_instant_status: Connecting to Thermostat ID = (2) uuid = () ip = (http://tingweil.asuscomm.com:2002) name = (Downstairs) 2014-01-15 13:57:32 - INFO --> get_instant_status: Outside Weather for J5R2X8: Temp 1.8 Humidity 76 2014-01-15 13:57:32 - INFO --> get_instant_status: Connecting to Thermostat ID = (3) uuid = () ip = (http://tingweil.asuscomm.com:2003) name = (LivingRoom) 2014-01-15 13:57:33 - INFO --> get_instant_status: Connecting to Thermostat ID = (1) uuid = () ip = (http://tingweil.asuscomm.com:2001) name = (Upstairs)

unlstorm commented 10 years ago

In the tmp folder? Is the file read only? On Jan 15, 2014 10:19 AM, "tingweil" notifications@github.com wrote:

I use Windows 7 pro, for chmod 777 equivalent in windows I add grant Full Control to "Everyone". for whole folder. still got the lockfile.

— Reply to this email directly or view it on GitHubhttps://github.com/ThermoMan/Thermostat-Tracking/issues/40#issuecomment-32376640 .

ThermoMan commented 10 years ago

This looks like the logging issue is resolved and now the uuid is not populating. I checked your sys and if you hard code "88308a278e3d" into it, then it ought to start logging (and we can figure out why it's not picking the uuid up later)

Add a line that says $stat->uuid = '88308a278e3d'; Just before these two lines logIt( "temps: UUID $stat->uuid IT " . $stat->temp . " OT $outdoorTemp IH $stat->humidity OH $outdoorHumidity" ); $queryTemp->execute(array( $stat->uuid, $stat->temp, $outdoorTemp, $stat->humidity, $outdoorHumidity ) );

in the thermo_update_temps.php file

In your log file, do you have any lines that have "status: " in them?

The get_instant_status is a log message from visiting your web page.

You are really close to being done.

tingweil commented 10 years ago

I get line 203 error for update_status.php, and still can't get the thermostat info with the code added ($stat->uuid = '88308a278e3d';).

is the status.php error related to update_temps.php?

here is the log file of today: http://xxxxx/thermo2/logs/log_2014-01-16.txt

I manually put the uuid for each thermostat in mysql database. So it shows in the log file.

ThermoMan commented 10 years ago

I'd guess that the temps error is related to the (semi-solved) status error. They use the same method to determine the uuid of the device. 2014-01-16 11:19:35 - INFO --> WRAPPER: temps: Thermostat Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tstat_uuid' cannot be null

Your devices respond with their uuid correctly, so I'm not sure why it's not being picked up in the connection. http://tingweil.asuscomm.com:2003/sys

Since you have three thermostats, the direct hard code of the uuid won't work. It needs a separate uuid for each one. I hate to spend time on work around code, but this piece (replacing the direct assignment I suggested before) might get us one step further towards working.

switch($thermostatRec['ip']) { case "http://tingweil.asuscomm.com:2001": $stat->uuid = '88308a97f21a'; break; case "http://tingweil.asuscomm.com:2002": $stat->uuid = '88308a278e3d'; break; case "http://tingweil.asuscomm.com:2003": $stat->uuid = '88308a278f6c'; break; }

I do not have multiple thermostats so can't model any of this at home. I have been planning a code change later on to stop using the uuid as a key in the data table and use the thermostat_id instead. But that won't help here.

Here is what my logs look like (the status and temps are interleaved so I have manually untangled them)

2014-01-16 2:00:02 - INFO --> status: Connecting to Thermostat ID = (1) uuid = (5cdad4276ec5) ip = (localhost:31081) name = (Home) 2014-01-16 2:00:09 - INFO --> status: Heat: OFF 2014-01-16 2:00:09 - INFO --> status: Cool: OFF 2014-01-16 2:00:09 - INFO --> status: Fan: OFF 2014-01-16 2:00:09 - INFO --> status: uuid = (5cdad4276ec5) GOT PRIOR STATE H C F SDH SDC SDC 2014-01-16 2:00:09 - INFO --> status: Updating record with 2014-01-16 02:00:00 SDH SDC SDF H C F for UUID 5cdad4276ec5

2014-01-16 2:00:03 - INFO --> WRAPPER: temps: Outside Weather for 90210: Temp 42.0 Humidity 56 2014-01-16 2:00:09 - INFO --> WRAPPER: temps: Connecting to 1 5cdad4276ec5 localhost:31081 Home 2014-01-16 2:00:21 - INFO --> WRAPPER: temps: UUID 5cdad4276ec5 IT 68 OT 42.0 IH -1 OH 56 2014-01-16 2:00:22 - INFO --> WRAPPER: temps: Run Time Today - Inserting RTH 0 RTC 0 U 5cdad4276ec5 T 2014-01-16 2014-01-16 2:00:22 - INFO --> WRAPPER: temps: Run Time Yesterday - Inserting RTH 203 RTC 0 U 5cdad4276ec5 T 2014-01-15

This was the first entry in the log file for today. So I can see I've got a weirdness in date handling (I looked in the previous day log file and the midnight change over is several lines up form the bottom - I think the logging library that I started using does something funky with dates. I'll have to look into that and fix it.

look in t_lib.php at the function that stats on line 606. This is the function that queries the device for the uuid. This is where the problem is probably happening. public function getSysInfo() { $outputs = $this->getStatData( '/sys' ); // '/sys/info' No longer works // {"uuid":"xxxxxxxxxxxx","api_version":113,"fw_version":"1.04.84","wlan_fw_version":"v10.105576"} $obj = json_decode( $outputs ); $this->uuid = $obj->{'uuid'}; $this->api_version = $obj->{'api_version'}; $this->fw_version = $obj->{'fw_version'}; $this->wlan_fw_version = $obj->{'wlan_fw_version'}; return; }

I'm poking around in the code to see if I can find out generically why it might not be getting your sys info.

unlstorm commented 10 years ago

I think he needs to remove the "http://" from his IP definitions. The "http://" is already prefixed by the getStatData function.

On Thu, Jan 16, 2014 at 9:24 PM, ThermoMan notifications@github.com wrote:

I'd guess that the temps error is related to the (semi-solved) status error. They use the same method to determine the uuid of the device. 2014-01-16 11:19:35 - INFO --> WRAPPER: temps: Thermostat Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tstat_uuid' cannot be null

Your devices respond with their uuid correctly, so I'm not sure why it's not being picked up in the connection. http://tingweil.asuscomm.com:2003/sys

Since you have three thermostats, the direct hard code of the uuid won't work. It needs a separate uuid for each one. I hate to spend time on work around code, but this piece (replacing the direct assignment I suggested before) might get us one step further towards working.

switch($thermostatRec['ip']) { case "http://tingweil.asuscomm.com:2001": $stat->uuid = '88308a97f21a'; break; case "http://tingweil.asuscomm.com:2002": $stat->uuid = '88308a278e3d'; break; case "http://tingweil.asuscomm.com:2003": $stat->uuid = '88308a278f6c'; break; }

I do not have multiple thermostats so can't model any of this at home. I have been planning a code change later on to stop using the uuid as a key in the data table and use the thermostat_id instead. But that won't help here.

Here is what my logs look like (the status and temps are interleaved so I have manually untangled them)

2014-01-16 2:00:02 - INFO --> status: Connecting to Thermostat ID = (1) uuid = (5cdad4276ec5) ip = (localhost:31081) name = (Home) 2014-01-16 2:00:09 - INFO --> status: Heat: OFF 2014-01-16 2:00:09 - INFO --> status: Cool: OFF 2014-01-16 2:00:09 - INFO --> status: Fan: OFF 2014-01-16 2:00:09 - INFO --> status: uuid = (5cdad4276ec5) GOT PRIOR STATE H C F SDH SDC SDC 2014-01-16 2:00:09 - INFO --> status: Updating record with 2014-01-16 02:00:00 SDH SDC SDF H C F for UUID 5cdad4276ec5

2014-01-16 2:00:03 - INFO --> WRAPPER: temps: Outside Weather for 75075: Temp 42.0 Humidity 56 2014-01-16 2:00:09 - INFO --> WRAPPER: temps: Connecting to 1 5cdad4276ec5 localhost:31081 Home 2014-01-16 2:00:21 - INFO --> WRAPPER: temps: UUID 5cdad4276ec5 IT 68 OT 42.0 IH -1 OH 56 2014-01-16 2:00:22 - INFO --> WRAPPER: temps: Run Time Today - Inserting RTH 0 RTC 0 U 5cdad4276ec5 T 2014-01-16 2014-01-16 2:00:22 - INFO --> WRAPPER: temps: Run Time Yesterday - Inserting RTH 203 RTC 0 U 5cdad4276ec5 T 2014-01-15

This was the first entry in the log file for today. So I can see I've got a weirdness in date handling (I looked in the previous day log file and the midnight change over is several lines up form the bottom - I think the logging library that I started using does something funky with dates. I'll have to look into that and fix it.

look in t_lib.php at the function that stats on line 606. This is the function that queries the device for the uuid. This is where the problem is probably happening. public function getSysInfo() { $outputs = $this->getStatData( '/sys' ); // '/sys/info' No longer works // {"uuid":"xxxxxxxxxxxx","api_version":113,"fw_version":"1.04.84","wlan_fw_version":"v10.105576"} $obj = json_decode( $outputs );

$this->uuid = $obj->{'uuid'};
$this->api_version = $obj->{'api_version'};
$this->fw_version = $obj->{'fw_version'};
$this->wlan_fw_version = $obj->{'wlan_fw_version'};

return;

}

I'm poking around in the code to see if I can find out generically why it might not be getting your sys info.

— Reply to this email directly or view it on GitHubhttps://github.com/ThermoMan/Thermostat-Tracking/issues/40#issuecomment-32577262 .

tingweil commented 10 years ago

Cool! with http:// removed, the update_temps finally works!! here is the log file: http://xxxxxxxxxx/thermo2/logs/log_2014-01-17.txt

the last thing update_status.php still get error message:

(uiserver):u47339368:~/tingliang-photo/thermo2 > php6 scripts/thermo_update_stat us.php X-Powered-By: PHP/5.4.24 Content-type: text/html


Fatal error: Call to undefined function doError() in /homepages/15/d2 34533587/htdocs/tingliang-photo/thermo2/scripts/thermo_update_status.php on line 203

ThermoMan commented 10 years ago

That doError() is left over from ages past. I tripped over two of them today. What I replaced it with is this. $log->logInfo( 'status: Thermostat Exception ' . $e->getMessage() ); flock( $lock, LOCK_UN ); // Should be in a finally block? die(); // Does die() prevent finally?

Although the die(); might be excessive and I think I'll remove it. Just chuck in that log statement instead of the doError() and you should be OK.

I'll have some small updates checked into github in a day or so (I messed with the logging a bit and also added some retry logic on the thermostat communication)

I've found that I am getting some timeout errors and some cannot find URL errors now that I am logging the curl errors. I'll have to look at the logs over a period of a couple of days and see what errors seem to jump out.

Already though I've found that a communication error in the wrong place results in the addition of a setpoint of zero being added to the database.

Hooray for your success! And thanks for spotting that @unlstorm!

tingweil commented 10 years ago

Thanks Unlstorm and Thermo! both scripts are running without error. Now it seems missing a setpoint table in database. How to create it? I see there is a upgrade_setpoint in the install folder.

here is todays log file. at the end it shows: 2014-01-17 13:46:24 - INFO --> status: Thermostat Exception SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db509804270.thermo2__setpoints' doesn't exist

unlstorm commented 10 years ago

Try running the upgrade_setpoints.php script. I never tested it so your mileage may vary but it should create the table and adjust as needed. What'd you run to get your original tables installed?

On Fri, Jan 17, 2014 at 12:53 PM, tingweil notifications@github.com wrote:

Thanks Unlstorm and Thermo! both scripts are running without error. Now it seems missing a setpoint table in database. How to create it? I see there is a upgrade_setpoint in the install folder.

here is todays log file. at the end it shows: 2014-01-17 13:46:24 - INFO --> status: Thermostat Exception SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db509804270.thermo2__setpoints' doesn't exist

— Reply to this email directly or view it on GitHubhttps://github.com/ThermoMan/Thermostat-Tracking/issues/40#issuecomment-32635661 .

tingweil commented 10 years ago

I use create_table script in install folder, it didnt have the setpoint table. I run the upgrade_setpoints.php give me errors.

what field i need to create setpoint table?

unlstorm commented 10 years ago

Run these commands in your mysql database query area (I assume you have phpMyAdmin installed) and you should get the table created:

ALTER TABLE thermo2__thermostats MODIFY id TINYINT unsigned NOT NULL;

CREATE TABLE IF NOT EXISTS thermo2__setpoints ( id tinyint(3) unsigned NOT NULL, set_point decimal(5,2) DEFAULT NULL, switch_time datetime NOT NULL, KEY id (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE thermo2setpoints ADD CONSTRAINT thermo2setpoints_ibfk_1 FOREIGN KEY (id) REFERENCES thermo2__thermostats (id);

On Fri, Jan 17, 2014 at 8:03 PM, tingweil notifications@github.com wrote:

I use create_table script in install folder, it didnt have the setpoint table. I run the upgrade_setpoints.php give me errors.

what field i need to create setpoint table?

— Reply to this email directly or view it on GitHubhttps://github.com/ThermoMan/Thermostat-Tracking/issues/40#issuecomment-32671772 .

ThermoMan commented 10 years ago

@tingweil are you up and running now?

tingweil commented 10 years ago

The database is collecting data, but the graph table doesn't work..

ThermoMan commented 10 years ago

If you right click on the image alt text "The temperatures" and choose "view image" (in Firefox - other browsers may have a different method) you see the error message

Warning: Include path '../common/php/' not exists in /homepages/15/d234533587/htdocs/tingliang-photo/thermo2/common.php on line 14 Thermostat not found. Fatal error: Class 'pData' not found in /homepages/15/d234533587/htdocs/tingliang-photo/thermo2/draw_daily.php on line 163

That line 14 is in the middle of a function called "add_include_path( $path )" whose purpose is to reference code outside of the current working tree. The error on line 153 in draw_daily.php is where the code references an object from the pChart library (this is the code that lives in a different directory) In the file common_chart.php on line 5 is where that external library is added (using the add_include_path function) so the three includes on lines 12, 13, and 14 are not working. include( 'pChart2.1.3/class/pData.class.php' ); include( 'pChart2.1.3/class/pDraw.class.php' ); include( 'pChart2.1.3/class/pImage.class.php' ); I guess I ought to make these "require_once" instead of include since failure breaks things.

pChart is a 3rd party, free for personal use, library that lives in a different part of the file system. files You can download it from here http://www.pchart.net/download

Oh hey. I see that it is not abandoned! They have an update.
Download that zip and expand it and put it on your web server in a directory like you see in the image above.
Modify the include statements to point to the proper named directory since they updated their version number.

I'll also download the new version and make sure everything still works (and if not I'll get you a copy of the previous one)

tingweil commented 10 years ago

Is Finally working!!! Special thanks to @ThermoMan and @unlstorm at last step, I manually put uuid to each thermostat in database, and voila!

question1: I have one question, can it show real runtime of the heat pump? With the zoning system, 3 of the thermostats can run individually, but they use the same outdoor heat pump unit. So sometime the thermostat runtime will overlap it.

question 2: I see the setpoint are off on the chart, what is the cause?

question 3: Why the weather forecast is not showing?

last question: If I want to download all the current files to replace the files I using now (downloaded 21 days ago), will it cause any problem?

ThermoMan commented 10 years ago

q 4 first. It ought not cause a problem. If you keep a copy of existing files and use the backup.php script to save your database, then any problem should be curable. I'm checking my existing code against what is checked in. There are two new features in the works, but don't affect the database (which is where issues might arise)

q 2. Should be fixed by the latest files. The setpoint is now used when looking for min/max temperature on the chart

q 1. This may be where you will have disappointment. There is no way in the existing code to show that two thermostats share a resource. Might be able to come up with some SQL that will look at the two sets of history and merge them into a single set of data (And then push back into both as they are now identical) but you'd have to run it once a day or so. Maybe if it was connected to the instant_status it could refresh whenever you look in on the charts. Not trivial and has a chance to mess up data.

ThermoMan commented 10 years ago

q 3.... What does it show instead of a forecast?