Shop OBEX P1 Docs P2 Docs Learn Events
Using Prop to send data to a Web server — Parallax Forums

Using Prop to send data to a Web server

eagletalontimeagletalontim Posts: 1,399
edited 2014-11-24 10:39 in Propeller 1
Hello all again! I am interested in converting my home Power Logger project to send data through the web directly instead of having the computer communicate with the Prop and send the same data to my web server. Being able to see the info of the current power usage on the computer is nice, but I will probably convert it to display on a 2x16 display.

What I need to know is how to have the prop connect to my network and send data to my web server via the query string or POST. Right now, I have a VB program that I wrote which constantly pings the Prop (Via Serial Com) and gets all recent readings. Every hour, the VB program sends the Watt hour usage to my web server which is stored in the DB for later viewing. I need to break the tie between the computer and the Prop so I can adjust the power settings on my computer to save power :)

What can I purchase that will allow me to get the Prop communicating with my web server? Anything premade? I have seen the "Spinneret Web Server" which may be what I am looking for, but I am not entirely sure. Any suggestions?

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-11-22 21:57
    There are hundreds of solutions to the Internet of Things (IoT, Google it) problem now a days.

    One very cheap and flexible solution is to use a Raspberry Pi Model A+ and a cheap, tiny, WIFI dongle. Connect you Propeller to the Pi's on board UART port that comes out on it's GPIO header pins. Write a 20 line program for the Pi, in the language of your choice, to communicate with the Prop and exchange data to your web server. One could use XHR or a web socket connection. My preferred way to do this kind of thing currently is with JavaScritpt running under Node.js.

    The Pi solution has the great advantage that you can run the propeller-loader on it which means you can now program your Propeller form the Pi. Over the air Propeller programming. Go the whole hog and run the open source spin compiler on the Pi. Or even the SimpleIDE or PropellerIDE.

    Of course for simple logger applications you may now find that you don't need the Propeller, the Pi has a bunch of GPIO pins...

    But if there is some real-time control/monitoring work going on then a Prop and a Pi can make a great combination.

    Available form RS and Element14;
    http://uk.rs-online.com/web/p/processor-microcontroller-development-kits/8332699/
    http://www.element14.com/community/community/raspberry-pi/raspberry-pi-aplus?ICID=rpimain-topban-rpiaplus


    Another nice solution involves using a cheap WIFI router and loading it with OpenWRT firmware. With a bit of delicate soldering one make a serial connection from router to Propeller. We have done this with TP-Link's WR703N and MR3020 routers and the D-LINK DIR-613. They also run propeller-loader and openspin. You may already have such a router or the can be had for 20 dollars. Routers like that with OpenWRT are very reliable setups.

    Here is a nice long thread about using such routers with the Prop:
    http://forums.parallax.com/showthread.php/156414-WiFi-amp-IOT-for-home-controllers-monitors-using-WR703N-20-routers-and-xx-WRT
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-11-22 22:12
    Hello all again! I am interested in converting my home Power Logger project to send data through the web directly instead of having the computer communicate with the Prop and send the same data to my web server. Being able to see the info of the current power usage on the computer is nice, but I will probably convert it to display on a 2x16 display.

    What I need to know is how to have the prop connect to my network and send data to my web server via the query string or POST. Right now, I have a VB program that I wrote which constantly pings the Prop (Via Serial Com) and gets all recent readings. Every hour, the VB program sends the Watt hour usage to my web server which is stored in the DB for later viewing. I need to break the tie between the computer and the Prop so I can adjust the power settings on my computer to save power :)

    What can I purchase that will allow me to get the Prop communicating with my web server? Anything premade? I have seen the "Spinneret Web Server" which may be what I am looking for, but I am not entirely sure. Any suggestions?

    The first page of this forum has just the answer with this little module. Much better solution than having to a card sized Pi or router box etc.
    http://forums.parallax.com/showthread.php/157167-Preview-of-IoT5500-in-a-WIZ820io-footprint-opt-Propller-uSD

    http://forums.parallax.com/showthread.php/157167-Preview-of-IoT5500-in-a-WIZ820io-footprint-opt-Propller-uSD

    P.S. I notice the temporary forum code doesn't have any advanced posting options coming up such as embedding URLs.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-11-22 22:12
    I was hoping to stay all Prop based since I am getting more and more familiar with the code and have several circuits that connect directly with the prop. If I can use one module with 3 or 4 inputs and outputs, is Prop based, and does not require additional addons, that is what I would like to go with. The spinneret looks like it may be what I am needing but I am not quite sure. I am sure there may be a cheaper route, but for the size (Trying to stay as small as possible) and not appearing to need any additional circuitry besides the circuit that connects to the IR sensor, it looks like the easiest way for me to go without having to learn any other platform or worry I will burn something :P
  • Heater.Heater. Posts: 21,230
    edited 2014-11-22 23:20
    I think the wiznet solution is great. I would not mind to get couple to experiment with.

    The down side is in needing a that ethernet cable. Then you might need some nearby switch/router to plug it into, with it's attendant wall wart at which point the small size advantage disappears.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-11-22 23:59
    Heater. wrote: »
    I think the wiznet solution is great. I would not mind to get couple to experiment with.

    The down side is in needing a that ethernet cable. Then you might need some nearby switch/router to plug it into, with it's attendant wall wart at which point the small size advantage disappears.

    This module was meant for hard-wired installations anyway and as part of a system too, so power is already available. I don't think you'd ever really just run this from a wall-wart although it's possible especially if you can get by with the spare I/O from the module to run some sensors etc. There's up to 7 I/O on the pins plus I2C as well as another 11 I/O on the fine pitch edge pads. The base IoT5500 module is designed to fit into a cutout so that the magjack is level with the host PCB and SMD pads right to the edge allows for a simple solder bridge instead of the standard pins.

    The base module can also be controlled directly from a host Prop or CPU with just 4 I/O but you would need to run a fair bit of software to make it work. The better way would be to let the +P8 Prop handle it all including I/O or else or talk to the module via simple RX/TX and let it format up the data and send it off etc.

    The +P8 module on it's own also makes for a very compact Prop board with 14 I/O + I2C and includes either 16MB SPI Flash or microSD card and filesystem software including datalogging etc.

    PM me if you would like some at the right price, it's mainly shipping that adds up. I will get a shipment off soon for DP where he has volunteered to distribute these locally in the US. (Hang in there Dave)
  • mindrobotsmindrobots Posts: 6,506
    edited 2014-11-23 05:36
    There is more and more success with the $5 ESP8266 modules.

    http://forums.parallax.com/showthread.php/157430-Low-cost-wifi-module-ESP8266

    You can find them all over ebay. The firmware is a little rough around the edges but it is hard to beat a $5 Wifi connection!
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-11-23 08:15
    A hard wire is no problem as it already sits right next to my router any ways :) Going wireless would be cool as I could eliminate the extra wires hanging in the rat nest behind my computer. Problem is, I know enough about SPIN to get the job done one way or another. I don't quite have it down pat though. I am still at the stage where I have to take someone else's working code and modify it to do what I need it to do.

    On other thing I thought of.... I am using my computer's date and time to keep track of time inside the Prop. If the computer is turned off and the Prop does not have the ability to dump the current readings to it, the data is stored in an Array until the computer begins to communicate with it again.

    Here is the code I am using right now. Probably quite rough and could use some serious tweaking!
    CON
      _CLKMODE = XTAL1 + pll16x
      _XINFREQ = 5_000_000
      LED = 0
      Sensor = 1
      CountDelay = 10
    
    VAR
      BYTE countpointer
      LONG pulseData[255]
      LONG hourData[255]
      LONG pulseCount
      LONG count1
      BYTE Time_Count_Hours
      BYTE Time_Count_Minutes
      BYTE Time_Count_Seconds
      BYTE Time_Count_Days
      LONG pulsewidth
      LONG PulseCounterStack[100]
      LONG readDataStack[100]
      LONG receivedData
      LONG TimeStack[100]
    
      long var1
      long var2
      long var3
      byte varall[255]
    
    OBJ
      Ser     :       "FullDuplexSerialPlus"
    
    PUB Main
      pulseCount := 0
      Time_Count_Hours := 0
      Time_Count_Minutes := 0
      Time_Count_Seconds := 0
      countpointer := 0
    
      ' testing only!
      'pulseData[0] := 1234
      'pulseData[0][1] := 267
      'pulseData[0][2] := 12
      'pulseData[1][0] := 5678
      'pulseData[1][1] := 267
      'pulseData[1][2] := 13
      'countpointer := 1
      
      Ser.start(17, 16, 0, 9600)
      cognew(TimeKeeper, @TimeStack)
      cognew(PulseCounter, @PulseCounterStack)
      cognew(readData, @readDataStack)
      
      repeat
        if Time_Count_Seconds == 60
          Time_Count_Seconds := 0
          Time_Count_Minutes++
          
        if Time_Count_Minutes == 60
    
          pulseData[countpointer] := pulseCount
          hourData[countpointer] := Time_Count_Hours
          pulseCount := 0
          countpointer++
          
          Time_Count_Minutes := 0
          Time_Count_Hours++
        if Time_Count_Hours == 24
          Time_Count_Hours := 0
          
        waitcnt(clkfreq / 1000 * 200 + cnt)
    
    PUB TimeKeeper
      repeat
        Time_Count_Seconds++
        waitcnt(clkfreq / 1000 * 1000 + cnt)
    
    PUB readData | command, i
      repeat
        repeat until Ser.rx == "#"
          waitcnt(clkfreq / 1000 * 10 + cnt)
        command := Ser.rx
      
        if command == 1
          Time_Count_Minutes := Ser.rx
          Time_Count_Seconds := Ser.rx
          Ser.tx("S")
    
        if command == 2
          Ser.tx("#")
          Ser.dec(pulsewidth)
    
        if command == 3
          ' Send pulseData Array
          Ser.tx("D")
          i := 0
          repeat i from 0 to countpointer
            Ser.dec(pulseData[i])
            Ser.tx(":")
            Ser.dec(hourData[i])
            Ser.tx(",")
            'i++
    
        if command == 4
          Ser.tx("C")
          Ser.dec(pulseCount)
    
        if command == 5
          ' Clear pulseData Array
          Ser.tx("E")
          bytefill(@pulseData,0,255)
          bytefill(@hourData,0,255)
          countpointer := 0
          Time_Count_Hours := 0
        
        Ser.rxflush
          
    
    PUB PulseCounter | updated, cnt1, cnt2
      count1 := 0
      repeat
        updated := 0  
        dira[LED]~~
        repeat while ina[Sensor] == 1
          if updated == 0
            cnt2 := cnt
            pulseCount++
            updated := 1
          outa[LED] := 1
          waitcnt(clkfreq / 1000 * 10 + cnt)
          if count1 > 0
            pulsewidth := (cnt2 - cnt1) / (clkfreq / 10000) 
          count1 := 0
        if updated == 1
          cnt1 := cnt
        count1++
        outa[LED] := 0
    

    EDIT : I am also using a wall wart already. Got to keep this thing powered for years some how :p Been running for about 2 years so far with only a few minor glitches. It has helped me get my electric bill from + $200 a month to an average of $180 a month during the summer and under $100 in the winter!
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-11-23 08:32
    I just remembered about the XBee... It shows that it can communicate with an 802.11 bgn network. Would that work too? Sorry for all the questions, I am not familiar with making my own circuit to connect to a network. The XBee and the Spinneret seem to have good documentation and source codes which makes me want to lean towards either of those.
  • MJBMJB Posts: 1,235
    edited 2014-11-23 12:41
    with Tachyon you can run a webserver directly on the Spinneret or on Peter's new IoT5500+P8 module
    and FTP is there as well.
    There is also a webserver in SPIN for Spinneret.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-11-24 10:39
    I bought 2 Xbee Wifi modules and 1 Spinneret in hopes of getting them to communicate together. My goal is to use the spinneret as a socket server that receives data from the wifi modules and sends it to my server periodically. Not sure if this is able to be done, but with enough dedication and source code, I may be able to get it working.

    If this will work, I can tie different projects to the same socket server to communicate via web. Am I in over my head?
Sign In or Register to comment.