Skip to content

communication

vincePekaway edited this page Jan 20, 2024 · 15 revisions

Communication

The VanPi system supports several ways of communication between devices. Please read below for detailed information.

HTTP API

With the HTTP API you can get information about the states and names of switches etc., as well as change the state and rename them. To request the HTTP API keep in mind, that you'll need the IP-address of your Raspberry Pi device and the port for Node-RED (standard is 1880). the following requests are supported:

Names:

  • GET /names - displays all names (as shown in frontend) and the respective global variables (used in backend)
  • PUT /names/<device>/<input>/<value> - set new names for the frontend, with <device> being the device you want to address, <input> the device number and <value> being the new name.
    • For the device you can use "relay", "wrelay", "dimmer", "level" or "temp", device number ( = <input>) can be 1-10
    • Example: PUT http://RPI-IP:1880/names/relay/3/Lights Kitchen - the name of relay 3 will then be shown as Lights Kitchen in the frontend

Battery:

  • GET /batt - displays current battery status

Level:

  • GET /level - displays current waterlevel status

Temperature:

  • GET /temp - displays current temperature status

Heater:

  • GET /heater - displays current heater status
  • PUT /heater/<truefalse> - turns the heater on or off, with truefalse being either true or false
  • PUT /heater/<truefalse>/<temp> - turns the heater on or off with a target temperature in Celsius, <temp> has to be set to a number between 12 and 35
  • PUT /heater/<truefalse>/<temp>/<time> - turns the heater on or off, with a target temperature and a timer in minutes, <time> has to be a number between 1 and 600. Notice that there is no timer counting down in the frontend, it only runs in the backend.

Autoterm specific endpoints (experimental):

  • PUT /autoterm/<ventilation_heatingpower>/<value> - Set Ventilation or Heatingpower with a value between 0 and 10. <ventilation_heatingpower> must either be "ventilation" or "heatingpower".

Relays:

  • GET /relay/<input> - displays current relay state of choosen relay, <input> can be one to ten, or 1 to 10 or all
  • GET /relay - displays all current relay states, same as GET /relay/all
  • PUT /relay/<input>/<value> - change the choosen relay state, <input> can be one to ten, or 1 to 10 and <value> has to be true or false for on/off
  • PUT /toggle/relay/<input> - toggle the choosen relay state, <input> can be one to ten, or 1 to 10, based on the current state it will turn either on or off

Wifi-Relays:

  • GET /wrelay/<input> - displays current wifi-relay state of choosen relay, <input> can be one to eight, or 1 to 8 or 'all'
  • GET /wrelay - displays all current wifi-relay states, same as GET /wrelay/all
  • PUT /wrelay/<input>/<value> - change the choosen wifi-relay state, <input> can be one to eight, or 1 to 8 and <value> has to be true or false for on/off
  • PUT /toggle/wrelay/<input> - toggle the choosen wifi-relay state, <input> can be one to eight, or 1 to 8, based on the current state it will turn either on or off

Dimmers:

  • GET /dimmer/<input> - displays the current dimmer state as a range from 0 to 100, <input> can be one to eight, or 1 to 8 or 'all'
  • GET /dimmer - displays all current dimmer states, same as GET /dimmer/all
  • PUT /dimmer/<input>/<value> - change the dimmer state, <input> can be one to eight, or 1 to 8 and <value> has to be a number between 0-100 (0 is off, 100 fully on)

Switch all off:

  • PUT /switchall/false - this will switch all relays, wifi-relays and dimmers off

Set date and time:

  • PUT /attime?date=YY/MM/DD&time=hh:mm:ss&gmt=+04 - this will set the date and time of the server with gmt being 15min steps to Greenwich Mean Time, so range is -48 to +48
    • (Headers are "Content-Type: text/html; charset=utf-8")
    • Remember to turn off network time sync (systemd-timesyncd.service), otherwise it'll always overwrite the time.

MQTT API

A Mosquitto MQTT Broker is served on the standardport 1883. Please note that all topics and payloads are case sensitive! Also make sure there are no additional spaces in your payload. In the VanPi configuration tab there's a switch "Send stats via MQTT" - Turning it on will send all stats every 5min under the topic pkw/tele/#. Use the following topics to address your devices:

Battery:

  • pkw/stat/batt - publishing anything to this topic will return current battery stats under pkw/tele/batt

Level:

  • pkw/stat/level - publishing anything to this topic will return current level stats under pkw/tele/level

Temperature:

  • pkw/stat/temp - publishing anything to this topic will return current temperature stats under pkw/tele/temp

Heater:

  • pkw/stat/heater - publishing anything to this topic will return current heater stats under pkw/tele/heater
  • pkw/cmnd/heater/POWER - publish a payload with "on" or "off" to this topic to turn the heater on or off
  • pkw/cmnd/heater/POWER/<temp> - publish a payload with "on" or "off" to this topic to turn the heater on or off with <temp> being the desired temperature from 12 to 35 in Celsius
  • pkw/cmnd/heater/POWER/<temp>/<time> - publish a payload with "on" or "off" to this topic to turn the heater on or off with a target temperature and a timer in minutes, <time> has to be a number between 1 and 600. Notice that there is no timer counting down in the frontend, it only runs in the backend.

