USB modem K5150 on Raspberry Pi with openHABian

Hi,
I want to connect to internet using my USB Huawei K5150 modem (with SIM card). This modem works fine with Windows 10. But with openHABian it does not connect to internet.
It looks like USB modem device is in “Mass storage mode”.
After executing “lsusb” I get:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 12d1:1f16 Huawei Technologies Co., Ltd. K5150 LTE modem (Mass Storage Mode)
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I already tried many suggested solutions from different internet forums with no success. Can somebody help with this? Thanks.
Operating System: Raspbian GNU/Linux 10 (buster)
Kernel: Linux 5.10.17-v7l+
Raspberry Pi 4

This wouldn’t be an issue with openHABian, it’s just a question of getting your modem working with Linux. There might be someone here who’s doing something similar, but if the suggestions from other forums failed then I’m doubtful this community will be of much help.

I would suggest doing a fresh Raspbian install (not the openHABian image) and try the other solutions you found. If you can get it working on Raspbian, then you’ll at least know it works. After that, you can either try again with your openHABian image or just install openHAB onto your working Raspbian system.

Good suggestion. Probably going to try it tomorrow. And maybe first with some more conventional Linux OS like Ubuntu (if it is even possible to install on R Pi ?)

You already installed the packages usb-modeswitch and usb-modeswitch-data ?

Yes

usb-modeswitch					install
usb-modeswitch-data				install

Have you tried that: Huawei K5150 - /dev/ttyUSB missing - USB_ModeSwitch

I have just tried but it looks like Linux does not recognize my USB modem as a modem. When playing with mbimcli as they do in provided threads I set APN=internet in /etc/mbim-network.conf and other values left unchanged (left them commented out). Maybe PIN missing? I have the PIN for SIM card inside modem but dont know where to enter it. Windows 10 asks me PIN and then it connects to internet no problemo. When I try mbimcli -d /dev/cdc-wdm0 -p --enter-pin=[myPIN] then I get error: couldn't open the MbimDevice: Couldn't spawn the mbim-proxy

Anyway. I just tried third OS on Raspberry with this USB modem.
First it was openHABiab. My USB modem is there recognized as mass storage device.
Second I tried Ubuntu server OS. USB modem was there recognized as LTE modem but I did not succeed to connect to internet. Tried using nmcli, mmcli and wvdial with google’s help without success. Maybe I did it wrong. I am not Linux “pro”.
Third (right now) I am trying official Raspberry OS with desktop GUI interface. But USB modem again recognized as mass storage device. This USB modem should be also accessed using web interface at 192.168.9.1 but no access. That’s weird because user guide from this modem says this web interface is for Linux users. But in Windows 10 web interface on that IP address works.

Did you also stumble upon this how-to: WiFi Access Point with 4G Uplink on Raspberry Pi

Looks promising since it seems not to be impossible to use this modem with a RasPi

You already may know this as you most probably have more articles than I have as far as I understood several articels e.g. also this one in german such devices are detected to be mass storage devices per default.
Under Windows the drivers are located on that mass storage drive after installing the drivers the device is switched to a modem. Under linux these drivers do not help that is where usb-modeswitch comes in.
Under linux the mass storage id needs to be detected and trigger a udev rule.
Did you try the udev rule from the article I linked in my previous post ?
What is the content of dmesg after this rule is setup and the device is plugged in ? Does it trigger the rule and execute the related commands ?

Thanks for the article. Indeed looks promising. But I am stuck at step #2 “USB Mode Switching”. My device still appears as “mass storage” even after reinstalling packages: libusb-1.0-0, libusb-1.0-0-dev, usb-modeswitch, usb-modeswitch-data and also after ungplgung/pluging and restarting devices.

This is why most likely I am doing some stupid mistake which hopefully might be obvious for more experienced Linux users.

Actually I stumbled across these articles before but it was too technical for me. I will revisit and try again. So far I can tell that my udev rule file does not contain reference to my modem.
I have unplugged and plugged again the modem and then copied last lines from my /var/log/syslog file. I hope it might be helpful. I note that my Raspberry is pluged also to functional LAN network with access to internet. I control R-Pi from local network via SSH. Here are the logs after replugging the modem.

