Connect Your Raspberry Pi To Cellular Via Hologram’s Network

/ Written By Reuben Balik

NOTE: An updated version of this tutorial is available in our documentation.

Many people prefer to build their cellular project off of the familiar Raspberry Pi rather than the Konekt Dash. Don’t worry—you’re not hurting our feelings. As you may have noticed, one of the rewards in our Kickstarter Campaign is a Raspberry Pi kit that includes the Raspberry Pi 2 Model B along with everything you need to get up and running on the Konekt network.

The following tutorial should help you take a Raspberry Pi from unboxing to Internet in less than an hour.

rpi - connecting raspberry pi to cellular

Ingredients for connecting your Raspberry Pi to cellular

Items with a * are included in the Kickstarter Raspberry Pi kit.

  • Raspberry Pi 2 Model B*
  • 8GB or greater MicroSD card*
  • 2.4A USB power supply and cable*
  • Huawei e303 3G USB Dongle*
  • Monitor with HDMI input
  • USB Mouse and Keyboard

Instructions for connecting your Raspberry Pi to cellular

First, a few caveats:

  • This is a quick and dirty method that will get you on the network as soon as possible.
  • It requires the use of the GUI (which means monitor, keyboard, and mouse) and isn’t scriptable.
  • It requires you to download a package via the Ethernet port on the Pi.

Now that you’ve read the fine print, let’s get started.

  1. Download and install the Raspbian image to your micro SD card following the instructions on the Raspberry Pi site.
  2. Insert the Konekt SIM card into the USB Dongle. The cover slides off easily and there’s a slot on top for the SIM. It’ll look like this when you have it installed correctly:
    e303withsim - connecting raspberry pi to cellular
  3. Put the microsd card into the slot on the back of the Pi.
  4. Plug the monitor, keyboard, mouse, Ethernet cable, and USB dongle into the Pi and then power it on.
  5. Since this is a new image, you’ll be greeted with the RPi configuration utility. It’s up to you what you want to change in here. I always go through the internationalization settings and switch from the British keyboard layout to the US layout.
  6. Once you’re finished there, you’ll be sent to a command prompt. Let’s start up the GUI by typing startx
  7. Open up a terminal window and type
    sudo apt-get update
    sudo apt-get install usb-modeswitch
  8. Answer yes to any questions that come up. This will install the utility needed to switch the USB dongle from storage mode into modem mode.
  9. Reboot the Raspberry Pi and run startx again
  10. Open a terminal window and type ifconfig. You should see an entry for eth1 similar to the image below. This is the interface for the USB modem.
    - connecting raspberry pi to cellular
  11. Type sudo dhclient eth1. This will assign it an IP address.
  12. Open up the web browser and go to 192.168.1.1
  13. You should now be in the USB modem configuration web application. If you are asked for a PIN, type in the PIN written on the front of the SIM card. (The larger piece of the card from which you punched out the micro-SIM.)
  14. Go to Settings and Profile Management and create a new profile called “Konekt” with the apn “apn.konekt.io” It should look like this:
    3-apn - connecting raspberry pi to cellular
  15. Go to Mobile Connection, switch to “Auto” mode and turn on the setting to allow for roaming.
  16. Click Home. Hopefully all went well and you are now connected to a cellular network.
  17. Let’s test it out. Unplug the ethernet cable from the Pi, open up a new tab in the web browser and try to go to http://hologram.io/test.html
  18. If it doesn’t work, you probably need to add a new default route. In the terminal window, type
    sudo route add default gw 192.168.1.1 eth1

You should now be able to connect to the internet with the 3G USB Modem and the Konekt network!

Automation

Once you have this working, you probably don’t want to have to go through this process each time. We already configured the modem to connect automatically when it is powered on, now we just want Linux to setup the interface each time.

To get that to happen, edit the file in /etc/network/interfaces (sudo leafpad /etc/network/interfaces) and add these two lines after the line that says iface eth0 inet dhcp:

allow-hotplug eth1
iface eth1 inet dhcp

Once you do this, you should get a working cellular internet connection every time you power up which means that you’ll be able to use the Pi unconnected from a monitor and keyboard.

I hope this was helpful. We’ll keep putting out more tutorials and documentation to walk you through every step of building your IoT device using Konekt technology.

I’m eager to hear your feedback. If you have any questions or comments, leave them below or on our community forum.

Also, you can get the latest update on how our hardware is coming along right here, and of course, make sure to check out the Konekt Dash Kickstarter for more info on our Cellular Dev Kit if you haven’t already!

