Building a backend to connect with devices using a Websocket connection

Hi, I’m fairly new to low code backendless, however thanks to the intuitive interface and Marks amazing intro videos I’m already seeing some nice results.

What I am still struggling to fully understand yet however - and I couldn’t find anything related in the docs - if it’s possible at all in Backendless to build a service that on a very basic level listens to incoming connections requests via websocket from the outside, like in the simple python code below.

I’m building a central system that electric vehicle chargers can connect to. Information exchange happens using Rest/JSON based on the open OCPP 1.6j protocol. According to this protocol, a websocket connection is opened by the charge point with an “opening handshake” as described in RFC6455.

I’m not asking for any coding help or pointers, just would like to know if this is possible to do at all (using JS for example), or if I have to build a standalone service that will run between Backendless and the charge points.
Thanks!

import asyncio
import websockets

from datetime import datetime

from ocpp.routing import on
from ocpp.v16 import ChargePoint as cp
from ocpp.v16.enums import Action, RegistrationStatus
from ocpp.v16 import call_result


class MyChargePoint(cp):
    @on(Action.BootNotification)
    def on_boot_notitication(self, charge_point_vendor, charge_point_model, **kwargs):
        return call_result.BootNotificationPayload(
            current_time=datetime.utcnow().isoformat(),
            interval=10,
            status=RegistrationStatus.accepted
        )


async def on_connect(websocket, path):
    """ For every new charge point that connects, create a ChargePoint instance
    and start listening for messages.

    """
    charge_point_id = path.strip('/')
    cp = MyChargePoint(charge_point_id, websocket)

    await cp.start()


async def main():
   server = await websockets.serve(
      on_connect,
      '0.0.0.0',
      9000,
      subprotocols=['ocpp1.6']
   )

   await server.wait_closed()


if __name__ == '__main__':
   asyncio.run(main())

Hi Sam,

Thank you for checking out Backendless. We have our own socket server implementation used for real-time database and Overview - Backendless SDK for JavaScript API Documentation, however, you’d need to use our SDK (any of them) in order to send/receive events/messages. My understanding you would not have the freedom to inject our SDK into the chargers. A possible solution would be to stage a separate (your own) server that can accept messages from the chargers and then proxy them into Backendless for further processing.

Regards,
Mark

1 Like