Mar 13 14:54:18 raspberrypi dhcpcd[411]: wwan0: carrier lost
Mar 13 14:54:18 raspberrypi avahi-daemon[345]: Interface wwan0.IPv6 no longer relevant for mDNS.
Mar 13 14:54:18 raspberrypi avahi-daemon[345]: Leaving mDNS multicast group on interface wwan0.IPv6 with address fe80::dbc:b370:befd:7035.
Mar 13 14:54:18 raspberrypi kernel: [ 4604.525768] usb 1-1.2: USB disconnect, device number 3
Mar 13 14:54:18 raspberrypi kernel: [ 4604.526043] cdc_mbim 1-1.2:2.0 wwan0: unregister 'cdc_mbim' usb-0000:01:00.0-1.2, CDC MBIM
Mar 13 14:54:18 raspberrypi avahi-daemon[345]: Interface wwan0.IPv4 no longer relevant for mDNS.
Mar 13 14:54:18 raspberrypi avahi-daemon[345]: Leaving mDNS multicast group on interface wwan0.IPv4 with address 169.254.8.92.
Mar 13 14:54:18 raspberrypi avahi-daemon[345]: Withdrawing address record for fe80::dbc:b370:befd:7035 on wwan0.
Mar 13 14:54:18 raspberrypi avahi-daemon[345]: Withdrawing address record for 169.254.8.92 on wwan0.
Mar 13 14:54:18 raspberrypi dhcpcd[411]: wwan0: deleting address fe80::dbc:b370:befd:7035
Mar 13 14:54:18 raspberrypi dhcpcd[411]: wwan0: deleting route to 169.254.0.0/16
Mar 13 14:54:18 raspberrypi dhcpcd[411]: wwan0: removing interface
Mar 13 14:54:40 raspberrypi kernel: [ 4626.583255] usb 1-1.2: new high-speed USB device number 4 using xhci_hcd
Mar 13 14:54:40 raspberrypi kernel: [ 4626.714950] usb 1-1.2: New USB device found, idVendor=12d1, idProduct=1f16, bcdDevice= 1.02
Mar 13 14:54:40 raspberrypi kernel: [ 4626.714971] usb 1-1.2: New USB device strings: Mfr=6, Product=5, SerialNumber=8
Mar 13 14:54:40 raspberrypi kernel: [ 4626.714989] usb 1-1.2: Product: K5150
Mar 13 14:54:40 raspberrypi kernel: [ 4626.715007] usb 1-1.2: Manufacturer: Vodafone (Huawei)
Mar 13 14:54:40 raspberrypi kernel: [ 4626.715024] usb 1-1.2: SerialNumber: FFFFFFFFFFFFFFFF
Mar 13 14:54:40 raspberrypi kernel: [ 4626.717929] usb-storage 1-1.2:1.0: USB Mass Storage device detected
Mar 13 14:54:40 raspberrypi kernel: [ 4626.718792] scsi host0: usb-storage 1-1.2:1.0
Mar 13 14:54:40 raspberrypi systemd[1]: Starting USB_ModeSwitch_1-1.2:1.0...
Mar 13 14:54:41 raspberrypi usb_modeswitch: switch device 12d1:1f16 on 001/004
Mar 13 14:54:41 raspberrypi kernel: [ 4627.584726] cdc_mbim 1-1.2:2.0: setting rx_max = 16384
Mar 13 14:54:41 raspberrypi kernel: [ 4627.584923] cdc_mbim 1-1.2:2.0: setting tx_max = 16384
Mar 13 14:54:41 raspberrypi kernel: [ 4627.584931] cdc_mbim 1-1.2:2.0: NDP will be placed at end of frame for this device.
Mar 13 14:54:41 raspberrypi kernel: [ 4627.585064] cdc_mbim 1-1.2:2.0: cdc-wdm0: USB WDM device
Mar 13 14:54:41 raspberrypi kernel: [ 4627.585459] cdc_mbim 1-1.2:2.0 wwan0: register 'cdc_mbim' at usb-0000:01:00.0-1.2, CDC MBIM, ae:7d:83:25:05:8e
Mar 13 14:54:41 raspberrypi kernel: [ 4627.585810] usb-storage 1-1.2:2.2: USB Mass Storage device detected
Mar 13 14:54:41 raspberrypi kernel: [ 4627.586128] scsi host0: usb-storage 1-1.2:2.2
Mar 13 14:54:41 raspberrypi systemd-udevd[914]: Using default interface naming scheme 'v240'.
Mar 13 14:54:41 raspberrypi dhcpcd[411]: wwan0: waiting for carrier
Mar 13 14:54:41 raspberrypi dhcpcd[411]: wwan0: carrier acquired
Mar 13 14:54:41 raspberrypi kernel: [ 4627.718505] 8021q: adding VLAN 0 to HW filter on device wwan0
Mar 13 14:54:41 raspberrypi dhcpcd[411]: wwan0: IAID 83:25:05:8e
Mar 13 14:54:41 raspberrypi dhcpcd[411]: wwan0: adding address fe80::dbc:b370:befd:7035
Mar 13 14:54:41 raspberrypi avahi-daemon[345]: Joining mDNS multicast group on interface wwan0.IPv6 with address fe80::dbc:b370:befd:7035.
Mar 13 14:54:41 raspberrypi avahi-daemon[345]: New relevant interface wwan0.IPv6 for mDNS.
Mar 13 14:54:41 raspberrypi avahi-daemon[345]: Registering new address record for fe80::dbc:b370:befd:7035 on wwan0.*.
Mar 13 14:54:41 raspberrypi dhcpcd[411]: wwan0: soliciting a DHCP lease
Mar 13 14:54:42 raspberrypi dhcpcd[411]: wwan0: soliciting an IPv6 router
Mar 13 14:54:42 raspberrypi kernel: [ 4628.594147] scsi 0:0:0:0: Direct-Access     Vodafone Storage(Huawei)  2.31 PQ: 0 ANSI: 2
Mar 13 14:54:42 raspberrypi kernel: [ 4628.594948] sd 0:0:0:0: Attached scsi generic sg0 type 0
Mar 13 14:54:42 raspberrypi root: usb_modeswitch: switched to 12d1:1f16 on 001/004
Mar 13 14:54:42 raspberrypi kernel: [ 4628.645230] sd 0:0:0:0: [sda] Attached SCSI removable disk
Mar 13 14:54:42 raspberrypi systemd[1]: usb_modeswitch@1-1.2:1.0.service: Succeeded.
Mar 13 14:54:42 raspberrypi systemd[1]: Started USB_ModeSwitch_1-1.2:1.0.
Mar 13 14:54:46 raspberrypi dhcpcd[411]: wwan0: probing for an IPv4LL address
Mar 13 14:54:51 raspberrypi dhcpcd[411]: wwan0: using IPv4LL address 169.254.8.92
Mar 13 14:54:51 raspberrypi dhcpcd[411]: wwan0: adding route to 169.254.0.0/16
Mar 13 14:54:51 raspberrypi avahi-daemon[345]: Joining mDNS multicast group on interface wwan0.IPv4 with address 169.254.8.92.
Mar 13 14:54:51 raspberrypi avahi-daemon[345]: New relevant interface wwan0.IPv4 for mDNS.
Mar 13 14:54:51 raspberrypi avahi-daemon[345]: Registering new address record for 169.254.8.92 on wwan0.IPv4.
Mar 13 14:54:54 raspberrypi dhcpcd[411]: wwan0: no IPv6 Routers available

