Hi again, not really satisfying to day!
Extrem unstable to flash code, hoping you are on working on that!
here is a code which comes from my current arduino projects, but I can’t get it running on a spark core
so it would be helpfully to know more about limitations and when we can expect the local cloud and a none web based IDE
@zach , please take a look: If i have to rewrite some code, please tell me
int led=D7;
int errled=D0;
bool ledison=false;
String logString;
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
bool lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds
TCPClient client;
char server[] = "87.139.63.138"; // address for couchdb server (NOT using DNS)
char key[]= "xxxxxxxxxxxxxx";
void setup() {
Serial.begin(19200);
pinMode(led,OUTPUT);
digitalWrite(led,HIGH);
}
void loop() {
//debug:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(getData());
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
void sendData(String logString ){
int lng = logString.length() +1;
char logRecord[lng];
logString.toCharArray(logRecord, lng);
Serial.println(logRecord);
Serial.print("connecting...");
Serial.println( server );
//Serial.print(" port: ");
// if you get a connection, report back via serial:
if (client.connect(server, 5984)) {
Serial.println("doing the post...");
client.print("POST ");
client.print("/emon/ "); // couchdatabase
client.println("HTTP/1.0");
client.print("Authorization: ");
client.println(key);
client.println("Content-Type: application/json");
client.println("Host: home.dewaard.de"); // ??
client.print("Content-Length: ");
client.println(strlen(logRecord));
client.println();
client.println(logRecord);
client.println("User-Agent: sparkyOne");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// you didn't get a connection to the server:
Serial.println("connection failed");
Serial.println("disconnecting.");
client.stop();
}
}
String getData() {
//example only get data later ...
long tmp=125;
long prs=9806;
long alt=2123;
logString = "{\"type\":";
logString += "\"logRecord\",";
logString += "\"pressure\":";
logString += prs;
logString +=",";
logString += "\"temperature\":";
logString += tmp;
logString +=",";
logString += "\"altitude\":";
logString += alt;
logString +=",";
logString += "\"distance\":";
logString += "\"300m\"";
logString += "}";
return logString;
}