Brovning Posted May 24, 2020 Share Posted May 24, 2020 (edited) Hello, is it possible to implement a RSCP (Remote-Storage-Control-Protocol) communication for a PV-battery with PHP? I'm experienced with PHP, but I have never implemented a socket communication with PHP... How do I create a frame fulfilling the length constraints (see attached image)? For example, what do I have to do to send the following frame: Frame: 0xE3 0xDC 0x01 0x00 0x11 0x59 0x7B 0x53 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0E 0x00 0x20 0x00 0x00 0x06 0x00 0x00 0x00 0x12 0x00 0x00 0x01 0x00 0x00 0x00 + CRC32 Checksum Best regards, Brovning Edited May 24, 2020 by Brovning Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/ Share on other sites More sharing options...
gizmola Posted May 24, 2020 Share Posted May 24, 2020 Yes. Take a look at stream_socket_client and pack. I don't think this type of application is PHP's forte, but it is possible. Creating an executable with c, c++ or Go would be a simpler final product upon completion, but PHP is certainly capable. Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/#findComment-1578338 Share on other sites More sharing options...
Brovning Posted May 24, 2020 Author Share Posted May 24, 2020 Hello, thank you! I found a Cpp implementation for this protocol, but I'd like to have it in PHP, because my home automation is based on PHP. What is the easiest way to "convert" a Cpp implementation to PHP? Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/#findComment-1578341 Share on other sites More sharing options...
gizmola Posted May 24, 2020 Share Posted May 24, 2020 Did you look at the links I provided? There's not much more to it. Pack will let you pack the bytes into a binary string. You make the socket connection and fwrite the packed string to it. Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/#findComment-1578342 Share on other sites More sharing options...
Brovning Posted May 24, 2020 Author Share Posted May 24, 2020 Hello, yes, I tried it, but the server is not responding: $fp = stream_socket_client("tcp://".$serverIp.":".$serverPort, $errno, $errstr, 30); $msg = pack("n*", 0xE3DC, 0x0100, 0x1159, 0x7B53, 0x0000, 0x0000, 0x0000, 0x0000, 0x0E00, 0x2000, 0x0006, 0x0000, 0x0012, 0x0000, 0x0100, 0x0000); $msg .= pack("N", crc32($msg)); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { fwrite($fp, $msg); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); } I'm receiving a timeout after 30 seconds. Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/#findComment-1578343 Share on other sites More sharing options...
gizmola Posted May 24, 2020 Share Posted May 24, 2020 I'm not familiar with this protocol. Are there other details (authentication or encryption for example) that might explain your result? Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/#findComment-1578345 Share on other sites More sharing options...
requinix Posted May 24, 2020 Share Posted May 24, 2020 What's the C++ code you're working from? Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/#findComment-1578354 Share on other sites More sharing options...
NotionCommotion Posted May 27, 2020 Share Posted May 27, 2020 Maybe I am wrong but sure looks like serial communication (most likely RS-485) and not Ethernet. Quote Link to comment https://forums.phpfreaks.com/topic/310841-rscp-communication-with-php/#findComment-1578404 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.