Huawei E173 3G (2/2): Huawei E173 3G connection setup with DHT22 Sensor Data to ThingSpeak Server, and Raspberry Pi 


This tutorial is the last of the two-part series on how to setup Huawei E173 3G with the Raspberry Pi. In this tutorial, you will learn how to set up a Huawei E173 3G connection, and with DHT22 a temperature and humidity sensor to send the data to the ThingSpeak server.



  • Raspberry Pi 3B+ (Compatible on Raspberry Pi Zero and Zero W, Raspberry Pi B+, Raspberry Pi 2 B, Raspberry Pi 3 BRaspberry Pi 3 B+, Raspberry Pi 3 A+)

  • Huawei E173 3G HSDPA USB Modem Dongle Stick With Sim Card 
  • DHT22 Temperature and Humidity Sensor



    • RPI terminal
    • Internet Browser (Example Chrome)


    Application Discussion


    The Huawei HiLink E173 Cellular Modem is an ultra-slim device with a MicroSD card slot up to 32GB. This modem is a widely used GSM/UMTS USB wireless modem. It has a connection for an external antenna that can be useful in places with low mobile phone coverage. 


    DHT22 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins are needed). It's fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds.


    ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize and analyze live data streams in the cloud. ThingSpeak provides instant visualizations of data posted by your devices to ThingSpeak.


    In this application, we will use the Huawei E173 as a USB modem to Raspberry Pi. So that you can connect to the internet if you're planning to use Raspberry Pi in a low mobile phone coverage area or area without any internet service provider, and we will send DHT22 Temperature and Humidity Sensor Data to the ThingSpeak server with Raspberry Pi.


    Setup Hardware

    Connect DHT22 and Huawei E173 to Raspberry Pi as stated in the pictures here:

    DHT22 to Raspberry Pi Connection Schematic:

    DHT22 and Huawei E173 to Raspberry Pi Actual Picture:



    Setup Software

    • To setup, Huawei E173 go to the first tutorial the link is here.

    !Link First tutorial (To be followed)!

    3G Connection Setup

    • Install USB ModeSwitch package by inputting this command below.
    $ sudo apt-get update
    $ sudo apt-get install ppp usb-modeswitch wvdial
    $ cd ~
    $ sudo git clone
    • After downloading input this command to copy the needed files (you can check it here) to the /etc/ppp/peers/ directory, this file's function is to connect and disconnect Huawei E173 3G Connection.
    $ sudo cp -r  ~/createlabz-public-raspberry-pi/usb_modem_dongle_huwaei_e173/gammu/data/etc/ppp/peers/ /etc/ppp/
    • Check where's the Huawei E173 is mounted by inputting this command.
    $ dmesg | grep ttyUSB
    • If you set up the Huawei E173 successfully then you will see this in your terminal. If not go to the first tutorial as stated above and follow it.
    [   79.750375] usb 1-1.1.2: GSM modem (1-port) converter now attached to ttyUSB0
    [   79.751900] usb 1-1.1.2: GSM modem (1-port) converter now attached to ttyUSB1
    [   79.753044] usb 1-1.1.2: GSM modem (1-port) converter now attached to ttyUSB2
    • Take note of the first line ttyUSB which is the ttyUSB0 we will be using later. If you don't see those in the terminal, try to disconnect and reconnect the device again.
    • Then input this command to change the provider configuration settings.
    $ sudo nano /etc/ppp/peers/provider
    • Now look for these lines of codes.
    # modem initialization string.
    connect "/usr/sbin/chat -v -f /etc/chatscripts/pap -T ***********"
    # Serial device to which the modem is connected.
    • Change the ******** with your sim card number. And change the ttyUSB to the corresponding ttyUSB we take note of earlier. Then to save it press the CTRL+X key, then press the key, and press ENTER key to save.
    • Now we will connect the Huawei E173 to the 3G Connection by inputting this command.
    $ sudo pppd call huawei &
    • If the response is like this, then you're Huawei E173 is connected to 3G.
    pi@raspberrypi:~ $ sudo pppd call huawei &
    [1] 2145
    pi@raspberrypi:~ $ Serial connection established.
    Using interface ppp0
    Connect: ppp0 <--> /dev/serial/by-id/usb-HUAWEI_Technology_HUAWEI_Mobile-if00-port0
    PAP authentication succeeded
    Could not determine remote IP address: defaulting to
    replacing old default route to wwan0 []
    local  IP address
    remote IP address
    primary   DNS address
    secondary DNS address
    • You can press the CTRL+C to go back to prompt, it will not disconnect. To disconnect input this command.
    $ sudo pkill pppd
    • Now you're Raspberry Pi has an internet connection using your Huawei E173.

    Setup DHT22 and ThingSpeak Server, and Send Sensor Data to the Server

    • First, we need to setup ThingSpeak Server, to do that go to this website.

    • Sign in if you have already an account then proceed, if not click Create One! text to sign up. After logging in click the button "New Channel". We will create a channel for monitoring your DHT22 Temperature and Humidity data.

    • Next, you may copy the data as indicated to fill up the fields, on the picture below, or you may use your own.


    • After you fill up all data fields, you can see 2 charts as you can see it like this. Then click the API Keys tab text, we will get the API key of your data channel.


    • Then copy the Write API Key as indicated in the red arrow below.

    • Go back to the Raspberry Pi command prompt and input this command to install the needed packages.
    $ pip3 install adafruit-circuitpython-dht
    $ sudo apt-get install libgpiod2
    • Then go to the Github library we cloned earlier, and go to the thingspeak directory by inputting this command.
    $ cd ~/createlabz-public-raspberry-pi/usb_modem_dongle_huwaei_e173/thingspeak/
    • Now we will edit the file, to put the WRITE API KEY we take note of earlier by inputting this command.
    $ sudo nano
    • Then look for this line of code and replace **************** with your WRITE API KEY.
    API_KEY = "****************"  # Put your API Key here
    • After replacing your API Key, press the CTRL+X key, then press the key, and press ENTER key to save.
    • Proceed to run the python code by inputting this command.
    $ python3
    • The successful send response will be like these.
    28.5  C 64.3  %
    200 OK
    26.6  C 50.1  %
    200 OK
    26.5  C 50.0  %
    200 OK
    26.5  C 50.0  %
    200 OK
    26.5  C 50.0  %
    200 OK
    26.5  C 50.1  %
    200 OK
    26.4  C 50.6  %
    • Now you're done! Go back to your thingspeak server DHT22 channel, and click private view tab text and you can see the Temperature and Humidity data chart updating like this.



    Now you can use your Raspberry Pi in an area without an Internet Service provider, that needed Sim Card to have an internet connection, and also for the low mobile coverage area. You can add multiple sensors if you want, that depends on your project.


    Check other tutorials in this series: Huawei E173 with Raspberry Pi

    Huawei E173 Setup, Send and Receive SMS with Raspberry Pi 



    Dht22Huawei e173Huawei e173 3g hsdpa usb modem dongle stickHuawei e173 raspberry piHuawei e173 setupInternet of thingsThingspeakUsb modem dongle stick

    Leave a comment

    All comments are moderated before being published