Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
craigcmehil
Community Manager
Community Manager
So with SAP TechEd Las Vegas just days away (serious it's like 3 days before I leave) I decided to why not throw a whole other mess on my desk and try something totally new.



I dusted off my old Raspberry Pi, grabbed a miniSD card and decided sure why not, let's do it!



Oh wait, what did I do? What am I rambling about? Well with our #hackthekeg Evening Event happening in Las Vegas I thought how cool would it be to have my Kegerator data showing in my Apple Home?


With the Home app, you can easily and securely control all your HomeKit accessories. Turn off the lights from your iPhone. See who’s at the front door on your iPad. And even control things remotely with the help of Apple TV. The Home app makes all your connected devices work harder — and smarter — for you.

 

But the challenge was that our Kegerator was not using HomeKit enabled hardware at the moment. So after a bit of searching I found a possible solution, more on that in a second. For now back to the RPi that I needed.

If you are not familiar with the RPi there is a gazillion pieces of information out there on it so I'm not going to deep dive that too much but I will cover some basic steps I did. Since the RPi boots off the miniSD card I just had to get a new card and replace it (hence not disturbing anything that I used it for before).

  1. You need to ensure the SD card is formatted correctly

  2. Then download "NOOBS" I took the basic one (not Lite)

  3. Stuck the card into the RPi, hooked up a network cable, mouse, monitor and keyboard

  4. Once it booted I installed Raspbian from the options and rebooted.

  5. Next I opened the terminal program from the menu and ran the command "sudo raspi-config"

  6. In the config program I then enabled SSH, VNC, changed the password of the user "pi"

  7. Then I set the boot to go command line with auto login

  8. For the reboot I unplugged everything but the network cable

  9. I then checked my network (router or other tool) to see the IP assigned to my RPi


At this stage I was able to put the thing on the shelf and ignore it and was able to run the "ssh pi@xx.xx.xx.xx" on my own computer (in my case a MacBook Air in Terminal) and connect to the RPi.

So the RPi is there, I'm connected and now I want to get back solution I thought I had found. Enter "Homebridge"
Homebridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It supports Plugins, which are community-contributed modules that provide a basic bridge from HomeKit to various 3rd-party APIs provided by manufacturers of "smart home" devices.

and I bet you guessed they have instructions for the RPi which would be why I was using it. I basically just followed the instructions (I did choose NodeJS 4.5.0 to install) as is and then jumped to the homebridge install once the RPi was ready.

I think the process took me a grand total of half an hour maybe 45 minutes.

I configured it to call the "platform" or reference it as "SAP Kegerator"

Then I opened up my phone....







 

Now that I had the bridge in the system and connected it was a matter of doing some local NodeJS coding and creating a new homebridge plugin.

There are samples, examples and even plugins published all online so I don't really want to go into the code too much but I will touch a bit on some modifications I made considering I did not actually connect this to hardware directly, instead I connected it straight to our ODATA API for the Kegerator!

WAIT!!!! WHAT??


Yep that's right I actually made my plugins connect to my SAP HANA ODATA service and not directly to the hardware, just call me a rebel rule breaking renegade!

OK so I know I just made it sound like I did massive amounts of work and modifications but there were really only a couple of lines of code I had to worry about.
var result = JSON.parse(body);
var items = result.d.results;
value = items[0].TEMPERATURE;

And by using the ODATA URL parameters I was able to limit my responses to exactly what I wanted.
/temperature?$format=json&$top=1&$orderby=ID%20desc

So all in all much easier than I actually thought..... UNTIL I tried to install the plugin to my homebridge server. Now that I have done a few though I just kind of think oh yeah that's no biggie.

  1. First you need to be sure your plugin has the standard "package.json" file

  2. Once you are done coding you need to run the command "npm pack" from the directory

  3. That will give you a packed file you then need to get onto your RPi

  4. scp xxxxxxxxx-x.x.x.tgz pi@xx.xx.xx.xx:/tmp

  5. Once it's sent up to the RPi then I ssh back to the Pi and install

  6. Make sure you are in the right directory or your directory (makes it easier)

  7. pi@raspberrypi:/usr/local/lib/node_modules $ npm install /tmp/xxxxxxxxxx-x.x.x.tgz

  8. Then modify your config.json file homebridge and include the accessory info

  9. restart homebridge

  10. If it worked then you'll see it in the logs but more importantly you will see in in Apple Home


        "accessories": [
{
"accessory": "HttpTemperature",
"name": "Keg",
"url": "xxxxxxx/temperature?$format=json&$top=1&$orderby=ID$
"http_method": "GET"
},
{
"accessory": "HttpDoor",
"name": "Keg Door",
"url": "xxxxxx/doorstate?$format=json&$top=1&$orderby=ID%2$
},
{
"accessory": "HttpInfo",
"name": "Keg Info",
"url": "xxxxxx/kegs?$format=json&$top=1&$orderby=ID%20desc"
}
]



Success I have a new accessory automatically.



 

This one was my temperature. A little tweaking a few more plugins and my Apple Home now looks like....



One tip or trick - be sure you setup homebridge to run under "systemd" on your RPi it makes restarting and checking the logs so much easier.
sudo systemctl restart homebridge

journalctl -f -u homebridge

Now with my homebridge running on a RPi, connected to my network at home - no matter where in the world I am I can access via Apple Home my Kegerator data!!! How cool!
Sep 20 11:19:09 raspberrypi homebridge[30461]: [20.9.2017, 11:19:09] Loaded plugin: homebridge-sapkegerator-door
Sep 20 11:19:09 raspberrypi homebridge[30461]: [20.9.2017, 11:19:09] Registering accessory 'homebridge-sapkegerator-door.HttpDoor'
Sep 20 11:19:09 raspberrypi homebridge[30461]: [20.9.2017, 11:19:09] ---
Sep 20 11:19:14 raspberrypi homebridge[30461]: [20.9.2017, 11:19:14] Loaded plugin: homebridge-sapkegerator-keg
Sep 20 11:19:14 raspberrypi homebridge[30461]: [20.9.2017, 11:19:14] Registering accessory 'homebridge-sapkegerator-keg.HttpInfo'
Sep 20 11:19:14 raspberrypi homebridge[30461]: [20.9.2017, 11:19:14] ---
Sep 20 11:19:18 raspberrypi homebridge[30461]: [20.9.2017, 11:19:18] Loaded plugin: homebridge-sapkegerator-temperature
Sep 20 11:19:18 raspberrypi homebridge[30461]: [20.9.2017, 11:19:18] Registering accessory 'homebridge-sapkegerator-temperature.HttpTemperature'
Sep 20 11:19:18 raspberrypi homebridge[30461]: [20.9.2017, 11:19:18] ---
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] Loaded plugin: homebridge-server
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] Registering platform 'homebridge-server.Server'
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] ---
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] Loaded config.json with 3 accessories and 1 platforms.
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] ---
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] Loading 1 platforms...
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] [Server] Initializing Server platform...
Sep 20 11:19:19 raspberrypi homebridge[30461]: [20.9.2017, 11:19:19] Loading 3 accessories...

 

So now it's really time to #hackthekeg!! Email invites started going out already and people are already signing up, we will be creating a waitlist and some additional options for joining in the next day or so!