surfrock66 / torque

A set of tools used with the Torque app for Android to store OBD2 data in MySQL, view GPS data from Torque on a map in real time using the Google Maps JavaScript API, plot OBD2 data in time series charts, and export the data to CSV or JSON.
Other
43 stars 24 forks source link

No sessions being displayed #10

Closed owenashurst closed 7 years ago

owenashurst commented 8 years ago

The data is there and I could see all my sessions previously. Checked just now and it's not displaying any sessions even though the data exists in the database.

Current php warnings; [Sat Oct 01 19:19:39.098668 2016] [:error] [pid 27773] [client 192.168.0.103:55266] PHP Warning: max(): When only one parameter is given, it must be an array in /var/www/TorqueLog/session.php on line 15, referer: http://192.168.0.138:81/TorqueLog/session.php [Sat Oct 01 19:19:39.098848 2016] [:error] [pid 27773] [client 192.168.0.103:55266] PHP Notice: Undefined variable: session_id in /var/www/TorqueLog/session.php on line 321, referer: http://192.168.0.138:81/TorqueLog/session.php [Sat Oct 01 19:19:39.099957 2016] [:error] [pid 27773] [client 192.168.0.103:55266] PHP Notice: Undefined variable: session_id in /var/www/TorqueLog/session.php on line 535, referer: http://192.168.0.138:81/TorqueLog/session.php

Running on Raspberry Pi 3 with Apache2 & PHP 5.6.24-0+deb8u1 (cli)

surfrock66 commented 8 years ago

Do you have anything in your mysql logs? That error indicates it couldn't fetch any sessions; since the data is there I'm wondering if something isn't wonky with the retrieval of sessions in the get_sessions.php file. I haven't changed anything in forever, but it's possible if malformed data got in there it could mess up the query, or it could be an input-santiization bug.

owenashurst commented 8 years ago

Hmm, I see one log from yesterday when I drove home, but none of my other logs.

Here's all I see in the SQL logs;

2008 Init DB TorqueLog 2008 Query SELECT timestart, timeend, session, profileName, sessionsize FROM sessions WHERE ( YEAR(FROM_UNIXTIME(session/1000)) LIKE '2016' AND MONTHNAME(FROM_UNIXTIME(session/1000)) LIKE 'October' ) GROUP BY session, profileName, timestart, timeend, sessionsize ORDER BY session DESC 2008 Query SELECT id,description,type FROM torque_keys WHERE populated = 1 ORDER BY description 2008 Query SELECT kff1006, kff1005 FROM raw_logs WHERE session=1475427371343 ORDER BY time DESC 2008 Query SELECT YEAR(FROM_UNIXTIME(session/1000)) as 'year' FROM sessions WHERE session <> '' GROUP BY YEAR(FROM_UNIXTIME(session/1000)) ORDER BY YEAR(FROM_UNIXTIME(session/1000)) 2008 Query SELECT distinct profileName FROM sessions ORDER BY profileName asc 2008 Quit

If I execute the first query (highlighted in bold), I get two sessions. One with session size 74 and the other as 4.

If I execute the second query, I get a result of the torque_keys Id, description and type.

If I execute the third query, I get a result of two torque_keys - kff1005 & kff1006 with data.

If I execute the fourth query, I just get the current year.. 2016

And the fifth query just shows me the profile name I saved in Torque for my car.

Looking in the sessions table in MySQL, I can see there are 8 sessions in total. These are my lost sessions that aren't being displayed on the web interface.

EDIT: It turns out I can see all my sessions again. What the hell?

surfrock66 commented 8 years ago

UGGGHHHHH I forgot about this and thought I solved it, and it's been so long since looking at the code I forgot. At the first of the month the default filter applies to an empty set (it says "check October of this year for sessions") and that stops subsequent queries...you added an October session, now the script continues. I thought I patched that by doing a "pull the last 2 months" code...I'll review.

owenashurst commented 8 years ago

Heheh, glad you remembered! Will you let me know when I can update from the repo with the fixes?

surfrock66 commented 8 years ago

Which version are you using? I was looking back through my commits, see this issue:

https://github.com/surfrock66/torque/issues/1

Then this commit to solve it:

https://github.com/surfrock66/torque/commit/66bcd4dcf784e80f88f76ae7c356d6ae8aeac836

I'm reviewing the code, and it looks fixed. Make sure you're up to date?

