Need Help Restarting 3372H Dongle via Command or API on Ubuntu Server

Momiji319

Registered Member
Joined
Aug 20, 2023
Messages
50
Reaction score
12
Hello,

I'm currently running an Ubuntu VM with Squid, and I'm having trouble restarting my Huawei 3372H dongle using a command directly from SSH. I've tried using the ifdown and ifup commands, but they don't seem to work as expected and IP remain the same.
Of course if I am going to the Huawei dashboard with the gui interface, I can obtain fresh IP.

I've also searched for APIs on GitHub, but I haven't found one that works well for my setup.
I don't have any physical access to this dongle.

I'm looking for a command or a method to restart the dongle directly from SSH for creating bash script. If anyone has experience with a reliable way to achieve this, please share your knowledge. I would greatly appreciate any guidance or suggestions.

Thank you in advance for your help!
 
I've also searched for APIs on GitHub, but I haven't found one that works well for my setup.
Why? There is a lot of python/bash scripts that cover almost every needed function: restart, data on\off, switch mode 2g/3g/4g/auto, read/send SMS/USSD etc.
 
Why? There is a lot of python/bash scripts that cover almost every needed function: restart, data on\off, switch mode 2g/3g/4g/auto, read/send SMS/USSD etc.
Ok so I use a python script and automize everything with CRON.
Find below the code:
#!/usr/bin/env python
import sys
import requests
import xmltodict
class HuaweiE3372(object):
BASE_URL = 'http://{host}'
TOKEN_URL = '/api/webserver/SesTokInfo'
SWITCH_URL = '/api/dialup/mobile-dataswitch'
session = None
def __init__(self,host='192.168.8.1'):
self.host = host
self.base_url = self.BASE_URL.format(host=host)
self.session = requests.Session()
def switch_modem(self, state='1'):
try:
# Get session and verification tokens from the modem
r = self.session.get(self.base_url + self.TOKEN_URL, timeout=3)
_dict = xmltodict.parse(r.text).get('response', None)
# Build the switch request
headers = {
'Cookie': _dict['SesInfo'],
'__RequestVerificationToken': _dict['TokInfo']
}

data = '<?xml version: "1.0" encoding="UTF-8"?><request><dataswitch>' + state + '</dataswitch></request>'
r = self.session.post(self.base_url + self.SWITCH_URL, data=data, headers=headers, timeout=3)
if r.status_code == 200:
return True
else:
return False
except Exception as ex:
print("Failed to switch modem..")
print(ex)
return False

def main():
e3372 = HuaweiE3372()
# Pass '1' for on
# Pass '0' for off
e3372.switch_modem('1')
if __name__ == "__main__":
main()
It's working pretty well.
By anychance, do you have api directory for restarting the dongle ? (no reboot, only restart)


thanks
 
What's restart?
I find the api command with dev tool network.
So:
/api/dialup/mobile-dataswitch will attribute a new IP (disable enable data, I post a python script on my previous post)
/api/device/control will restart / reboot the dongle and also attributing you a new ip but this fonction is longer than dataswitch but can be usefull.
 
here are some ideas you can try:

  1. Huawei API: Some Huawei modems support a set of APIs that allow for various controls. Although not all commands are supported on all devices, it might be worth investigating.
    • First, see if you can access the modem's API at http://192.168.8.1/api/device/reboot (or the appropriate IP for your dongle). If you can access this URL, you might be able to send a POST request to it to reboot the modem. You can use tools like curl for this.
      bashCopy code
      curl -X POST http://192.168.8.1/api/device/reboot
    • If the above method works, then you can easily include it in a bash script.
  2. USB Modeswitch: Another approach is to use the usb_modeswitch tool, which is designed to switch modes of USB devices. You might be able to simulate a reconnection of the dongle by switching its mode.
    Install it with:
    bashCopy code
    sudo apt install usb-modeswitch
    Once installed, you can try switching the mode of your dongle and then switch it back. This might make the device disconnect and reconnect, simulating a physical replug.
  3. Network Manager CLI: If you're using NetworkManager, you can control your connections using the nmcli tool.
    • First, list all your connections:
      bashCopy code
      nmcli con show
    • Then, you can disconnect and reconnect:
      bashCopy code
      nmcli con down id '<Your Connection Name>'
      nmcli con up id '<Your Connection Name>'
  4. Physically Restart the Device: If none of the software solutions work, and if your setup allows, you could use a programmable power switch that can turn off and then turn on the power supply to the dongle. This would be akin to physically unplugging and plugging the dongle back in. There are USB hubs available with individual port power switches which can be controlled programmatically.
Always remember to be careful when applying these methods, especially when automating, as repeated rapid reconnections could cause wear on the dongle or draw unnecessary attention from your ISP.
 
here are some ideas you can try:

  1. Huawei API: Some Huawei modems support a set of APIs that allow for various controls. Although not all commands are supported on all devices, it might be worth investigating.
    • First, see if you can access the modem's API at http://192.168.8.1/api/device/reboot (or the appropriate IP for your dongle). If you can access this URL, you might be able to send a POST request to it to reboot the modem. You can use tools like curl for this.
      bashCopy code
      curl -X POST http://192.168.8.1/api/device/reboot
    • If the above method works, then you can easily include it in a bash script.
  2. USB Modeswitch: Another approach is to use the usb_modeswitch tool, which is designed to switch modes of USB devices. You might be able to simulate a reconnection of the dongle by switching its mode.
    Install it with:
    bashCopy code
    sudo apt install usb-modeswitch
    Once installed, you can try switching the mode of your dongle and then switch it back. This might make the device disconnect and reconnect, simulating a physical replug.
  3. Network Manager CLI: If you're using NetworkManager, you can control your connections using the nmcli tool.
    • First, list all your connections:
      bashCopy code
      nmcli con show
    • Then, you can disconnect and reconnect:
      bashCopy code
      nmcli con down id '<Your Connection Name>'
      nmcli con up id '<Your Connection Name>'
  4. Physically Restart the Device: If none of the software solutions work, and if your setup allows, you could use a programmable power switch that can turn off and then turn on the power supply to the dongle. This would be akin to physically unplugging and plugging the dongle back in. There are USB hubs available with individual port power switches which can be controlled programmatically.
Always remember to be careful when applying these methods, especially when automating, as repeated rapid reconnections could cause wear on the dongle or draw unnecessary attention from your ISP.
Many thanks for all of this details.
This might help a lot of people.

Regarding option 3, I tried ifdown <Your Connection Name> follow by ifup <Your Connection Name> but it didn't work for rotating my mobile IP. Let's try nmcli ;)
 
Back
Top