I have successfully implemented the first three Annotated Examples but have become stuck at the Local Communication example. I have no idea how to set up the simple_server.js. Would you walk me through how to do this on a Mac running the Chrome browser?
There are many ways to have a Local server so for this example, a node.js or ruby server is used.
You can do the following:
-
Install Node.js on Mac http://nodejs.org/download/
-
Once you are done, download the simple_server.js example
https://github.com/spark/local-communication-example -
On your command line node
/path/to/simple_server.js
-
Using Spark Cloud IDE, flash the following firmware:
https://github.com/spark/local-communication-example/blob/master/firmware.cpp
-
Run the following command:
curl https://api.spark.io/v1/devices/0123456789abcdef01234567/connect
-d access_token=1234123412341234123412341234123412341234
-d âargs=IPADDRESSâ
I must say this example is rather outdated and getting it doing that a little practice.
Thereâs a simpler way to test out local exampleâŚ
Or you can try this example code:
https://gist.github.com/kennethlimcp/6add4d73594c3645edaa
If you just run a simple web server locally, try a html file. Replace the IP address in the code above and call âyourhtmlname.htmlâ
<HTML>
<HEAD>
<TITLE>
Local Server Example
</TITLE>
</HEAD>
<BODY>
<P>Congrats for connecting successfully!</P>
</BODY>
</HTML>
I opted for the HTML route. I made local.html, put your above 10 lines of of html code in it and modified the client example to point to local.html. I flashed the modified example to my core but nothing happened. When I opened local.html in my browser the page only says âCongrats for connecting successfully!â What did I do wrong?
Can I see what you changed in the code?
Also, You can see the output on serial for more info of whatâs happening
This is what I flashed to the Core.
TCPClient client;
char server[] = "File://Mini09_HD/Users/boulderwalker/Local_Server/local.html"; //change to local path or ip address
void setup() {
Serial.begin(9600);
delay(3000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=sparkcore HTTP/1.1"); //Add in your own file path
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
}
else
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
void loop() {
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}
Iâve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy
Change this to your server/computer IP address
char server = "192.168.1.100";
Change this to
It depends like what is the path to your local.html file. If you go to your server eg. 192.168.100 and to access the file it's 192.168.100/xxx/yyyy/local.html. Then below you have to change to /xxx/yyy/local.html
client.println("GET /local.html HTTP/1.1"); //Add in your own file path
client.println("Host:YOUR IP ADDRESS");
Thanks, I got it to work.
I see from this thread that I am not the only one who remains mystified by the âLocal Serverâ example?
What I really want from sparkcore is a low cost WAN-connected micro-controller board - so understanding this example - and answering the question how do I find out what IP address my core has been allocated - is kinda key to that!
But I am really struggling. I think the cause of my confusion is that I donât really understand how the eco-system it is using is laid out. Itâs connecting to the core, but its connecting to a server - what server? there is no slot for me to add a server name or IP?- am I supposed to have a server set-up listening on port 9000 already? Whatâs a quick and dirty way to do that? and the âConnectâ event/function - how do I initiate that - and to what?
Could be there is a wonderfully lucid and illustrated article to go with this example, but I havenât found it. Can anyone lighten my darkness for meâŚ?
In any case, IMO, that example on the intro page could do with a lot more comments in the code and an accompanying diagram illustrating the overall scheme of things AND some example commands (as in the other code examples) showing how to use curl or other easily available utilities to make it the entry-level learning tool that it aims to be.
Alan T
Good day to you
I kinda of stuck at the local communication too. I have manage to get the nodejs server running and I have three cores connected to it. Therefore I have 3 local ip address for each of the core. I like to control the outpin pin independent of each core.
The ip of each core is
190.178.0.104
190.178.0.111
190.178.0.105
For example, I like to have
D0 of 190.178.0.104 (core 1) to be HIGH and D1 of 190.178.0.111(core 2) to be LOW. Is it possible to achieve that?
Looking forward to hear from you and thank you so much for your time
Bryan
1.) Do you mean you have the Local running?
2.) Do you have spark-cli
installed? With that, you can easily control each core via the command line tool. For what you are doing, i presume you are using the default tinker app or wrote some Spark.function() to do that?
Yeah. I have the local cloud running.
Recently got a few spark cores, wanted to make a small project for home automation at home.
Plan is to use a pi as a hub (running nodejs server) talking to 3 other spark cores locally.
Yeah. I do have the spark-cli installed, but using spark-cli it will be using the wifi to control the spark core?
Would it be possible to control it locally?
Iâm using the sample from here right now.
I would recommend using the tinker firmware instead since that example is more of TCPâŚ
Since you have a local running, you can use a user account and interact with your core via your local network.
Not sure if you have setup a local using this: https://community.spark.io/t/tutorial-local-cloud-1st-time-instructions-30-nov-14/5589
but thereâs instructions in there on how to create a âprofileâ for you to point to the local .
Once that is done, you can use Spark-cli to flash the tinker app to the cores using spark flash core_name tinker
.
With that, controlling them via Spark-cli is simply spark call digitalwrite "D0,HIGH"
for example
Just to be more complete, Spark-cli can be used to interact with any spark in general. Simply a switch of profile will do.