Evnt_Handler.c possible error

I’m a bit of a noob at this, so please forgive me if I’m not seeing things right. It seems there’s a bit of code on line 253 in evnt_handler.c that isn’t doing what I think it would have been intended to.

while (1)
	if (tSLInformation.usEventOrDataReceived == 0)
		volatile system_tick_t now = GetSystem1MsTick();
		volatile long elapsed = now - start;
		if (elapsed < 0) { // Did we wrap
			elapsed = start + now; // yes now

		if (cc3000__event_timeout_ms && (elapsed >= cc3000__event_timeout_ms))

It seems like the intention is to break the loop if a timeout occurs. However, the elapsed time function doesn’t calculate the wrap right, and the cc3000__event_timeout_ms is declared as false from the get-go… which seems to invalidate the whole following chunk of code. I tried to find something about this in the community or git, but couldn’t find anything that seemed to address it. Is this code simply unnecessary?

Thanks for any possible help. I’m trying to figure out a way to turn off wifi if the core loses the cloud, and then simply retry every 10 minutes or so. I want to “fix” this piece of code, but I’m not sure if it’s this way for a particular reason that I don’t understand.

Thanks, JB

Hey JB, thanks for digging in and reaching out!

If you want to check the connectivity to the Spark Cloud, just call Spark.connected(), documented here. Turning off Wi-Fi should be done with WiFi.off() (docs). Calling Spark.connect() will go through all the requisite state transitions (Wi-Fi module on, connect to Wi-Fi network, connect to Spark Cloud). Thus, in sum, you could do something like:

loop() {
  isConnected = Spark.connected();
  if (!isConnected) {
    if (wasConnected) {
      wifiOffMillis = millis();
    } else if (millis() - wifiOffMillis > 600000) {
  wasConnected = isConnected;


Zachary, you are awesome. Here I am trying to reinvent the wheel. Thanks! I had simply assumed that it wasn’t even running the sparkloop because I wasn’t able to interact with the core after disconnects. It probably has to do with how I made my debouncing routines and the long wait between the loop. Thanks!


Thanks! It’s my pleasure to help! Be sure to share some pics of whatever you’re making, either here in the community or on spark.hackster.io! :dancer:

will do! It’s a big work-in-progress, so it might take me a while :smile:

1 Like