Update 4/22/2015: Changed the test URL from google.com to hologram.io/test.html. This new page uses barely any data so you don’t have to worry about using half your data allotment loading the Google homepage. Alternatively you could just ping google.com or konekt.io as that will use very little data.

  • condew

    Thanks for the detailed procedures.

    I note the use of a 2.4A power supply. Does the E303 draw so much power that a beefy supply like that is required?. Certainly power supply issues are common with a Raspberry Pi used with high-current USB peripherals, and Cellular cards for Arduino often draw peaks around 2A. On the other hand, you did not activate the option for higher current USB on the Pi 2B by adding “max_usp_current=1” to /boot/config.txt.

    When I get the equipment to try this, I’ll probably choose a test URL that is more miserly than google.com; the picture on their homepage today is 300K, about a third of my 1 meg/month used up on one initial test!

    • Reuben Balik

      Keep in mind that this was running with a monitor hooked up and input devices. If you’re running headless you could probably get away with much less.

      I tested with a 1A supply and was getting constant undervolt warnings and the 2.4A was the only other one I had available. I’m hoping to hook up a watt-meter in the near future to get a more accurate reading.
      The E303 specs say it can pull 500mA. It looks like the Pi2B provides 600mA on USB by default so no need to bump up the current limiter for this, but that’s a really good tip that I didn’t know about.
      If you’re on an older Pi, then you might need to use a powered USB hub because I think the original models could only do 100mA on a port.
      Good point about the test site. We should have some recs for people that don’t use a ton of data. You can always ping google.com instead of bringing it up in a web browser and it’ll keep your usage really low.

    • Reuben Balik

      We added a page on our server at http://konekt.wpengine.com/test.html so that people can have a really small page to request instead of pulling the Google homepage or some other page that would take a bite of their data plan. I’ve updated the post above. Thanks for the suggestion.

      • condew

        On my Ethernet-connected Pi that page takes 1544 Tx + 2190 Rx = 3744 bytes.
        As your page is a mere 79 bytes, that makes the overhead for just requesting the page and getting it back 3665 bytes. One could probably trim that a bit by using an IP address to avoid the dns lookup, and maybe there is some unnecessary stuff in the http header created by my browser and your server. Without any tuning, and depending how the network computes usage, I could make 267 such exchanges on a 1 meg/1 month plan, very reasonable for test, and certainly usable for many tasks. This does demonstrate why your cloud services could be valuable.

        Edit: I copied your file to my Raspberry Pi webserver and used the IP address to view it. It took 1022 Tx + 935 Rx = 1957 bytes; permitting 510/month.

        • condew

          Further investigation using a Konekt sim and cellular connection, the Konekt sim management site tells me fetching the test.html page costs about 2300 bytes.

          Using a domain or using an IP address used about the same amount of data, so there is no significant advantage in using an IP address instead of a domain; the cellular network seems to do the domain lookup for free.

          Simulating the same request using firefox’s web developer tools, there seems to be about 330 bytes of header on both the request and the response. Even with this overhead I can only account for about 1/3 of the actual data usage, so there is still more to be learned.

          • Reuben Balik

            Perhaps there is a minimum size due to TCP/IP headers and framing overhead
            Edit: I guess that’s on the order of 20-40 bytes so maybe not…

          • condew

            I think extra usage is due to the DNS lookup, but I tried the request using an IP address and your sim management site added 4090 bytes to my usage.

            The management site only updates the byte count about twice a day — fine for billing, but a bit coarse for this sort of investigation. I might be tripped up by some caching in the Pi, too. The great thing about the USB modem solution offered here is that the Pi is just another Linux computer connected to the internet, so all the normal Linux stuff should work without any additional programming effort. But that complicates figuring out the true cost of a file request because while I wait for the management site to update the byte count anything in the Pi could wake up and make some minor request on the network that would not normally be noticed. So I get counter-intuitive results like a request by domain costing 2355 bytes and a request by IP costing 4090. I’d expect using the IP address to reduce the bytes used by the 1700 to 2600 byte exchange with the name server, but that’s not what I observed.

          • Reuben Balik

            Our usage data updates every 15 minutes. I should have mentioned this earlier, but you can see every single usage event with our API. Try going to this URL:
            https://dashboard.konekt.io/api/1/usage

  • Reuben Balik

    Keep in mind that this was running with a monitor hooked up and input devices. If you’re running headless you could probably get away with much less.

    I tested with a 1A supply and was getting constant undervolt warnings and the 2.4A was the only other one I had available. I’m hoping to hook up a watt-meter in the near future to get a more accurate reading.
    The E303 specs say it can pull 500mA. It looks like the Pi2B provides 600mA on USB by default so no need to bump up the current limiter for this, but that’s a really good tip that I didn’t know about.
    If you’re on an older Pi, then you might need to use a powered USB hub because I think the original models could only do 100mA on a port.
    Good point about the test site. We should have some recs for people that don’t use a ton of data. You can always ping google.com instead of bringing it up in a web browser and it’ll keep your usage really low.

  • condew

    Are the 2.4A power supply and SD card in the Kickstarter Raspberry Pi Kit? The Kickstarter page doesn’t mention them.

    • Reuben Balik

      The MicroSD card will be in the kit as will a power supply. I can’t guarantee that it will be 2.4A. We’re testing a 2A and if that’s good enough then we’ll probably just go with that. I can guarantee that it will be powerful enough to be able to send data over the e303.

  • condew

    I picked up an unlocked E303 on ebay. I can connect to the internet with it using my laptop, but on the Pi it shows up in ifconfig as “wwan0” not “eth1”. “sudo dhclient wwan0” runs for a long time and ends without assigning an IP address, so I can’t continue any further. Any clues on how to proceed? Does the E303 in your Raspberry Pi kit have special firmware?

    • Reuben Balik

      What OS are you running? You may need a more recent version of Raspbian.
      Also, does your E303 have the Hi-link feature? I think that is what is needed to get the configurable webapp.

      • Reuben Balik

        P.S. There will be a Hi-Link logo on the back if it supports it. This should definitely be doable without Hi-Link, though. We’ll try to get a tutorial written for how to do it with those modems.

        • condew

          Only logo on the back is Huawei, so I probably don’t have the “Hi-Link” feature. On the PC I set the profile with “Turbonett Movil”. I see an option there to use the E303 in “RAS” or “NDIS” mode. A little research says “RAS” responds to AT commands while “NDIS” acts like an Ethernet controller. I’d expect “RAS” to show up as a serial port, and “NDIS” might show up as eth1; but the setting apparently doesn’t get saved on the device. I’ll see how your device works when the kickstarter kit arrives.

          Messing with a SIM900, I see it stores contexts on the sim, maybe when I move the sim back to the E303 it will see the context I created with the SIM900.

        • condew

          I picked up an E3131 on ebay, and true to the description it has HiLink. However, I don’t think the 3131 was made for U.S. markets; it claims to be 3G, but will only connect at 2G. Set it to connect to “3G only” and it won’t connect at all.

          The good news is that using your procedures this modem will retrieve your web page on a Raspberry Pi! I want to learn more about cellular modems and lower power solutions, but this works so slick on a Pi that it will be my go-to solution.

          So yes, HiLink is the missing piece required to connect on a Pi, but no, this modem does not have a HiLink logo. But hey, it’s ebay; it may have been hacked. I think HiLink may only be a firmware update.

          I am looking forward to getting some E303s from your store so I can connect a Pi at 3G speeds; and I won’t be wasting any more money trying modems from ebay.

          • Reuben Balik

            Yeah, so I guess I was wrong about that and it looks like you can’t just go by the logo. All of the modems in our store have HiLink, but they don’t have the logo on the modem itself. Apparently the only way to tell for sure for the e303 is the specific model number that you see next to the SIM card slot. (And now I can’t find the website that said which models had it, but the ones in our store are E303s-65.)
            On a related note, we’re working on a tutorial on how to get these modems into Serial/PPP mode using AT commands so they can be used on a Linux system without the HiLink feature. It’s a little more complicated but will help people who have older models or want more direct access to the config from their app.

          • condew

            Using a connect sim and E303 that arrived today, I activated the sim, but the portal says it expires today, 6/3, not 7/3 as I would have expected.

            On the Raspberry Pi, apparently the only network the E303 can find is a T-Mobile 2G. I created a konect profile with apn “apn.konekt.io”, but when I try to connect it says “Connection failed. The profile is invalid.”, and tells me to contact my service provider.

          • Reuben Balik

            About not being able to connect, give it a bit more time. It sometimes takes a couple hours for the activation to propagate.
            About the expiration date, that’s a bug and we’ll get that fixed. Don’t worry, it won’t result in the SIM being suspended or anything.
            And finally about the 2G connection, this is super frustrating for us as well because some E303s get 3G in the US and some don’t. It seems to be dependent on the firmware as the hardware version is identical. I just created a thread on our community page to discuss this and we’re trying to track down a firmware update that will enable those frequencies.

  • condew

    Using a Konekt sim and modem, according to the Konekt management website an idle Raspberry Pi seemed to be consuming about 50k/day. I turned off ntp with “sudo sevice ntp stop” and the data consumed by the idle Raspberry Pi dropped to zero.

    • Reuben Balik

      That’s a really good tip. Thanks.

  • John Tierney

    Thanks for the tutorial. Everything seems to work great, except after the modem has been idle for a while it disconnects, and the only way I can seem to get it to reconnect is to unplug and replug. Can’t seem to turn up any good solutions on Google. Any Suggestions? Using a raspberry pi 2 and one of your new e303 usb sticks.

    • Reuben Balik

      Hmm, I haven’t run into that, but I haven’t done much long term testing yet. I can mess around with it and see if I can reproduce.
      What happens if you try to bring the interface down and up?

      • John Tierney

        Yep, doesn’t appear to be a common problem. Seems to disconnect somewhere in the 2-8hr range, haven’t tried to figure out exactly when. If I try “ifup eth1” I get “already configured” if I go down then up, the commands give no error, but the modem doesn’t connect.

    • Reuben Balik

      Oh, one more thing: there’s a setting in the web interface to automatically reconnect when roaming. Make sure that’s checked.

      • John Tierney

        Confirmed that auto connect even when roaming was checked. Just tried setting a Max. idle time (on the same screen) We’ll see if that changes anything.

  • Sujani Koya
  • Pingback: Google()

  • Christopher Hammond

    All works fine except when I turn the connection off for some extended time and then turn it back on using ifconfig. I can’t connect to anything until I restart the PI. From a programming language call, I get a message that says “lame referral”, so maybe I need to re-init a route or something?

    • Christopher Hammond

      Note also that roaming is on and max idle is set to zero. Not sure if that is affecting anything.

    • Christopher Hammond

      Tried updating the max idle to the largest possible number. After a couple of hours, restarted the eth1 interface and it again cannot connect to anything. Ping of 8.8.8.8 says it cannot connect. The only way I seem to be able to consistently get the network back is to reboot the PI

    • Christopher Hammond

      I turned on logging for useb_modeswitch and see this in the /var/log

      DefaultVendor= 0x12d1
      DefaultProduct= 0x14fe
      TargetVendor= 0x12d1
      TargetProductList=”1506,150f,151d”
      HuaweiNewMode=1
      NeedResponse=0
      Success check enabled, max. wait time 20 seconds
      System integration mode enabled

      Use given bus/device number: 001/011 …
      Look for default devices …
      bus/device number matched
      found USB ID 12d1:14fe
      vendor ID matched
      product ID matched
      Found devices in default mode (1)
      Use interface number 0
      Use endpoints 0x01 (out) and 0x81 (in)

      USB description data (for identification)
      ————————-
      Manufacturer: HUAWEI
      Product: HUAWEI Mobile
      Serial No.: not provided
      ————————-
      Using standard Huawei switching message
      Looking for active driver …
      OK, driver detached
      Set up interface 0
      Use endpoint 0x01 for message sending …
      Trying to send message 1 to endpoint 0x01 …
      OK, message successfully sent
      Reset response endpoint 0x81
      Reset message endpoint 0x01
      Device is gone, skip any further commands
      Bus/dev search active, refer success check to wrapper. Bye!

  • Christopher Hammond

    The E303 dongle that i bought a while ago seems to work fine. We bought a new one, but it seems that the PI only recognizes it as media and not as a network interface. We can browse to /media and see it as well as the files that it contains. When we pull the dongle out, it complains that a disk was removed. Also, ifconfig does not show eth1 as ever appearing with that dongle. Is it a problem with the software on the dongle?

    • Christopher Hammond

      I note that the one that works is model E303S-65 and the one that is showing up as media is model E303S-3

      • Reuben Balik

        It probably doesn’t have the HiLink feature which is what provides the web interface to configure the network interface. Not all models of the E303 are the same. You may want to take this discussion to our forum at community.hologram.io as this blog post is pretty old and not many people are monitoring the comments on here. You might also be able to use this modem model in PPP mode by following our docs at https://hologram.io/docs/guide/connect/usb-modem

  • PiAnywhere

    Hey all,

    This powerful HAT gives you 4G, 3G or GSM mobile data, GPS, Bluetooth and a rechargeable power source for your Raspberry Pi.

    Check us out… http://www.pianywhere.com