Amol Desai
Posts: 4
Joined: Fri Dec 19, 2014 1:17 pm

Retrieve data from mysql table using python

Sat Jan 03, 2015 2:38 pm

Hi,
I have collected data from mysql table using python as follows,
sensor=Analog Sensor 0,Interval=60
sensor=Digital Sensor 2,Interval=120
sensor=Digital Sensor 5,Interval=0
I want to read data from sensor for particular interval. So how do I select the Interval for Analog sensor 0 by using python so that I can take reading from that sensor .
Thanks in advance

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Retrieve data from mysql table using python

Sat Jan 03, 2015 2:55 pm

It is hard to respond if we don't know the structure of your table and how you did implement the table insertion?

is it three different tables ? one for each sensor or it is on the same table with a sensor id field ?

I'm confuse about interval 0. What interval do ?

I put code on how to use mysql with a card reader maybe take a look at the python3 code

[urlhttp://www.raspberrypi.org/forums/viewtopic.ph ... 44#p647644[/url]

Daniel

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Retrieve data from mysql table using python

Sat Jan 03, 2015 3:25 pm

If we assume you have a timestamp column then you can use a BETWEEN predicate with a start time & end time.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Retrieve data from mysql table using python

Sat Jan 03, 2015 3:30 pm

Are you able to extract your data using normal sql console query ?

if yes than it is exactly the same with python! use the same command in a string!

Daniel

Return to “Python”