Пример #1
0
    def _send(self, req: Request):
        """Sends a request on the serial port"""

        json_str = json.dumps(req.get_body())

        req_line = "!r_p[{}]_b[{}]_\n".format(req.get_path(), json_str)
        self._logger.debug("Sending: {}".format(req_line[:-1]))
        out_data = req_line.encode()
        bytes_written = self._serial_client.write(out_data)
        if not bytes_written == len(out_data):
            self._logger.error(
                f"Problem sending request: only {bytes_written} of {len(out_data)} bytes written."
            )
 def _format_request(req: Request) -> str:
     req_obj = {"path": req.get_path(), "body": req.get_body()}
     req_str = json.dumps(req_obj)
     return req_str
Пример #3
0
    def _format_request(req: Request) -> str:
        json_str = json.dumps(req.get_body())

        req_line = "!r_p[{}]_b[{}]_\n".format(req.get_path(), json_str)
        return req_line
 def _send(self, req: Request):
     topic_with_channel = f"{self._channel}/{req.get_path().strip('/')}"
     self._client.publish(topic_with_channel, json.dumps(req.get_body()))