Querying configuration information from the LightwaveRF website

LightwaveRF Communi… > Forum > LightwaveRF Hackers > Querying configurat…

LightwaveRF Community: Welcome Forums LightwaveRF Hackers Querying configuration information from the LightwaveRF website

This topic contains 5 replies, has 4 voices, and was last updated by  tinkerfailure 5 years, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #3818
     Anonymous says:

    Anonymous

    If you are a developer, or a dabbler, then you may be trying to get your LightwaveRF devices to do your bidding with a variety of scripts. Thanks to the information that has leaked from the (bizarrely) closed API for the WiFi link into the public domain, it’s not too hard to do this if you have a bit of development know-how. One of the challenges though is getting the configuration out of the WiFi Link itself – eg it’s easy to tell it to turn device 1 in room 2 on, but what is device 1 and which room is room 2?

    Because no-one seems to have worked out how to interrogate the WiFi Link – in fact it doesn’t seem possible at the moment – I thought I’d try to interrogate the “My LightwaveRF” part of the LightwaveRF website instead. It’s possible, so I thought I’d post my code here for others to use as inspiration.

    The code is in Python 2.6.4 (note that it may not work in any other version of Python 2 and won’t work in Python 3.x). Big caveat – it works today (January 7th, 2013) but if JSJS Designs change the website, it may stop working. All it does is:

    1. Interrogate the website

    2. Grab the configuration information

    3. Print it out

    Very simple – most of the faff is for the print-out step in fact. To use it, just edit the lines at the top with your email address and PIN and run it.

    Enjoy!


    """
    Quick and dirty script to scrape the LightwaveRF website for
    configuration information, because JSJS Designs won't let
    developers access the web API to get this information.

    Proof of concept; this does work but has no error handling
    and is not resilient to the website design being changed.
    It worked on 7 January 2013.

    Target language : Python 2.6.4
    Date : 7 January 2013
    Author : dev[at]billinge(dot)me(dot)uk
    """
    import urllib, re

    # Set up parameters
    base_url = "https://lightwaverfhost.co.uk/manager/"
    email_address = ''
    pin = ''

    # Get data from web page into a list
    post_url = base_url + "index.php"
    parameters = urllib.urlencode({'email' : email_address, 'pin' : pin})
    url = urllib.urlopen(post_url, parameters)

    # We need some JavaScript variables. The following regex will help get them
    jsvar_regex = re.compile('var ([A-Za-z]*) = ([^;]*)')
    jsvars = {}
    for line in url:
    # Get all JavaScript variables in this line and store them in the jsvars_dict dictionary
    for variable, value in jsvar_regex.findall(line):
    jsvars[variable] = eval(value)

    url.close()

    # Only proceed if we have the info we need. Just check to see if we have any rooms.append
    if jsvars['gRoomNames'] != ['']:
    # We now have all the data we need. Put it in an easy to use format.
    # Rooms: We just want active rooms here. The website records more than we need
    room_number = 0
    rooms = []
    for room in jsvars['gRoomNames']:
    if jsvars['gRoomStatus'][room_number] == 'A':
    # This is an "active" room, so record it
    rooms.append(room)
    room_number += 1

    # Devices - gDeviceNames is a rather peculiar structure of 80 values, structured as the following ten values for each room:
    # Devices 1 - 6, Mood 1 - 3, All Off
    # The other variable, gDeviceStatus, appears to have an entry for each device, with the following values (these are my guesses):
    # O: on
    # o: off
    # I: inactive (ie not configured)
    # m: inactive mood
    # M: active mood
    #
    # The code below just splits this into two lists (devices, device statuses) for each room, ignoring inactive rooms. It does no further processing
    devices = []
    device_statuses = []
    room_number = 0
    for room_number in range(0,8):
    if jsvars['gRoomStatus'][room_number] == 'A':
    device_number = room_number * 10
    devices.append(jsvars['gDeviceNames'][device_number:device_number+10])
    device_statuses.append(jsvars['gDeviceStatus'][device_number:device_number+10])

    # Timers - this is a list of lists
    timers = []
    for timer in jsvars['gTimers']:
    timers.append(timer)

    # Sequences - this is a list of lists
    sequences = []
    for sequence in jsvars['gSequences']:
    sequences.append(sequence)

    # Get settings
    setting_geo = jsvars['gSettingsArray'][3]
    setting_timezone = jsvars['gSettingsArray'][4]
    setting_mac = jsvars['gSettingsArray'][5]

    # Display resulting data extraction
    print "Rooms: %d" % len(rooms)
    room_number = 0
    for room in rooms:
    print " Room %d: %s" % (room_number + 1, room)
    device_number = 0
    for device in devices[room_number]:
    # Only display devices and moods that are active
    device_status = device_statuses[room_number][device_number]
    if device_status in 'OM':
    print " Device %d: name=%s, status=%s" % (device_number + 1, device, device_status)
    device_number += 1
    room_number += 1
    print
    print "Geographical location : %s " % setting_geo
    print "Timezone : %s " % setting_timezone
    print "MAC address : %s " % setting_mac
    print
    print "Timers:"
    timer_counter = 1
    for name, when, details, started in timers:
    print " Timer %d:" % timer_counter
    print " Name : %s" % name
    print " When : %s" % when
    print " Details : %s" % details
    print " Started : %s" % started
    timer_counter += 1
    print
    print "Sequences:"
    sequence_counter = 1
    for sequence in sequences:
    name = sequence[0]
    steps = sequence[1:]
    print " Sequence %d:" % sequence_counter
    print " Name : %s" % name
    print " Steps (%d) : %s" % (len(steps), ", ".join(steps))
    sequence_counter += 1
    else:
    print "No configuration information available - have the correct credentials been provided?"

    • This topic was modified 5 years, 7 months ago by  @Chris.
    #3821
     Chris says:

    Chris
    Key Master

    Wonko, would you mind putting some more words around this and making it a blog post (feature from the menu at the top)? While traffic to the forum is picking up, it’s stuff like this that makes the community great and what I want to promote through the use of the blog. It will also allow us to tweak the SEO a bit to give it good search engine exposure and I will put something on the front page slider.

    If you are happy, I will see what I need to do to give you editing permission.

    This offer goes out to others too – if you have a specific project that you would be happy to write about (and maintain) in more depth than a simple forum post, please let me know and we can increase the use of the blog.

    Chris Mills Founder and Editor - LightwaveRF Community http://cpmills.com/ http://lightwaverfcommunity.org.uk
    #3869
     Anonymous says:

    Anonymous

    Sounds like a good idea – I’d be happy to turn this into a blog post. Let me know when you’ve updated the permissions.

    #3873
     pauly says:

    pauly
    Participant

    if you don’t use the mobile app, then I don’t think what you have told the official servers you are calling the rooms matters. I worried about this at first, I had set up the dining room as room 1 and the bedroom as room 2 and was concerned about keeping in sync with this as I developed my own stuff, but does it matter? I reordered them, and everything still works. It seems like the protocol must take into account the device you are sending from when you send the signal, so when I put the lounge lights in  learning mode and first sent a signal from the command line on the raspberry pi I called that room 1 device 1 this time, and everything still works as expected.

    I’m not imagining this am I? I seem to be bypassing the “official” config.

    Is everyone else making heavy use of the phone app?

    12 rooms automated, time to stop now... API + more at https://github.com/pauly/lightwaverf
    #3879
     Chris says:

    Chris
    Key Master

    I am in the process of hacking together my own Objective-C code (maybe for ultimate deployment to my (and others?) iPad/iPhone) and in testing, I just replicated the device/room code from my existing official iPhone app and the same lights activated (once I’d authorized the mac with the Wi-Fi link of course). This makes me think that the room and device number sent to the Wi-Fi link are mapped internally to specific identifiers that are transmitted over the 433.92Mhz radio so sending the same device and room IDs from different devices results in the same radio signal and the same devices doing what they are supposed to.

    There is no reason (other than filling the memories) why you couldn’t pair a dimmer with two different room/device ID’s. The only limitation would be that you would be using more of the six available pairing slots in each device and if you had other devices using the same room/device ID’s elsewhere in the house, these would activate too.

    With website app, I assume this is just sending the room/device ID to your Wi-Fi link and it responds the same way. There is room in the UDP protocol to send a string and this is then displayed on the LCD when the Wi-Fi link does it’s thing. None of the code I have written uses it – my Wi-Fi link is in the loft and I can’t see it without getting a ladder out so it just adds unnecessary bytes to the network traffic.

    Chris Mills Founder and Editor - LightwaveRF Community http://cpmills.com/ http://lightwaverfcommunity.org.uk
    #4042
     tinkerfailure says:

    tinkerfailure
    Participant

    Hi All,

    I only found this forum yesterday. Very nice work Chris!

    I’ve been using my own app on my iphone for a few months now. I had a fiddle with XCode on the Mac to see what was involved with writing a ‘proper’ Objective-C app for the iphone. But I reckon the level of complexity I require is well within the capabilities of an HTML5 web-app. This has a couple of benefits for me: I’ve been writing PHP and HTML/CSS for a few years now, and it free’s the app from the constraints of being tied to one platform or another.

    Currently, I have 2 seperate CSS layouts. One for the iPhone and a larger one for the iPad (which is currently also selected if you visit it from a computer browser, I’ll write a full one later). There’s a bit of stuff to display temperature graphs for the house, but the main use for it at the moment is to do LightwaveRF switching.

    It’s all made possible by the work Steven over at http://blog.networkedsolutions.co.uk/?p=149 did. I expanded on his work decoding the WiFiLink messages and basically set up a controller that sets different moods. The backend script can be found here:

    LightwaveRF PHP Script

    Feel free to use or revise the code as you see fit!

    Chris

     

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.