Shop OBEX P1 Docs P2 Docs Learn Events
How to log data from web device into a server — Parallax Forums

How to log data from web device into a server

Timothy D. SwieterTimothy D. Swieter Posts: 1,613
edited 2009-04-30 01:24 in General Discussion
The subject is kind of a generic question. Let me add some more details here.

I am creating a concept for a home based sensor system. The first sensor I am considering is a current sensor to measure my home electricity usage. The electronics would be made of a current sensor, Propeller and a WIZnet ethernet module.

I hope to have a home "server" or at least my laptop available to log data. The "server" may in fact be a Network Attached Storage (NAS) device that can run PHP/MySQL. I was thinking the AC current logger would send out a message via the ethernet every so often to a web page and then the data is logged into a MySQL table. Is this is a good idea? Is there a better method?

For the method described, is the best way to pass data to a web page to use the URL info such that you include the variables? Something along the lines of "test.htm?Variable1=1234@variable2=5678" is what I am thinking.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com

Comments

  • InSilicoInSilico Posts: 52
    edited 2009-04-18 07:12
    All of this is possible, and there's always more than one way to do it. The setup you propose is quite involved, though.

    You need to setup an HTTP server program on the server computer. Look up Apache. Then you can plug-in PHP into Apache (there is a specific procedure for that). Then, MySQL would be running alongside Apache.

    You write the PHP script(s) to handle the data. Setup the Apache server in such a way that when you retrieve a PHP page from the computer, Apache runs the PHP interpreter, and runs the script. The script will automagically generate an HTML page and send that to the client.

    So you may have a PHP file named "retrieve.php", and you would access it by typing "<server computer>/retrieve.php" in your browser and it would return an HTML page with a nicely formatted table or even a graph, of your house's current consumption over time, based on the data in the MySQL tables. You can probably even have "<server computer/retrieve.php?date=20090418" so you can retrieve data from a specific date.

    You may have another PHP file named "logdata.php" but is requested only by the Propeller. The Propeller would construct a URL like "<server computer>/logdata.php?amperes=230&timestamp=041820091210" and send that to the server. The PHP script will be able to extract the info and insert into the MySQL table via an SQL query.

    It's the most practical Rube Goldberg machine yet! smilewinkgrin.gif· Seriously though, it does require quite a bit of effort, but entirely possible.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-18 07:37
    Thanks InSilico for confirming some of the concept I am considering. The NAS that I am looking at is a Synology '09 series like the DS209+ or DS409+. www.synology.com/enu/products/DS409+/index.php I believe it has the web server, PHP and MySQL stuff already setup (or easy to configure). Over the past year or so I have read off and on about MySQL and PHP so I could probably stumble through that portion. I love projects like this where I can learn while I go along.

    Are there other ways you would propose to log the data for later retrieval and analysis? Perhaps the current monitoring device would have a SD card that logs the data to that device and only dumps it out over Ethernet(or USB) when a PC application requests it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-18 07:39
    A little more digging and it looks like the Synology product uses Apache as well......www.synology.com/enu/products/features/webstation.php I am getting a NAS for storage reason, it would be nice to use it for a project like this too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • InSilicoInSilico Posts: 52
    edited 2009-04-18 10:08
    Ahh a fancy gadget is an option! Makes it much easier (working with the Apache config file is not exactly the most user friendly thing in the world).

    Your SD card idea is sound. It's a very good idea for the sensor node to be able to store the data locally, especially in the case the server computer goes out for some reason. Also, it relieves the burden of the server computer.

    I've seen people host a (tiny) HTTP server on the microcontroller and you access the data by directly requesting from that microcontroller. I'm pretty sure the Propeller is more than capable of doing that. Although you can get away with just a TCP/IP stack.

    I would either use an SD card or a high-capacity EEPROM attached to the Propeller, and a real time clock. The Propeller would take samples at specific time intervals, or if a significant event occurs (for example, the central air conditioner turns on and current spikes up), and record the ampere reading from the sensor and a timestamp to the mass storage device. The Propeller would also support network sockets (http://en.wikipedia.org/wiki/Internet_socket). The Propeller·creates a socket and listens for incoming connections.

    Your PHP server would have a script like "retrieve.php" which contains code that creates a socket and connects to the Propeller. Then data transfer can occur, with the propeller do a dump on the mass storage device.·Then, that PHP script can do whatever it wants with the data, maybe store it in the MySQL database for archival purposes, etc.

    So, in this setup, the Propeller becomes a server and your Synology station is the middleman talking to it via sockets. Note that MySQL works sort of the same way - the PHP script accesses the MySQL database via a socket (although PHP includes libraries that make MySQL access easy).
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-04-20 16:28
    Timothy,

    My home-brew home-security system has a web interface and tells me the status of the system as well as various other information like backup battery level, temperature, etc. I may even expand it later to monitor other gas levels. Currently this information is hosted on a PINK module, which I find perfect for this task. Not only do I have over 100 variables I can watch and set, but I can get e-mail updates (which I get on my cell phone as text messages) and I can also send/receive command information via UDP. I haven’t posted the project yet as I am in the process of redesigning it for the Propeller, but I thought I would mention what I was using for my purposes. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2009-04-20 17:41
    @Timothy D. Swieter

    I've been learning to use Delphi For PHP to hopefully interface a Propeller chip to a web server eventually.

    Delphi For PHP web site:
    www.codegear.com/products/delphi/php

    Currently I have it working with Apache(automatically setup when installing Delphi For PHP) and mysql .

    Learning how to do the PHP scripts will be next. freaked.gif I have no idea about PHP therefore , it will take a while yet. smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Aka: CosmicBob
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-21 12:54
    Thank you guys for the thoughts and the details on your approaches. I will certainly check out Delphi for PHP and see what that is about. Chris you sound like you have a great system going too. I bet there will be a lot of interested folks that want to learn more about that system.

    The last couple days have been busy. Next week I have a flight to the USA from HK so I plan to do more thinking and reading then and we will see what I come up with. Ultimately though I think it will be the actual experimenting and testing that will prove what works best. So it won't be until June that I can do that once I am moved and settled. In the mean time lots of research. Keep the inspiration coming.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • KPRKPR Posts: 189
    edited 2009-04-21 14:07
    You could even have the the prop host the webserver.. look at what has been don for the xbox2 (Darco) and stuff that Harrison Pham have done.. All without any external servers..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New ICON coming, gotta wait for the INK to heal, now we have colour!
  • icepuckicepuck Posts: 466
    edited 2009-04-22 00:42
    Since there are c compilers for the prop now why not port one of the linux web servers(Apache or BOA) or one of the embedded linux servers out there.
    Better yet why port http://www.uclinux.org/ to the prop?
    -dan
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-23 04:08
    OK, lets bring this topic back around. I have various pieces of hardware to chose from. I also have various pieces of software to chose from. There are several good ideas here. I am still researching and reading, but the end goal is to have a network of sensors logging data for immediate access and graphing.

    The project will start with an AC current sensor. i don't think each device will be a web server per se. But there may be a master device that receives and logs data to memory or SD. Then that device can serve data or upload the data to a database/web site app.

    If the web server is on my home network, I can make it a fixed IP address. However if I want to send data from the ethernet enable sensor to an external web site, what hiccups are there? I know there are some like the fact that my home may be on a dynamic IP and maybe even the web server itself. Would having a fix IP on the web server help when the web server is on the 'net?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Computer Geek 101Computer Geek 101 Posts: 179
    edited 2009-04-23 15:44
    I use an xport serial to ethernet module to send UDP data and a .net based service to write to a SQL server. ASP.NET can display the SQL data on a website. As long as the ports are open/forwarded properly, you can send to a SQL server anywhere in the world. In 3 months or so of constant usage, we havent had any data loss problems. If you want any samples, just let me know.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-24 00:35
    Cool Computer Geek! This sounds like another avenue as well. I was going to click over to the Digi site and look at the xports again since it has been a while.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Harrison.Harrison. Posts: 484
    edited 2009-04-24 06:48
    I use a system similar to the one you described for remote data acquisition. The sensor device performs a HTTP GET request to pass parameters to a PHP script running on a remote webserver. This setup is nice since it only requires a static IP on the webserver. You could skip the static IP part if your ethernet interface supports DNS (my tcp/ip stack doesn't, so I use a static IP on the server).

    My setup looks like this:
    Sensor --> Propeller + ENC28J60 --> Internet --> Apache Webserver
    



    The actual HTTP request looks like:
    http://myserver.tld/update.php?sensorid=1&auth=abcdef&value=72.38751
    



    I highly recommend rrdtool (oss.oetiker.ch/rrdtool/) for logging and graphing the data. rrdtool uses a fixed size binary file for logging your readings and can perform various analysis functions. My PHP scripts directly call `rrdtool update` to log readings.

    Right now I have an example up at hdpham.com/sensors/apart-indoor.htm. It's a simple setup that uses a Propeller to submit temperature readings every minute to a remote webserver.

    Post Edited (Harrison.) : 4/24/2009 6:53:55 AM GMT
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-24 07:14
    Harrison - YES!! I love hearing about setups like this. It is similar to what I was imagining. I love forums, I get to learn about all sorts of possibilities and to see what others are doing.

    OK - I like the example page you have posted. If I leave the web page up for a while does it automatically update or reload? AJAX enabled graphs? The graph appears to be an image. Just wondering, it is not a requirement yet in my idea, but I like the cool factor of seeing the data stream in right in front of your eyes.

    I looked briefly at rrdtools. At first glance it looks a like I need to some reading and get in on a learning curve in order to use it.

    This project will be a fun learning project. I was thinking more of using a Google time line chart item like this: code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html since I think this graph is very functional. But then again, for getting started maybe that is going too far into the deep end of the pool.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Computer Geek 101Computer Geek 101 Posts: 179
    edited 2009-04-29 14:56
    Sorry it took so long to reply (Ive been very bysy at work).· This is the RFID door lock system we have at work.· The DLL is written in VB.NET.· I only sent the UDP dll and dummy test program so I didnt have to worry about account data to our servers.· The actual program runs as a windows service and logs the data to the SQL server so we know who enters the building and when.· Let me know if you need more information.·

    Post Edited (Computer Geek 101) : 4/29/2009 5:30:10 PM GMT
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-30 01:24
    Thank you - your attachment will provide some good inspiration.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
Sign In or Register to comment.