Getting started on TCP/IP CAN based devices

Hello everyone, I am just new to creating a Homey app. Watched all 3 :grin: YT videos on how to do it and it seems to be a no brainer. Now I would like to integrate my hobbyist Can based home automation system into Homey. It should be easy since all I have to do is send and read TCP/IP commands (also mentioned as frames). However since I’m new to node.js and generally haven’t done lot of programming since quite some time I am looking for a kind support here.

Let me start with a perhaps silly question: how to send a TCP/IP command from Homey app? For reference, here what I use in my local web server PHP script:

<?php function SendHapcanCommand( $action ) { if(($sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp")))) { if(socket_connect($sock, '192.168.1.100', 1001)) { $message = hex2bin($action); if( socket_send ( $sock , $message , strlen($message) , 0)) { if(socket_recv ( $sock , $buf , 2 , MSG_WAITALL ) === FALSE) { $message = bin2hex($buf); return $message; } } } } return "Error"; } ?>

And then I simply call the above function with the message that my Can system can understand:

Send_Hapcan_Form_Cmd(“AA10A0ABCD0202080100FFFFFF32A5”)

Of course the value I am sending depends on a device (relays, shutters, LED dimmers etc.) but I am able to build it dynamically.

So, what would the best and elegant way to send such a command on ‘onoff’ capability in the Homey app?

1 Like