Skip to main content

Getting started with the Ratchet backend

The backend consists of a few files, which listen for chat messages and send chats to all other connected clients.

Hardware and Software used

Steps to setup backend

  1. Install Composer with the following commands
  2. Create the project directories with the following commands
  3. Copy backend project files to the following directories
    You may want to use WinSCP if you are on a Windows machine to copy the files to the Raspberry Pi.
  4. Install Ratchet by running the following commands
  5. Modify the /var/www/html/chat/index.html file to change the IP Address to the Raspberry Pi's IP Address. If you change the port in the /var/chat/app.php file, you will need to change the port in the HTML file as well.
    Change var socket = new WebSocket('ws://localhost:8080'); to (Example shows an IP Address of 10.140.1.35 but use your Raspberry Pi's IP Address.) var socket = new WebSocket('ws://10.140.1.35:8080');
  6. Test that the backend is running properly
  7. Use systemd to run the script as a daemon on start-up
    REF: How to Execute a Command or Script at Reboot or Startup
I originally ran into issues with my FreePBX installation when I followed the steps at How to Install and Use PHP Composer on Debian 10. The step "sudo apt install wget php-cli php-zip unzip" installed PHP 7.4 on the system. I was not aware that FreePBX will not work with PHP 7.4.

If you make this mistake, you may work around FreePBX not working by reading what I found and documented in the FreePBX Ticket FREEPBX-21883. Unfortunately, the fix will break PHP Ratchet so your chat application will no longer function.

File Contents

Contents of the five files used for the Chat application, test, and service.