I’m playing my spark core with a local cloud setup on my computer. I’m having a problem to call any of my registered function through the cloud server, curl or CLI call, both have the same problem:
that When I call the func, the server will send the function call to the spark core but it seems my spark core is just not responding, and then connection lost. I tried to manually put a Spark.process() function inside the loop, but it doesn’t solve the problem. Following are logs from the server side. Anybody have this problem before?
Did you copy+paste this from your original source? Only the comment is the wrong way around (it won’t compile like that). Please edit to include your original source, and I’ll try to reproduce the problem.
That’s the original code that I copy paste, but just add this one line for Spark.process(); in order to show that I did try to have this there before, but I got it deleted later.
Still @mdma was right. Don’t comment that way you’ll forget it’s there later and experience hell when your code grows.
For your problem, I think the Core disconnect after every 20 seconds in automatic mode. However, when you have delays in while loop then that should solve the problem, since it calls Spark.process() to ping the cloud on every delay() call.
Thanks @metaculus, I've updated my application.cpp as following, but still have the same problem, it seems the core just won't call Spark.process(), or something else weird is happening...
And I also tried the original tinker firmware, that after each function call (POST), the core will lost connection and the curl/CLI command will be returned a timeout error.
I'll give it a try when I have time. But just for now why are you declaring the myFunc() at the top of your program? I saw that in the example too, but calling Spark.function() without that seemed to work just fine.
no special reason of doing that. It is a cpp file, and people do declare the func before the main(), we have no main() in application.cpp though, but just following the tinker example.
A declaration of a function without implementation is called a function prototype and is considered good practice. Normally these prototypes would be found in header files and this way anybody using a precompiled lib would know how the function signatures look.
Another reason for using them is, that not all compilers like to find calls to functions they have not "heard" of before and will complain with something like ... not declared in this scope, so you tell the compiler about the existance of this function and its signature and that an implementation will follow.
If your compiler does not complain, it might be setup to first "scan" the code completely, register all declared functions/variables and then compile in a subsequent pass.
In automatic mode you shouldn’t need to be doing any connection management. There’s no reason the core should be dropping the connection after every function call even with tinker. Hmm… Have you modified the server code, or do you have breakpoints set in it at all? Something that would interrupt it?
It’s possible it’s something blocking in the firmware, but it’s unlikely since he said he tested it against Tinker. I suspect it’s something different about the server setup, since he’s using the local cloud in this case.
Good news is I got the problem resolved, but the bad news is I’ve no idea what the problem is. So I just list what I did here. If anybody else have the same problem, try the following steps.
git clone and compile locally the Core-Firmware. no change. Flash into the core.
OBS: the core can connect with my local cloud. breathing cyan. but will lost connection after any function call, even cli cmd: spark list.
redirect the core and CLI to spark cloud:
CLI: spark keys server cloud_key.pub.pem
OBS: the core keep flashing cyan, having problem connecting with the public cloud.
put my core to Listening mode, try to setup the core again with my iphone
OBS: the iphone app was not able to find the Spark Core.
perform deep update
CLI: spark flash --usb deep_update_2014_06
OBS: core connected with public cloud. able to access core function through curl.
direct the core back to local cloud (on my raspberry pi)
OBS: it works! sign… All function call are successful, no lost connection again
re git clone the core-firmware folder, update the application.cpp with code above again, make, flash
OBS: it also works! Orz…
I kind of feel the deep update somehow did a magic work, fixed something that I messed up before? maybe