marvinwankersteen commented 7 years ago

I have a similar problem. Since January 01 2017 no session are being displayed. I got no error or something else. I also cant select the year 2016. If I look in the database, there are the entries from 2016. I use the code from the last commit 9e61be8.

I found a PHP Warning in apache-log: [Mon Jan 02 10:42:11.818293 2017] [:error] [pid 27251] [client x.x.x.x:60978] PHP Warning: max(): When only one parameter is given, it must be an array in /var/www/torque/session.php on line 15, referer: https://torque/

Update: If I open the site with ?year=2016&month=December then I get the tracks. In 2017 so far nothing is logged with torque. I will see it later when I drive at home.

surfrock66 commented 7 years ago

I need to take another look at the condition where it deals with finding an empty set. If I can get some code time tonight while I'm looking at https://github.com/surfrock66/torque/issues/12 I'll see if I can handle it better. I still think the core issue is the rolling over of the default set when a new month comes around...I may have solved the "new month" condition, but not the "new year" condition.

adel-s commented 7 years ago

The same error with current commit - no sessions. In mysql log I see only two requests:

2017-01-08T17:35:15.829271Z 240 Query SELECT timestart, timeend, session, profileName, sessionsize FROM sessions WHERE ( YEAR(FROM_UNIXTIME(session/1000)) LIKE '2017' AND MONTHNAME(FROM_UNIXTIME(session/1000)) LIKE 'January' ) GROUP BY session, profileName, timestart, timeend, sessionsize ORDER BY session DESC

2017-01-08T17:35:15.832585Z 240 Query SELECT id,description,type FROM torque_keys WHERE populated = 1 ORDER BY description

When I repeat first query in MYSQL I get 8 sessions. Second query returns torque keys.

And in webserver logs I see the same error as mentioned above: PHP message: PHP Warning: max(): When only one parameter is given, it must be an array

marvinwankersteen commented 7 years ago

It is working now. My problem was, that there were no logs sent to the server. The bluetooth-adapter had no connection to the ECU. Replugged in and all fine.

Now, I have the first logs in 2017 and the sessions, also from 2016, are displayed.

Sorry for my english.

surfrock66 commented 7 years ago

@marvinwankersteen glad to hear it!

@adel-s Do me a favor, in the mysql console, run the following (correct your DB name of course) use torque; SELECT session, YEAR(FROM_UNIXTIME(session/1000)) as year, MONTHNAME(FROM_UNIXTIME(session/1000)) as month from raw_logs ORDER BY session DESC LIMIT 20; SELECT session, YEAR(FROM_UNIXTIME(session/1000)) as year, MONTHNAME(FROM_UNIXTIME(session/1000)) as month from sessions ORDER BY session DESC LIMIT 20;

Then paste the results please.

adel-s commented 7 years ago

mysql> SELECT session, YEAR(FROM_UNIXTIME(session/1000)) as year, MONTHNAME(FROM_UNIXTIME(session/1000)) as month from raw_logs ORDER BY session DESC LIMIT 20; +---------------+------+---------+ | session | year | month | +---------------+------+---------+ | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887644975 | 2017 | January | | 1483887339369 | 2017 | January | | 1483887339369 | 2017 | January | | 1483887339369 | 2017 | January | | 1483887339369 | 2017 | January | | 1483887339369 | 2017 | January | | 1483887339369 | 2017 | January | | 1483887339369 | 2017 | January | +---------------+------+---------+ 20 rows in set (0,00 sec)

mysql> SELECT session, YEAR(FROM_UNIXTIME(session/1000)) as year, MONTHNAME(FROM_UNIXTIME(session/1000)) as month from sessions ORDER BY session DESC LIMIT 20; +---------------+------+---------+ | session | year | month | +---------------+------+---------+ | 1483887644975 | 2017 | January | | 1483887339369 | 2017 | January | | 1483887074449 | 2017 | January | | 1483887020227 | 2017 | January | | 1483886904548 | 2017 | January | | 1483886821858 | 2017 | January | | 1483886719574 | 2017 | January | | 1483886622060 | 2017 | January | +---------------+------+---------+ 8 rows in set (0,00 sec)

But after some debug today I found why this happened - all my sessions has $row["sessionsize"] less than 20. That's why I see no sessions.

Sorry my bad.

surfrock66 commented 7 years ago

Oh, ok cool, glad it's working!