Weather Station, Webserver, and Serial Comms

Discussion in 'Pascal Logic Code Examples' started by NickD, Jan 18, 2010.

  1. NickD

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,427
    Likes Received:
    64
    Location:
    Adelaide
    Here's something I hope people will find useful.

    I did most of this nearly 6 months ago when I was off work for a week with the swine flu... too sick to go to work but not sick enough not to be bored out of my mind doing nothing.... so call me a geek.

    It started out as a project to talk to a weather station like one of these.

    ..but then I wanted to share the info I'd got from it with other devices, and after a brief conversation with matty, we worked out we could implement a basic web server in logic too.

    I've been running this code in my own installation for a few months now... I've set up a proxy in my "proper" webserver to forward requests for the weather station to the Colour Touchscreen and it's been working reliably (my friends who live nearby use it regularly to check how much rainfall we've had).

    The attached project is not very pretty, but the logic code has plenty of examples of how to tackle various problems, and the webserver is kind of cool (IMHO).. and I think it's a good example of how powerful the logic engine really is (thanks darren!).

    Next is to make it tweet with weather observations... but that might have to wait until the next flu season...

    Feel free to use this as you like.. any questions, comments, etc welcome.

    Nick
     

    Attached Files:

    NickD, Jan 18, 2010
    #1
  2. NickD

    nickrusanov

    Joined:
    Aug 5, 2004
    Messages:
    308
    Likes Received:
    0
    Location:
    russia
    looks nice to have such kind of a code, thank you!

    but what kind of hardware do we use?

    Wireless Vantage Pro2 and C-Touch through RS232? what kind of web server do you mean?
     
    nickrusanov, Jan 28, 2010
    #2
  3. NickD

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,427
    Likes Received:
    64
    Location:
    Adelaide
    The hardware is the Wireless Integrated Sensor Suite and Weather Envoy with the RS232 interface, connected to a Colour C-Touch. You could just as easily use a B&W C-Touch Mk2, although the number of System IO variables used may be a problem.

    The code I've posted uses serial communications but in reality my project at home uses an old Lantronix UDS10 serial-ethernet converter because the RS232 port on my Colour C-Touch was already used to control my AV receiver.. Changing the code to support this is as simple as changing the intitalisation to "OpenClientSocket" instead of "OpenSerial", and changing all the "ReadSerial" and "WriteSerial" statements to "ReadClientSocket" and "WriteClientSocket".


    The code implements a simple webserver in the Logic Engine, using the ServerSocket functions, to make the weather data available via http.

    In my installation I have a "proper" webserver running (Apache running on an iMac), so I have set up a proxy in that to forward requests for the weather page to the Colour Touchscreen.

    Nick
     
    NickD, Jan 28, 2010
    #3
  4. NickD

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,427
    Likes Received:
    64
    Location:
    Adelaide
    Bad form to reply to one's own post I know, but here's a screenshot of the page served up by the Colour Touchscreen :
     

    Attached Files:

    NickD, Feb 11, 2010
    #4
  5. NickD

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,427
    Likes Received:
    64
    Location:
    Adelaide
    I also note that in the screenshot above the weather station is indicating that it's raining... yet the forecast is "Fine"..... we are having some strange weather at the moment here though.

    The station is actually usually surprisingly accurate with its forecast of rain, and even snow... It snows quite rarely in the Adelaide Hills.. but the weather station predicted the only snowfall we had last year (I scoffed at the prediction at the time but it proved me wrong).

    Nick
     
    Last edited by a moderator: Mar 19, 2010
    NickD, Feb 11, 2010
    #5
  6. NickD

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    229
    Likes Received:
    47
    Keep producing stuff like this Nick and someone is gunna start spiking your drinks with viruses to keep you crook! kudos mate
     
    Damaxx, Feb 17, 2010
    #6
  7. NickD

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,427
    Likes Received:
    64
    Location:
    Adelaide
    New feature in Logic

    With the recent release of PICED 4.8.x, I can now tell you about another cool new feature in logic that I've used in my weather station project.

    You can now *send* messages on the C-Bus Measurement application from logic (actually from System IO too).

    If you look under the Measurement Manager, you'll see a tick box labelled "controllable", as well as some new entries under the "Set IB System IO" menu in the logic wizard. If you tick the "controllable" box on a particular measurement channel in the Measurement Manager, you can specify the units, and you will be able to *Set* this measurement from logic, or from a System IO control. When changed, the new value will be sent on the Measurement application with the units you specified in the Measurement Manager.

    What this means for the weather station is that I can make the measurements from it available to other C-Bus devices, so another Touchscreen can display them, or a PAC or Wiser could use them in its own logic. In my case the weather station code is running on the Colour C-Touch, and once a minute it broadcasts some of the measurements to the C-Touch Spectrum by the bed.

    The code to do this is dead simple :

    Code:
    once (Second = 0) then
      begin
        r_temp := GetRealSystemIO("Daily Rainfall");
        SetRealIBSystemIO("Measurement App Real Value", "WIRED", 0, 0, r_temp);
        delay(5);
        r_temp :=  GetRealSystemIO("Inside Temperature");
        SetRealIBSystemIO("Measurement App Real Value", "WIRED", 0, 3, r_temp);
        delay(5);
        r_temp := GetRealSystemIO("Outside Temperature");
        SetRealIBSystemIO("Measurement App Real Value", "WIRED", 0, 1, r_temp);
        delay(5);
        r_temp := GetRealSystemIO("Rain Rate");
        SetRealIBSystemIO("Measurement App Real Value", "WIRED", 0, 2, r_temp);   
      end;
    
    The parameters of the function are the network, Device ID and channel as set in the Measurement Manager, and the value.

    You could also use this feature to make measurements from any device with an RS232 or Ethernet interface/protocol available on C-Bus via the Measurement application.

    Nick
     
    Last edited by a moderator: Mar 19, 2010
    NickD, Mar 19, 2010
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.