Hi, I am new to spark. I have a core a friend gave me.
Now I have an arduino sketch which uses xbee to communicate to a raspberry (with another xbee). I want to port it to spark because of its wifi.
I want to know if it is possible to make a POST/PUT/GET/DELETE to a local server without going through the cloud. In my case, I want it to run in a local network created by my raspberry. There will not be an internet connection.
I want to develop a rest service in node.js for the raspberry and then, some spark cores will send their data to it. Is this possible? Can you point me to some tutorials or examples to do that? I just find examples about sending data to the spark cloud.
About the rest of things, I guess spark core is very similar to an arduino, isn’t it? I mean, I use eeprom storage, read sensors, relays… Same use as arduino? Watchdog?
Thank you. I already checked that example. I think now I understand how it works. In the example, where should I put my wifi parameters?
#include "application.h"
#include "HttpClient/HttpClient.h"
/**
* Declaring the variables.
*/
unsigned int nextTime = 0; // Next time to contact the server
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
// { "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Serial.begin(9600);
}
void loop() {
if (nextTime > millis()) {
return;
}
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "www.timeapi.org";
request.port = 80;
request.path = "/utc/now";
// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";
// Get request
http.get(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);
Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);
nextTime = millis() + 10000;
}
Some alternative to make a post to a spark core without having to wait a response? Something like an interruption or so? I will keep reading documentation.