Cellular.connecting() "undefined reference"

I can’t get Cellular.connecting(); to work. I get the error - undefined reference to "spark::NetworkClass::connecting()"
I include Particle.h but don’t see anything else included in the examples out there.

#include "Particle.h"

void DisconnectCell();

void setup() {
	SYSTEM_THREAD(ENABLED);
	SYSTEM_MODE(SEMI_AUTOMATIC) 
}

void loop() {

	DisconnectCell();
}

//DisconnectCell - turn off the cell connection properly
void DisconnectCell(){
	
	bool x = Cellular.connecting();
}

Not sure what you’re up to with that code, but I believe

	SYSTEM_THREAD(ENABLED);
	SYSTEM_MODE(SEMI_AUTOMATIC);

should be just below “Particle.h” (not in setup)

and note the need for a semi-colon after

SYSTEM_MODE(SEMI_AUTOMATIC);

1 Like

Double check wheter you are actually targeting an Electron and what system version you are targeting - you should go with most recent (currently 0.6.4 - 0.7.0-rc.6)

BTW @bpr, the macros are terminated internally, so you don’t need them, just as you don’t need a semicolon after a function’s closing brace.
But adding them isn’t wrong either.

3 Likes

I made the changes but I still get the same error.
I was striping the code down to just the error, I need a function that turns off the cell properly and was using someones example.

void DisconnectCell(){
	if(Particle.connected()){ //if connected then just turn off
		Cellular.off();
	}
	else if (Cellular.connecting()){ //if not connected but trying to wait then turn off
		Cellular.disconnect();
		waitUntil(Cellular.connecting());
		Cellular.off();
	}	
}

It is an Electron and has the name of it in the bottom right and starred in the devices.

How about this suggestion from before?

The first version to support Cellular.connecting() was 0.5.0, you probably target 0.4.8.

BTW, waitUntil() and waitFor() don’t accept the () at the end of the function name you are waiting for.
Also I doubt that after Cellular.disconnect() you will actually get Cellular.connecting() to return true so you’d wait forever for that condition to get satisfied.

The firmware was the issue, thanks. It should be waitUntil(!Cellular.connecting());

Is this good or is there a better way

void DisconnectCell(){
	if(Particle.connected()){ //if connected then just turn off
		Cellular.off();
	}
	else if (Cellular.connecting()){ //if not connected but trying to wait then turn off
		Cellular.disconnect();
		waitUntil(!Cellular.connecting());
		Cellular.off();
	}	
}

When I said

I was refering to this line

waitUntil(Cellular.connecting());

and now you have

waitUntil(!Cellular.connecting());

whith the parentheses again.
You need to drop the () and you cannot use ! in this place either.
What you can do - even when it doesn’t make sense here - is

waitUntil(Cellular.connecting);

But for your purpose you just forget about waitUntil() completely as Cellular.disconnect() and Cellular.off() are enough and as it seems you just want to cut the connection in any case, just drop the if() ... else too.
If not connected Cellular.disconnect() won’t harm and if the module is already off Cellular.off() won’t do either.

1 Like

Thanks, that makes it easier. But are you saying I don’t need to wait for until Cellular.connecting() == false? In this post from you it says I do.


"When your device is flashing green it tries to connect. So it would be adviasble to first end any of these connection attempts via Cellular.disconnect() and only then when Cellular.connecting() == false call Cellular.off(), but since the module needs some time to comply with the network demands, some blocking behaviour is to be expected."

That’s quite some time ago. The newest system versions should take care of that.
Try 0.7.0-rc.6 (most recent release condidate) - not sure about the latest release 0.6.4 as 0.7.0 should have been released a lot earlier but got pushed further and further back…

1 Like