Spark Core for monitoring greenhouse. The code is written so now I need help interfacing with the core

Alright So I have this code written, mainly taken from here but I have added a few functions that it didn’t have and I need. I’m just so new to this I have no idea how to interface with the core to read this data. From what I gather unless you are on the “Cloud” you will only be able to access your core on the local network, but how do I do this? Please tell me step by step like I’m an idiot (mostly because I am when it comes to this)

Basically all I want to do is read the info from my sensors (temp, humidity, dewpoint, pH, tank levels, light intensity, sound loudness) remotely using the spark and view them from my iPhone. And I want to use the cloud so I can view all of this when I’m not connected to my wifi at home. So please tell me how I do this and I will be very grateful :smile:

Here is the code:

Code moved to pastebin ( - Harrison Jones

Hey Mike,

While it is possible that someone might come along and walk you through every required step I think that’s

  1. Unlikely, people are busy
  2. No fun. I think it’s more fun to do it myself with help then have someone do it for me
  3. Not what this forum is for

So, assuming you are ok with getting your hard dirty, here’s a gist of what you need to do.

Should be pretty simple. It looks like the code already “Publishes” data every few seconds. I personally wouldn’t do it this way. There’s 10 seconds of delay in your loop(). (actually it looks like your blinkLED function adds an entire minute delay) Ideally you’d run the loop() more often and try to eliminate hard-coded delays for cloud-connection reasons. The core only handles cloud stuff when your loop ends (and before it starts again) so putting at least 10 seconds of delay could mess things up.

So I would refactor the code in the following ways

  • Define global variables for everything you want to measure.
  • Use Spark.variable() instead of Spark.publish()
  • Comment, Comment, Comment!

To get you started I rewrote what you posted to do the first part “Define global variables…”: Hopefully that will get you started. Look at the docs for the Spark.variable() documentation, try your hand at bullets 2 and 3 and get back to me/us :slight_smile:

Actually the delay() routine also silently calls the background tasks for delays greater than 1000ms. So as long as you have long delays longer than 1 second, you'll be keeping the Cloud connection alive.

It's good practice not to rely on this and let the loop() finish as you say, but knowing this fact is useful.

You can also call SPARK_WLAN_Loop(); explicitly to process the background tasks in a hard loop if you wish.

There's a whole discussion/tutorial that needs to be worked up with these topics in mind :wink:

1 Like

You learn something new everyday! Thanks for correcting me!

1 Like

Is Spark.process() essentially a wrapper for SPARK_WLAN_Loop()? Spark.process() looks prettier to me (in code).