Spark CLI - Calling Spark Functions

I’m using Spark CLI to call a spark function similar to:

But I wanted to know how responsive the CLI is, when I type “spark function list” into the cmd, it lists my cores and says that all are offline. When I clearly have two, breathing cyan, and each with their own Spark Functions. Is the CLI not the best way to call Spark Functions?

Follow up question, are you not able to call a Spark Function while the Core is in the middle of executing code (for example, transmitting or reading pins) ?

As always any insight is always appreciated :smile:

There is no ‘best’ way, just different ways. The CLI is only one of many options you can use to call functions.

If your code is blocking a lot, It could potentially cause issues. To be sure that everything is set up correctly, would you mind logging in here, and checking whether or not your Cores/functions/variables are properly listed? It’s a little tool I made to help with testing, using the JavaScript SDK.

I saw that thread, and have had that issue parsing from devices which encode spaces differently…

I clean them up like this in my code:

check for the presence of the "%20"

if (strstr(weatherCondition, "%20"))
      {
        strncpy(weatherCondition, cleanString(weatherCondition, "%20"), sizeof weatherCondition);
      }

then clean it…

char *cleanString(char *targetString, char *searchString)
{
  while(strstr(targetString, searchString))
  {
    char* stringChunk;
    stringChunk = strstr(targetString, searchString);
    targetString[stringChunk - targetString] = '\0';
    strncpy(myCharBuffer, targetString, sizeof myCharBuffer);
    strncat(myCharBuffer, " ", sizeof myCharBuffer);
    strncat(myCharBuffer, stringChunk + strlen(searchString), sizeof myCharBuffer);
    strncpy(targetString, myCharBuffer, sizeof myCharBuffer);
  }
  return myCharBuffer;
}

@BulldogLowell That is interesting and I’ll have to try when I get there, but my main issue is not seeing that my functions are available for calling.

@Moors7 Logging in to the link you posted showed that all my cores are “offline” when I know one is at least up and running with a spark function. So you could be absolutely right, that my code is blocking too much. But then how can I reduce this “blocking”, or is it all just random timing hoping that you don’t call your function while your core is doing something.

This happens sometimes to people who accidentally set up two different Spark accounts with two different emails (or a typo in their email).

It’s odd that they don’t show up at all. Normally when a Core connects, it also sends a Server Sent Event saying that it’s online. Just a random idea; could you try hitting the reset button on one of the Cores, and then quickly refresh that page I linked to, as soon as they’re breathing cyan? It takes a while for the Cloud to notice that they’re offline, so they should then appear to be online. Alternatively, would you mind reflashing the Tinker firmware again and checking whether that appears correctly? That shouldn’t block anything, so we can rule out potential other issues.


@bko, but then it wouldn’t show their Cores at all, since there won’t be any linked to that account?

1 Like

@Moors7 sorry i couldn’t reply earlier, but got some interesting results!

Logged in first thing, all my Cores were online which was great!

Tested the function of one of them, and after a slight wait, success! The function went through.

After which the Core went offline, my assumption why this happened was that after carrying out a function it looses connection so that your not able to spam the Core with functions.

After a little bit (<20sec) the Core back online, after refreshing your page, so I tried the same function with a different argument and the command JUST went through it seems (as I was writing this reply [maybe 1-2min?]!! That I was not expecting.

Is it possible to write an argument to an exposed function and have it kick in way after, after the Core is not blocking with user code? If the above is true, then this can work for my purposes, if it is not then how can I improve exposed function “responsiveness” ?

EDIT: Now I refreshed your page again, right after typing the above, to see if i can call the same Core again, and it went back offline. Even though it’s breathing cyan.

At least we know the Cores are functional, and there are no issues with wrong accounts. Seeing the above leads me to believe there might be things in your code causing issues.

That, I can say for sure, is not the case. I am actually able to spam my core repeatedly, without it throwing me out. Also, I don’t know of any such policies being implemented on the cloud side of things.

I think it’s time to check out your code, to see if there’s anything in there that might be blocking communications with the cloud. If you wouldn’t might posting your code here, I’m sure someone can help you out.

The above points to something in your code that is not working right.

If you can try with Tinker, the default firmware, you can prove that.

Still doing tests, had to explore some other things not related to this thread, so I apologize for not getting back.

@bko @Moors7 when you say something is wrong with my code do you mean something in my code is disconnecting me from the cloud?
Could a function that loops for >20sec disconnect me from the cloud?
Even in SYSTEM_MODE(AUTOMATIC)?
Would calling Spark.process() in the function that loops for >20sec potentially solve this?
Because other than this I don’t touch my Core’s Cloud connectivity or WiFi connectivity.

I will try this later today, and post back with results :smiley:

That could indeed be the case. I believe the Core tries to handshake every ~10 seconds. If it’s blocked while doing that, the connection may drop. You could try calling Spark.process(), that never hurts. I don’t think the system mode has a lot to do with that. I mean, even though you’re on ‘automatic breathing mode’, if I pull you underwater for 10 minutes, your ‘connection’ might drop as well :wink:
As long as we don’t see code, it’s just a guess from our side. If you could post your code here, it’d be a lot easier to debug.

2 Likes

Please don’t I like air :frowning::stuck_out_tongue:

My code is a mess, and I just don’t like posting until I’m sure I’ve explored everything, helps me learn also makes it easier on the eyes for viewers once it’s super cleaned up! I will post at the earliest convenience :smiley: But thanks for the confirmation, I’ll give it a whirl!

Exactly, and your Core likes a steady internet connection :wink:

Well, that’s what the forum is for. I haven’t seen a whole lot of code that was perfect the very first time it was posted. No use in posting something for help if it’s already working…
You can always post a snippet of where you think the problem may lie, in this case the function call. It’ll help us to help you explore things, and an extra set of eyes never hurts either :smiley: Once you’ve got everything working, and cleaned up, you can post that for others to use?
Then again, I kind of refuse to ask for help as well, so I can’t really blame you :wink:
Either way, good luck, and let us know if there’s anything we can help you with.

1 Like

I genuinely believe that did the trick, had a function loop going on for too long and calling Spark.process() seems to be doing the trick! But I can’t 100% confirm yet because now I have a different issue of perma flashing green core, regardless of factory reset or CC3000 patch update :frowning:

I’ll post again with a full confirmation as soon as I can !

1 Like