Read a Data from the external USB device

Hello everyone,
I have OpenWrt 19.07 running on Omega2s.

I have a device which provides the JSON file as USB out.

I wanna connect this device to Omega and read the JSON file then push it to a server.

How can I access my external device through the USB port as a serial device to read the data from an external device?

I am planning to write a python script for the above job. If so where should I add this python script?

Thanks in advance.

kmod-usb-serial will provide the generic linux usbserial driver.

without knowing the device and what linux kernel module supports it impossible to say if that will cover it but it is pretty unlikely.

but you can install the usbserial driver (will be dependency of most usbserial device drivers regardless) and check the dmesg for creation of the device node (ie /dev/ttyUSB0). if nothing happens in dmesg on connect you should research for the correct kernel driver for the device by manufacturer and product id numbers (available in lsusb will look like 067b:2303). then check if opkg has the module available for. list of kernel modules at:
https://openwrt.org/packages/index/kernel-modules

edit: forgot to mention lsusb is in usbutils package

1 Like

thank you so much .

The device which i have connected to omega is stm32f401ce which has ARM Cortex-M processor in it.

hrmmm was expecting a chipset that was clearly a usb to serial.

not familiar with the stm32f401ce but seems to have a usb-otg and uart both of which could provide serial output. the uart of course is going to require an adapter to usb.

best advice i can offer is plug the device into an usb port on a linux machine (hopefully one which device is know to work with or a distribution with fairly complete driver set) and watch the dmesg for info the driver which is loaded, ie:

[Sep28 07:56] usb 2-2: new full-speed USB device number 26 using xhci_hcd
[  +0.140787] usb 2-2: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00
[  +0.000007] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  +0.000004] usb 2-2: Product: USB-Serial Controller
[  +0.000003] usb 2-2: Manufacturer: Prolific Technology Inc.
[  +0.002680] pl2303 2-2:1.0: pl2303 converter detected
[  +0.000752] usb 2-2: pl2303 converter now attached to ttyUSB0

which shows the pl2303 serial drivers (openwrt package kmod-usb-serial-pl2303) being load and attached to a serial device.

without the usb manufacturer and product ids of the device i can't provide more insight to which driver you will need.

Thank you so much for the help.

This is what I get for lsusb


Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0483:5740 STMicroelectronics Virtual COM Port
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

and for lsmod

cfg80211              222896  3 mt7603e,mt76,mac80211
compat                  5888  2 mac80211,cfg80211
crc_ccitt                960  1 ppp_async
crc16                    960  1 ext4
crc32c_generic          1344  0
crypto_hash             8640  3 ext4,jbd2,crc32c_generic
ehci_hcd               34800  1 ehci_platform
ehci_platform           4576  0
ext4                  372832  0
gpio_button_hotplug     6816  0
ip_tables              10544  4 iptable_nat,iptable_mangle,iptable_filter
ip6_tables             10304 24 ip6table_mangle,ip6table_filter
ip6t_REJECT              992  2
ip6table_filter          608  1
ip6table_mangle         1152  0
ipt_MASQUERADE           640  1
ipt_REJECT               928  2
iptable_filter           608  1
iptable_mangle           864  0
iptable_nat              672  1
jbd2                   48464  1 ext4
leds_gpio               2848  0
mac80211              441632  2 mt7603e,mt76
mbcache                 2768  1 ext4
mmc_block              23312  0
mmc_core               80896  2 mmc_block,mtk_sd
mt76                   30752  1 mt7603e
mt7603e                36864  0
mtk_sd                 14960  0
nf_conntrack           60928 13 nf_conntrack_ipv6,ipt_MASQUERADE,xt_state,xt_nat,xt_conntrack,xt_REDIRECT,xt_CT,nf_nat_masquerade_ipv4,nf_conntrack_ipv4,nf_nat_ipv4,nf_nat,nf_flow_table,nf_conntrack_rtcache
nf_conntrack_ipv4       5056 10
nf_conntrack_ipv6       5424  4
nf_conntrack_rtcache    2592  0
nf_defrag_ipv4          1056  1 nf_conntrack_ipv4
nf_defrag_ipv6          4704  1 nf_conntrack_ipv6
nf_flow_table          13008  2 xt_FLOWOFFLOAD,nf_flow_table_hw
nf_flow_table_hw        2080  1
nf_log_common           2656  2 nf_log_ipv4,nf_log_ipv6
nf_log_ipv4             3392  0
nf_log_ipv6             4096  0
nf_nat                 10096  4 xt_nat,nf_nat_redirect,nf_nat_masquerade_ipv4,nf_nat_ipv4
nf_nat_ipv4             3888  1 iptable_nat
nf_nat_masquerade_ipv4    1552  1 ipt_MASQUERADE
nf_nat_redirect         1408  1 xt_REDIRECT
nf_reject_ipv4          2080  1 ipt_REJECT
nf_reject_ipv6          2496  1 ip6t_REJECT
nls_base                4832  1 usbcore
ohci_hcd               23600  1 ohci_platform
ohci_platform           4096  0
ppp_async               6848  0
ppp_generic            22320  3 pppoe,ppp_async,pppox
pppoe                   9152  0
pppox                   1168  1 pppoe
scsi_mod               87184  2 usb_storage,sd_mod
sd_mod                 29648  0
slhc                    5088  1 ppp_generic
uhci_hcd               18800  0
usb_common              2208  1 usbcore
usb_storage            40384  0
usbcore               128368 10 usbserial,usb_storage,xhci_plat_hcd,xhci_pci,xhci_hcd,uhci_hcd,ohci_platform,ohci_hcd,ehci_platform,ehci_hcd
usbserial              17136  0
x_tables               12656 24 ipt_REJECT,ipt_MASQUERADE,xt_time,xt_tcpudp,xt_state,xt_nat,xt_multiport,xt_mark,xt_mac,xt_limit,xt_conntrack,xt_comment,xt_TCPMSS,xt_REDIRECT,xt_LOG,xt_FLOWOFFLOAD,xt_CT,iptable_mangle,iptable_filter,ip_tables,ip6table_mangle,ip6table_filter,ip6_tables,ip6t_REJECT
xhci_hcd               88496  2 xhci_plat_hcd,xhci_pci
xhci_pci                3200  0
xhci_plat_hcd           5504  0
xt_CT                   2624  0
xt_FLOWOFFLOAD          3024  0
xt_LOG                   736  0
xt_REDIRECT              672  0
xt_TCPMSS               2752  0
xt_comment               448107
xt_conntrack            2272 12
xt_limit                1152 20
xt_mac                   576  0
xt_mark                  640  0
xt_multiport            1248  0
xt_nat                  1504  0
xt_state                 672  0
xt_tcpudp               1760  8
xt_time                 1728  0

I am not able to figure out which driver to install
Please help

so this appears this appears to be the usb-otg on the STM SOC operating as a usb serial gadget.

a little out of my experience (which is limited to ether gadget) so maybe someone will jump in with some pointers. regardless some information i found is:

according to this post, it appears to be a USB CDC ACM device which should be found as /dev/ttyACM*

this openWrt driver to allow this to happen should be kmod-usb-acm

again i have no hands on experience with usb serial gadget (might give it a try with a pi0 on openWrt since i am now curious). but hope this helps and maybe someone else has some insights.

You are probably right that it is ACM. The general test of unknown USB devices is to plug into a desktop Linux and check the log to see which driver loads.

1 Like

Thanks a lot. It is ACM. I am able to read the serial data.

It was a great help.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.