Van ez az oldal https://cosm.com/feeds/84398 ahová feltettem a DS18B20
hőmérséklet szenzort és olyan problémám van hogy csak akkor megy a http put push vagy minek nevezik ha nyitva van a soros monitor de még igy is leáll kb 10-15perc után nincs több update..
"Grafikon készitő oldal"
Kód: Egész kijelölése
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define APIKEY "secret" // replace your Cosm api key here
#define FEEDID secret // replace your feed ID
#define USERAGENT "Hőmérséklet (secret)" // user agent is the project name
#define ONE_WIRE_BUS 2 //digital 3 pin
#define TEMPERATURE_PRECISION 12
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
char* line= " "; // placeholder for the result of the dtostrf()-function
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // fill in your address here:
IPAddress ip(192,168,2,30); // fill in an available IP address on your network here,
EthernetClient client; // initialize the library instance:
IPAddress server(216,52,233,121); // numeric IP for api.cosm.com
//char server[] = "api.cosm.com"; // name address for Cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10000; //delay between updates to Cosm.com = 2 minutes
char* location[1] ={"sensor1,"}; // Names of your Cosm-streams
String dataString;
void setup() {
// start serial port:
Serial.begin(9600);
// Start up the sensors library
sensors.begin();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// give the ethernet module time to boot up:
delay(1000);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
Ethernet.begin(mac, ip);
}
}
void loop() {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
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)) {
sensors.requestTemperatures(); // read the Dallas Sensor:
String dataString = " "; //delete the previous dataString-Content
for (int i = 0; i < 1;){ // if you have more than three sensors change "3"
double tempC = sensors.getTempCByIndex(i); // Sensor mit index(i)
dtostrf(tempC,7,1,line); // Umwandeln des double in String. Das Ergebnis steht in line
String sensorReading = line;
dataString += location[i];
dataString += sensorReading;
dataString +="\n";
++i;
}
Serial.print(dataString);
sendData(dataString);
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
// this method makes a HTTP connection to the server:
void sendData(String thisData) {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP PUT request:
client.print("PUT /v2/feeds/");
client.print(FEEDID);
client.println(".csv HTTP/1.1");
client.println("Host: api.cosm.com");
client.print("X-ApiKey: ");
client.println(APIKEY);
client.print("User-Agent: ");
client.println(USERAGENT);
client.print("Content-Length: ");
client.println(thisData.length());
// last pieces of the HTTP PUT request:
client.println("Content-Type: text/csv");
client.println("Connection: close");
client.println();
// here's the actual content of the PUT request:
client.println(thisData);
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
// note the time that the connection was made or attempted:
lastConnectionTime = millis();
}
Arduino duemilanove 328P + W5100 Ethernet Shield SD foglalattal + DS18B20 hőmérséklet szenzor