[SOLVED] Is 3G available or only 2G?

Mod Edit (@harrisonhjones) Solution: Use @rickkas7’s Cellular Helper library

Hi all

I have a 3G Particle and I want to know when I’m connected with 3G and when it fall back to 2G. Is there a command to display this information?

The sample code here can be used to determine what band you are connected with, along with a lot of other useful information along those lines:


Thank You for your answer but isn’t there a single command just to look up if I’m connected to GSM or 3G?

No, there is not. But if you include CellularHelper.cpp and .h in your project, all you need to do is:

CellularHelperEnvironmentResponse envResp = CellularHelper.getEnvironment(3);
bool is3G = envResp.service.isUMTS;
1 Like

How I can include these files? I worked with Arduino before and I’m not sure how I can include this files in the Particle WEB IDE.

All you need to do is click on the + icon in the upper right corner of the Particle Build (Web IDE) window. Name it CellularHelper and it will create the CellularHelper.cpp and CellularHelper.h tabs for you, and then paste in the contents of the two files from Github.


Thank you :slight_smile:

1 Like

Thanks for the help @rickkas7!

Is there also a possibility to display if I’m connected to 2G?

If you are connected and it’s not 3G you probably know how you are connected :wink:

But how I know when I’m connected?

So my idea is: When I’m not conencted: RED LED, when 2G: Green LED and when 3G: Blue LED

Make sure you are using SYSTEM_THREAD(ENABLED) or one of the non-automatic system modes, otherwise your code won’t run when not connected to the cloud.

Then if envResp.result == RESP_OK then you have a connection, so if you’re not 3G connected, you’re 2G connected.

If envResp.result is something else then you’re not connected to any tower.

1 Like

My Electron connects automatically to the cloud. So is it ok?

The default mode is AUTOMATIC without system threading, what’s I showed above in the screen shot. In the case, your code isn’t even run when not connected to the cloud, which is why I omitted the test for envResp.result, because it will always be RESP_OK when it runs (probably).

Since you want to do something when connected and something else when not connected, I’d recommend adding a SYSTEM_THREAD(ENABLED) and adding the check for envResp.result == RESP_OK. That way your code will run whether connected to the cloud or not.

But when I use the code which you sent me in this post ([SOLVED] Is 3G available or only 2G?) it doesnt matter if I’m connected to the cloud?

So first I want to test the code which you have sent me. I want to light the LED up when I’m connected to 3G. But how I can make this? I only know char and string but not bool.