Back

Connect USB port to Appwrite [Docker]

  • 0
  • Self Hosted
  • Functions
Ponguta_
14 Feb, 2023, 15:57

Hello, how can I achieve to connect an USB port (Serial device) to Appwrite, to use it on functions?

TL;DR
The user is asking if they can connect a USB port (serial device) to Appwrite. Unfortunately, this is currently not possible as function runtimes in Appwrite do not have access to the host's USB ports. A workaround suggested is to use an ESP-8266 enabled device like a NodeMCU to transmit the sensor data to the Appwrite database, which can then be accessed inside a function. The user is advised to open a feature request on the Appwrite GitHub repository.
joeyouss
14 Feb, 2023, 16:18

Hi there, thank you for your question, allow me a moment to look into it, can you once confirm which SDK are you using?

Ponguta_
14 Feb, 2023, 16:19

I will be using Python SDK. Thanks to you

joeyouss
14 Feb, 2023, 16:35

Can you elaborate a bit on how you plan on using Appwrite with a USB device and/or share about your usecase so we can help you better?

Ponguta_
14 Feb, 2023, 16:40

Sure.

I'm going to capture some data from gas sensors using a RS485-USB adapter. Right now I'm testing in windows, but the machine that I'm going to use is gonna have Linux.

TypeScript
import minimalmodbus
import serial

def create_sensors(usb_port, num_sensors):
    sensor_array = []
    for i in range(num_sensors):
        sensor = minimalmodbus.Instrument(usb_port, (i + 1))
        sensor.serial.baudrate = 9600
        sensor.serial.bytesize = 8
        sensor.serial.parity = serial.PARITY_NONE
        sensor.serial.stopbits = 1
        sensor.serial.timeout = 0.05
        sensor.mode = minimalmodbus.MODE_RTU
        sensor.clear_buffers_before_each_transaction = True
        sensor_array.append(sensor)
    return sensor_array

This is a part of the code. An those are the libraries

Ponguta_
14 Feb, 2023, 16:41

I mean, I can use basic linux configuration to execute scripts directly from OS, but, I want to use Appwrite for everything, so I can figure out all its potential.

Ponguta_
14 Feb, 2023, 16:41

I hope I can do this

joeyouss
14 Feb, 2023, 17:06

Unfortunately, this is currently not possible since the functions runtimes do not have access to the host's USB ports.

However never say never and we would love to discuss this over a Github issue, can you please open one issue as feature request here: https://github.com/appwrite/appwrite/issues

The workaround would be to use any esp-8266 enabled device like a node-mcu and transmit the sensor data to the appwrite database. This data can then be accessed inside the function. Please refer to this:

https://appwrite.io/docs/server/databases?sdk=python-default#databasesCreateDocument to sensor data

Ponguta_
14 Feb, 2023, 17:34

Oh, that is really sad. ESP is a nice idea, but I have to get the interface first.

Can functions runtimes access to some folder inside host's?

joeyouss
14 Feb, 2023, 17:58

Function runtimes run completely isolated from the host. This is to prevent any kind of malicious code of one user, affecting other users using the same appwrite server and also to prevent malicious code from taking down the entire server.

Ponguta_
14 Feb, 2023, 18:34

Can I do something to change that? Any workaround?

joeyouss
15 Feb, 2023, 06:12

Hey, talking of workarounds, I think CreateDocument would be the best but let me just confirm with my team if there is a better way

ireneus
15 Feb, 2023, 08:15

i think you need to create another docker container that has access enabled for serial and inside the function try to put the function container with the other serial enabled container in one instance btw search for multi-stage builds i believe it can be all done through the same function, let me know if you get there

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more