Spark as stand alone server

I know the spark core is designed to connect to the cloud. The question is: can I set it up to be a stand alone server?, e.g. can I have a core broadcasting its existence and serving to clients? Either html files (port 80) or acting as modbus slave (port 502). Internet is not always available.
If so, how do I do it and what would be the best way to store html files? Is there an equivalent of resource in build?
Effectively I would like to move an existing Arduino+ethernet shield project into wireless connection. Next step would be to connect the core to the cloud.

@ecosta,

Hi - The core can not serve code like parsing a webpage fast enough but, there is something that is in the works. @kennethlimcp is putting in to production (with Spark Team’s Help) a MicroSD Card with FRAM non-volital memory. This would allow the core to run a webserver (TINYWebserver) and read the webpage html/php/java directly from the MicroSD card.

2 Likes

Hi @ecosta

Your existing Arduino project should move over the Spark core with few problems, just a few changes. You already have some limitations based on it being on Arduino and the limitations of a Spark core are similar but generally better.

One difference is that there is no real PROGMEM on Spark but static const arrays go into flash so RAM usage is minimized. So the PROGMEM macro just passes data on.

As @spydrop says, there are lots of possible ways to store more things in writeable memory like a microSD card or an external FRAM memory, but if you project works with Arduino, it should be OK with Spark.

3 Likes

Thanks @spydrop and @bko for the prompt reply. Yes I think that porting my project from Arduino to the Spark Core should be relatively simple. It only needs to provide few pages (stored as templates in memory) and some java libraries to the client.

However I still cannot visualize how to take control of the wifi: in Arduino I used the Ethernet class, initializing it with the mac and ip values. Then I had a dhcp class and a server class running on top. Do you know how I could code the equivalent of the initialization of the ethernet class instance in the Spark Core?

On a related note: in the documents section I could not find a reference for the available methods/classes. Is there such a document?

Thanks again for your time; greatly appreciated.

Hi @ecosta

You won’t need the Ethernet or dhcp classes or code–that is all built-in with Spark. You will need TCPServer, which is doc’ed here along with all the other methods and classes:

http://docs.spark.io/firmware/#communication-tcpserver

You should also look at

for an example.

1 Like

Hi Costa,

If you like a small webserver, it is possible without an SD card. You can use these classes to create a filesystem that can hold 16 ir more file up to 64kB in USER FLASH.
load these files down:
http://pastebin.com/WreFALxV
http://pastebin.com/CNL6TQQG

The header file contains an example in the comment area.

Next thing is to make a webserver. I have one running in alpha mode; it works, but I still need to imlement some stuff, like support for images. Maybe it’s ready next week, drop me a Q in 7 days!

If you don’t want to go this way, go SD, that works fine as well, I have good experiences with it on an Arduino, a bit slow though.
.

1 Like

Thanks @bko and @marcus.

Spark Core should be plenty to serve a small html file with SVG data built on the fly and some AJAX.

I think I didn’t express myself clearly on my original post. By using the currently in-built DHCP class I require a proxy (e.g. my router) to lease the Spark Core with an IP. However I am currently using a modified version of the DHCP Lite from Paul Kulchenko so that my Arduino leases an IP to my PC, thus I can connect directly to the Arduino with no middle man.

Now, ideally this could work in parallel with the in-built DHCP class so that the Spark Core could at the same time be leased and IP from the a proxy (if a proxy was available) effectively creating a bridge to the proxy.

So, is something like the DHCP Lite implementable in the Spark Core? Has someone already done this?

Thanks in advance.

Hi @ecosta

I am not aware of anyone doing a separate DHCP implementation. DHCP is built-in to the TI CC3000 so you would have to learn a great deal about that. Some folks have figured out a way to have a static address by letting the TI CC3000 get a DHCP address and then changing it using netapp_dhcp–search for that for details.

I think the usual approach to this kind of problem is to have your router hand out the same DHCP address to your Spark core (or Arduino) based on its MAC address. Most routers can do this.

Another approach is to have the Spark core publish its IP address to the PC so they can talk directly. You can use Spark.publish() or Spark.variable() or even a broadcast UDP packet like the startup messages broadcast by the core.

Would you like to get my webserver code, it;s only 5kb big, or so…
It serves files and filters files for PHP like variables Furthermore it supports the websocket protocol.
If so, I have to make a new github repo, it’ll be my first, so give me an excuse to dig in to github!

Marcus