0

For some basic background we are trying to develop an ADAS application using a serverless framework 'OpenFaas-Faasd'. We currently have a lidar sensor and a sunfounder rpi car as our vehicle. We are also communicating the lidar data to our serverless function through MQTT broker 'Mosquitto' using the OpenFaas 'mqtt-connector'.

We are using a Lidar to publish when objects are within 20cm to our serverless function using triggers with the mqtt-connector. Our serverless function receieves these messages, but it cannot communicate with the car because the 'picar_4wd' package import doesn't seem to work with OpenFaasd for some reason. So we decided another approach to have an 'external controller' to communicate with the car and publish commands for the rpi car through the serverless function. This is where we reached another problem as we were using paho to publish the lidar data locally to our MQTT broker 'Mosquitto' but I think our serverless function cannot communicate with our broker so we are running into errors trying to connect with the broker as it most likely has a different ip address. We looked into this a bit futher on how to publish from the serverless function to an external broker and came across an example 'Drone tracking project for Packet.com's session CES 2020' (https://github.com/packet-labs/iot link to example) github where we found some information regarding publishing however they are using the 'emitter' broker and are not running faasd any ideas on how we can get something similar for our case?

Github code example and link - https://github.com/equinix-labs/metal-iot/blob/50cb577271bc5162b56955b47a8cdfcb5e9ab711/openfaas/services/mqtt-publisher/publisher.js

const emitter = require('emitter-io')

class Publisher {
    constructor (options) {
        this.channels = options.channels
        this.client = emitter.connect({
            host: options.host,
            port: options.port,
            secure: !! options.secure
        })
        this.client.on('error', error => console.log(error.stack))
        this.client.on('connect', function () { console.log(arguments) })
        this.client.on('offline', function () { console.log('offline', arguments) })
    }

    publish (options) {
        console.log(this.channels, options)
        this.client.publish({
            channel: options.channel,
            key: this.channels[options.channel],
            message: JSON.stringify(options.message),
            me: false
        })
    }
}

module.exports = Publisher

When trying to connect to our MQTT broker Mosquitto on our RPI using local host ip address we got this error

Receieved message: {"angle": 340.58, "distance": 2210}
Traceback (most recent call last):
File "index.py", line 16, in <module>
ret = handler.handle(st)
File "/home/app/function/handler.py", line 14, in handle
client.connect(BROKER, PORT, 60)
File "/home/app/python/paho/mqtt/client.py", line 914, in connect
return self.reconnect()
File "/home/app/python/paho/mqtt/client.py", line 1044, in reconnect
sock = self._create_socket_connection()
File "/home/app/python/paho/mqtt/client.py", line 3685, in _create_socket_connection
return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
File "/usr/local/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 111] Connection refused

We tried again using the ip address of the RPI found using 'curl ifconfig.me' and we timed out as no connection was found.

Any response is extremely helpful. Thank you!

hybrid143
  • 1
  • 1
  • 1
    What exactly is the single answerable question here? Stack Overflow is not a discussion forum, there needs to be a distinct question we can try and answer – hardillb Jul 26 '23 at 06:50
  • @hardillb The single answerable question is how can we communicate with the Sunfounder RPI car through the serverless function. Ideally we tried using the library import provided by Sunfounder 'picar_4wd' but didn't work. So we are trying to use an external controller which uses another MQTT broker 'emitter' which subscribes to the publisher from the serverless function. We looked into this a bit and saw some example implementation using OpenFaas service 'mqtt-publisher' which is provided above in the post, however we are using the OpenFaas subset Faasd so we are unsure how to approach this. – hybrid143 Jul 26 '23 at 16:39
  • I'm sorry, but that question is far too broad. If you want help the best option would be to explain the error you got initially trying to connect to the broker and what IP addresses you tried, which we might be able to help you fix. Also all the information needs to be in the question, we are unlikely to spend time reading code in remote git repos. – hardillb Jul 26 '23 at 16:49
  • @hardillb Sorry about that, I just updated the questions and added details regarding what error we received. We have never had any luck connecting to our external MQTT broker 'Mosquitto' which is why we used the OpenFaas 'mqtt-connector'. If we tried connecting using local host we get the error pasted in the question, but if we used the ip address of the RPI which has the broker service on it we would get timed out. – hybrid143 Jul 27 '23 at 18:16
  • You should probably start again, with a new question, include the code, the error message, information about what is running where (network layout) and the mosquitto config file. (but most likely you have not configured mosquitto to listen on anything other than localhost and the fact that openfaas runs workers in containers) – hardillb Jul 27 '23 at 18:40

0 Answers0