I think that does not look that bad.
As far as I understand the logs the device is dectected and USB_ModeSwitch is started successfully.
Have a look at the last two posts at Huawei K5150 - /dev/ttyUSB missing - USB_ModeSwitch

Finally got it working! Let’s my openHAB journey begin. I will probably engrave information about steps I took in the stone for future reference. I will post more detail about my solution later. Thank you by then.

2 Likes

EDIT: I was able to reduce number of steps required to get this modem working with Openhabian and Raspberry Pi. Here are the steps:

  1. sudo apt update
  2. sudo apt install libmbim-utils
  3. create file /etc/mbim-network.conf with this inside:
APN=internet
APN_USER=
APN_PASS=
APN_AUTH=
PROXY=yes
  1. [plug modem to USB port]
  2. sudo mbimcli -d /dev/cdc-wdm0 -p --enter-pin=**** [change 4 stars for your SIM PIN number]
  3. mbim-network /dev/cdc-wdm0 start

If it will not working, try old instructions bellow.

========================================

Thank you all again for the help. My instructions for Modem Huawei K5150 installation in Linux OS (tested on latest openHABian and latest Raspberry official OS).

Before you start:
There is official Linux driver from Vodafone with instructions. I learned about it after problem was solved but tried it anyway with no success. You might want to try official driver first.

Now to the issue:

These packages should be installed:
libmbim
libusb
usb-modeswitch and usb-modeswitch-data - probably it already is installed by default
cdc_mbim - “Driver for CDC MBIM Mobile Broadband modems” probably it already is part of Linux by default

Create configuration file “/etc/mbim-network.conf” with following content:

APN=internet
APN_USER=
APN_PASS=
APN_AUTH=
PROXY=yes

Edit above values if needed. In my case above configuration worked (my ISP/carrier: Orange Slovakia). Try this for more help.

Plug the modem to USB port (if it is not plugged already). Modem LED should blink green.
Then use command:

sudo mbimcli -d /dev/cdc-wdm0 -p --enter-pin=*

where * is PIN of the modem SIM card
After this you should get message about SIM unlocking. Modem LED should blink purple.

Then use command:
sudo mbim-network /dev/cdc-wdm0 start
Above command sometimes executes in few seconds and sometimes in few minutes minutes so be patient. After it is complete you should be connected to the internet via modem. Modem LED should glow purple.
Above instructions worked for me.
If you want to be connected automatically after OS startup, you probably have to follow this manual mentioned in previous posts (WiFi Access Point with 4G Uplink on Raspberry Pi). This is something I will need to do too.
PS: I had plenty of links in this post but only 2 of them are allowed for me as new user.
Good luck!

1 Like