Merci pour ce petit post car c'est exactement ce que je veut faire sauf que la c'est pour une sonde ds18b20 et j'aimerais aussi ajouter des interrupteurs et pouvoir actionner actionner des relais ... etc
Donc ton code me semblais une bonne base cela dit en passant je suis vraiment noob de chez noob en code et du coup je galère pas mal et la j'ai une erreur a la con car j'essaye forcement de rajouter des truc et ca plante
l'erreur c'est ca :
sketch_sep11a.ino: In function ‘void httpRequest(String)’:
sketch_sep11a.ino:165:18: error: ‘celsius’ was not declared in this scope
et pour le code :
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = { 192,168,0, 177 };
boolean received = false;
boolean get2 = false;
EthernetClient client;
OneWire ds(7); // on pin 7 (a 4.7K resistor is necessary)
char server[] = "192.168.0.10";
unsigned long lastConnectionTime = 0;
boolean lastConnected = false;
const unsigned long postingInterval = 30000; // delay between updates, in milliseconds de base 5000
// declaration capteur
int trig = 6;
int echo = 7;
long lecture_echo;
long cm;
int trig2 = 8;
int echo2 = 9;
long lecture_echo2;
long cm2;
//
void setup() {
// capteur
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
pinMode(echo, INPUT);
pinMode(trig2, OUTPUT);
digitalWrite(trig2, LOW);
pinMode(echo2, INPUT);
//
randomSeed(analogRead(0));
Serial.begin(9600);
delay(1000);
Ethernet.begin(mac);
analogReference(INTERNAL); //Permet de fixer la temperature de refernce à 1,1 volt
}
void loop() {
//capteur ds18b20
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(10*1000); //10 secondes de pause
return;
}
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
ds.reset();
ds.select(addr);
ds.write(0x44, 1);
delay(1000); // maybe 750ms is enough, maybe not
present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
//capteur
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
lecture_echo = pulseIn(echo, HIGH);
cm = lecture_echo / 58;
Serial.print("Distancem : ");
Serial.println(cm);
delay(1000);
digitalWrite(trig2, HIGH);
delayMicroseconds(10);
digitalWrite(trig2, LOW);
lecture_echo2 = pulseIn(echo2, HIGH);
cm2 = lecture_echo2 / 58;
Serial.print("Distancem2 : ");
Serial.println(cm2);
delay(1000);
// fin capteur
while (client.available()) {
char c = client.read();
Serial.print(c);
received = true;
}
if(received)
{
client.stop();
received = false;
}
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
if(!client.connected() && (millis() - lastConnectionTime > postingInterval) && !get2) {
int i = random(10000);
String reading = "1:" + String(i);
httpRequest(reading);
}
if(!client.connected() && (millis() - lastConnectionTime > postingInterval) && get2) {
int i = random(10000);
String reading = "1:" + String(i);
httpRequest2(reading);
}
lastConnected = client.connected();
lastConnected = client.connected();
}
void httpRequest(String val) {
if (client.connect(server, 8080)) {
Serial.println("connecting...");
Serial.println("Sending " + val);
client.print("GET /json.htm?type=command¶m=udevice&idx=175&nvalue=0&svalue=");
client.print(celsius);
client.println(" HTTP/1.1");
client.println("Host: *HOST*");
client.println("Connection: keep-open");
client.println();
lastConnectionTime = millis();
get2 = true;
}
else {
Serial.println("connection failed");
Serial.println("disconnecting.");
client.stop();
}
}
void httpRequest2(String val) {
if (client.connect(server, 8080)) {
Serial.println("connecting...");
Serial.println("Sending " + val);
client.print("GET /json.htm?type=command¶m=udevice&idx=320&nvalue=0&svalue=");
client.print(cm2);
client.println(" HTTP/1.1");
client.println("Host: *HOST*");
client.println("Connection: keep-open");
client.println();
lastConnectionTime = millis();
get2 = false;
}
else {
Serial.println("connection failed");
Serial.println("disconnecting.");
client.stop();
get2 = false; // debug
}
}
Voila si une ame charitable pourrais me dire pourquoi mon celsius est hors perimetre par ce que moi je capte pas :s
Merci à tous
vin100