Autoterm specific endpoints (experimental):

  • pkw/cmnd/heater/autoterm/<ventilation_heatingpower>/<value> - Set Ventilation or Heatingpower with a value between 0 and 10. <ventilation_heatingpower> must either be "ventilation" or "heatingpower".

Relays:

  • pkw/cmnd/relay/<input>/POWER - publish a payload with "on" or "off" to set the respective relay, with <input> being a number between 1 and 10

Wifi-Relays:

  • pkw/cmnd/wrelay/<input>/POWER - publish a payload with "on" or "off" to set the respective wifi-relay, with <input> being a number between 1 and 8

Dimmers:

  • pkw/cmnd/dimmer/<input>/POWER - publish a payload with "0" up to "100" to set the respective dimmer, with <input> being a number between 1 and 8

Switch all off:

  • pkw/cmnd/switchall/POWER - publish a payload with "off" or "false to switch off all relays, wifi-relays and dimmers

Homebridge

Homebridge is included in the VanPi image and runs by default. You can turn it off in the config tab. The reason having it run by default is simply that on the very first boot it generates a new pin number. The pin can be displayed in the frontend GUI (config tab) or you can reach the Homebridge admin panel on its standard port 8581 with default login credentials being admin:pekawayfetzt. When your Raspberry Pi is in Access Point mode, Homebridge can also be reached at http://homebridge.peka.way (via nginx). If you turn Homebridge off it will stay deactivated even after reboot, until you turn it back on.

USB Serial & MULTIUART

Since many devices are using a serial interface to exchange data, the VanPi system can connect to 2 USB-serial-adapters. Supported devices can be set via the frontend in the config tab. It is important to understand that the different devices are using different current levels!

On the VanPi circuit boards we also brought out the UART3 port of the Raspberry Pi, which can be used for communication. We describe this port as "MULTIUART" and it can be connected to with a JST-PH (4 pin) plug.

All serial configuration is done in Node-Red in the "connections flow". There we bind directly all serials to Node-Red. So if you want to use a serial port on an other tool you have do deactivate or delete it in the "connections flow". The connections flow also setup the baudrates and the routing to the different device flows.

MULTIUART can only handle 3.3V and max amps of 50mA!

MULTIUART PORT (JST CONNECTOR) is connected to /dev/ttyAMA1 (UART5) BREAKOUT UART

RaspberryPI4 UART overview

(RPI3 and Zero2 can only use UART1)

TXD1 - GPIO14 - Pin8 DISPLAY - UART1 TX1 RX1 BREAKOUT WHEN RASPBERRY ZERO
RXD1 - GPIO15 - Pin10 DISPLAY - UART1 TX1 RX1 BREAKOUT WHEN RASPBERRY ZERO
TXD2 - GPIO0 - Pin27 connected to raspberry zero pads
RXD2 - GPIO1 - Pin28 connected to raspberry zero pads
TXD3 - GPIO5 - Pin29 - not in use
RXD3 - GPIO4 - Pin7 - not in use
TXD4 - GPIO8 - Pin24 connected to wemos esp port and breakout RX2 TX2 NOT WORKING NOW
RXD4 - GPIO9 - Pin21 connected to wemos esp port and breakout RX2 TX2 NOT WORKING NOW
TXD5 - GPIO12 - Pin32 Relayboard breakout TX5 RX5 + MultiUart
RXD5 - GPIO13 - Pin33 Relayboard breakout TX5 RX5 + MultiUart


On our first PCBs (the blue ones) we used UART3 for the Multiuart.

To use these hardware UART you have to setup the "dtoverlay=uart2,uart3,uart4,uart5" on the boot/config.txt.

On the VANPI IMAGE we are using only UART5 for now.

USB SERIAL

To have a stable connection to usb-serial-adapters we setup a udev rule to bind the specific usb-ports on the Pi to a fixed serial device name. If you don't have fixed names for them, sometimes after rebooting the system the connections where swapped.

The udev rules are located in /etc/udev/rules.d/

setupUDEV

setupUDEV

Victron

Devices of VictronCE send their stats every second using the VE.Direct interface. Currently the VanPi System is only able to read and display those values.

Victron Devices can be connected either via the MULTIUART or the USB interface.

Victron devices are using either 5V or 3.3V. It is important to not directly connect the 3.3V MULTIUART interface to a 5V device! It is crucial to have a level converter between them.

In our shop section we do offer USB adapters with integrated level convertes, which can be used with all Victron devices.!

Victron USB adapter in our Shop.

For further details about Victron devices, Victron offers well written documentations regarding the protocols in usage.

Clone this wiki locally