Image of an arrow

How does Ring communicate with connected devices # IoT

Avatar

cmarchi

light-bulbWhen you leave home, are you sure the lights are turned off? With Ring, you can check it with a video camera and adjust them simply by sending a text message through live chat. Save energy!

Within an hour, a Savoir-faire Linux expert has built a device that allows him to control the lighting in his living room, while he is at the office. As Adrien Béraud has set his Ring account to automatically accept every call, he can see his living room remotely by simply initiating a video call to his home computer. He can then check if the lights are on, and turn them off as needed.

A simple device crafted with open hardware

Ring-arduinoAdrien first connected lamps in his living room to the Internet using a small connected system Particle Core (type Arduino) and a relay expansion board (Relay Shield). As his lightning is associated with a three-way switching circuit, it can easily control lights, even in the case of Internet failure or in case of problems with the relay. He then added a few lines of code in the documentation of the relay to connect it the Internet.

With some command line, your lights are connected

Once connected, he types a command line in the terminal of his Linux computer. For example, to turn off (LOW) the first lamp (r1):

curl https://api.particle.io/v1/devices/0123456789abcdef/relay -d access_token=123412341234 -d params=r1,LOW

Light control with Ring’s chat can then be done with this Python script:

#!/usr/bin/env python3
import re, json, http.client, urllib.parse
from controler import DRingCtrl

PARTICLE_API_TOKEN = '[your_api_token_here]'
PARTICLE_REQ_URI = '/v1/devices/[your_device_id_here]/relay'
PARTICLE_REQ_RE = re.compile('^(r[0-4],(?:HIGH|LOW))$')

class LightRingController(DRingCtrl):
    def __init__(self):
        super().__init__("LightController")

    def tryParticleReq(self, params):
        try:
            conn = http.client.HTTPSConnection('api.particle.io')
            p = urllib.parse.urlencode({'access_token': PARTICLE_API_TOKEN, 'params': params})
            conn.request("POST", PARTICLE_REQ_URI, p, {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
            ret = json.loads(conn.getresponse().read().decode())['return_value']
        finally:
            conn.close()
        return ret

    def onIncomingMessage(self, callid, ufrom, message):
        super().onIncomingMessage(callid, ufrom, message)
        msg = message['text/plain']
        res = re.search(PARTICLE_REQ_RE, msg)
        if res:
            op = res.group(0)
            print('Command:', op)
            ret = self.tryParticleReq(op)
            self.callmanager.sendTextMessage(callid, {'text/plain':'Got: '+str(ret)}, False)

if __name__ == "__main__":
    ctrl = LightRingController()
    ctrl.run()

IoT: endless possibilities

Many uses are possible, from simple to complex. For example, a Ring call can directly control lighting with such a script:

#...

class LightRingController(DRingCtrl):

    #...

    def onCallStateChanged(self, callid, state, statecode):
        super().onCallStateChanged(callid, state, statecode)
        if state == "HUNGUP":
            self.tryParticleReq('r1,LOW')
        elif state == "CURRENT":
            self.tryParticleReq('r1,HIGH')

So imagine what you could do if your Ring software was connected to your heating or your garage door… The possibilities are endless!

You have ideas to share? Feel free to comment!

Leave a comment

Your email address will not be published. Required fields are marked *


Similar articles

Image of an arrow

Push Notifications: A New Feature Added to Ring Project Push notifications are essential part of the effective end-user experience on mobile platforms. They tend to boost the app engagement and users find them useful and handy as they ease their communications. Although push notifications are widely considered an advantage for most apps, they are regarded […]

On February 3rd and 4th, two members of Ring’s development team took part in FOSDEM 2018 in Brussels. FOSDEM (Free and Open Source Software Developers’ European Meeting), a major event for free software developers, is held annually since 2000 during the first week-end of February at the Université libre de Bruxelles. Sébastien Blin, a Ring […]

Thumbnail image

July 21, 2017 – Savoir-faire Linux releases the stable version of Ring:  Ring 1.0 – Liberté, Égalité, Fraternité. Ring is a free/libre and universal communication platform that preserves the users’ privacy and freedoms. It is a GNU package. It runs on multiple platforms; and, it can be used for texting, calls, and video chats more privately, more […]