REST API on Local Network?

Hi, I’m still waiting for my spark core + shields, but I was wondering, once I get the core on a local wifi network, what’s the easiest way to access the spark core locally?

My device is unlikely to have a solid net connection, so ideally I’d like to be able to ping via TCP/HTTP.

1 Like

Hi @lhl,

there are two classes to play with: TCPClient and TCPServer, so your core can be either server or client. Just take a look at the documentation at http://docs.spark.io/#/firmware/communication-tcpserver

3 Likes

@lhl , if your internet connection is not so good, you’ll probably want to build firmware locally + flash over USB via this project: https://github.com/spark/core-firmware

For local network interactions that don’t involve the internet, @dominikkv is correct, using these classes are the way to go for now. Also, at some point, we are planning to release a local cloud that will make doing this kind of thing easier/simpler.

@jgoggins great, thanks for the info. Hopefully the my spark core will arrive soon and I’ll be able to poke around (I had a battery shield, but I haven’t seen any confirmation info). My dev environment is OK on net access, but if the spark core works out, we’ll be sending these out in production attached to Cradlepoints that are pretty site-dependent as far as net connectivity goes.

@lhl right on, thanks for sharing details about your project!

My understanding of these Cradlepoints is that they guarantee access to the internet, even if local internet connection goes down. If you’ve got something like this, you shouldn’t need a local Spark cloud, right? Or do they have systems that let you run a local server as well? (If this is the case, I’d be curious what OS it runs or other OS/network-ish information)

@jgoggins The Cradlepoints create a reliable/stable local network, but the remote connection is dependent on the quality of the WWAN, which isn’t reliable depending on location and especially when there are crowds and the airwaves are saturated.

We run OS X and Linux systems on the local network that act as local servers. For the Linux machines we’re working with now we have GPIO onboard, but for the Macs we don’t and we have some finicky USB devices running that seem to have conniptions sharing the USB hub w/ the various microcontrollers I’ve tried (various Arduinos w/ Firmata, digispark, pymcu).

Basically, right now all I need is for the spark core to act as a glorified light switch - it wouldn’t make sense to require an Internet round trip (especially as that sort of latency would be terrible experience) - I think in many (most) use cases, having a local option is pretty important since it’s hard to guarantee net access in a lot of production environments, so I’m glad that’s an option (one of the reasons that the Electric Imp is a no-go for example).

(Right now I am actually using a RPi to drive some circuits and I have some Beaglebone Black’s that I’m using as well. Actually about the same price and pretty stable, but seems like a bit overkill if we can just have something dead simple/reliable.)

@lhl Right on, thanks for sharing. One of the folks here at Spark, @zachary , is working on an annotated example using TCPClient/TCPServer to illustrate how to do local networking with a core, either he or I will follow up with a link on this post when that happens in the next couple of days.

I’m planning to post that example of a TCPClient on the Core connecting to a local server in the next 24 hours. Right now @lhl, the Core doesn’t run the loop() unless it’s connected to the Cloud, so the personal cloud will be really helpful in places with poor connectivity.

The personal cloud is on our roadmap for early 2014.

Of course the firmware’s all open, and pull requests are welcome! :wink:

@lhl Just an FYI, @zachary posted an annotated example he referenced in a prior post here , in case it’s useful.

BTW, a bit offtopic, but sice I have some of you guys on the thread - should I be concerned if I haven’t gotten my KS Sparkcore yet? I saw a note that they had all gone out a while ago? I’m in Los Angeles.

You definitely shouldn’t be concerned; they shipped from Hong Kong and can take a few days to arrive.