first commit
This commit is contained in:
192
ATMEGA_RECEPTEUR/ATMEGA_RECEPTEUR.ino
Executable file
192
ATMEGA_RECEPTEUR/ATMEGA_RECEPTEUR.ino
Executable file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
Servo Receive Demo
|
||||
|
||||
Hacked from http://code.google.com/p/rc-switch/ by @justy
|
||||
|
||||
*/
|
||||
|
||||
#include <RCSwitch.h>
|
||||
|
||||
float temp = 0.0;
|
||||
float bar = 0.0;
|
||||
float hum = 0.0;
|
||||
float lum = 0.0;
|
||||
boolean yaduboulot = false;
|
||||
long id = 0;
|
||||
float tmp = 0;
|
||||
|
||||
#define ENABLE_Sniffer true
|
||||
|
||||
|
||||
RCSwitch mySwitch = RCSwitch(); // Create an instance of RCSwitch
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
// ********* IMPORTANT ***********
|
||||
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if (mySwitch.available()) {
|
||||
//clear;
|
||||
long value = mySwitch.getReceivedValue();
|
||||
|
||||
if (value == 0) {
|
||||
Serial.print("Unknown encoding");
|
||||
}
|
||||
else {
|
||||
|
||||
if (ENABLE_Sniffer) {
|
||||
Serial.print("Received ");
|
||||
Serial.print( value );
|
||||
Serial.print(" / ");
|
||||
Serial.print( mySwitch.getReceivedBitlength() );
|
||||
Serial.print("bit ");
|
||||
Serial.print("Protocol: ");
|
||||
Serial.println( mySwitch.getReceivedProtocol() );
|
||||
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case 111269:
|
||||
printf("Debut de message %i \n", value);
|
||||
id = 0;
|
||||
tmp = 0;
|
||||
break;
|
||||
case 1969:
|
||||
case 2069:
|
||||
case 2169:
|
||||
case 2269:
|
||||
case 2369:
|
||||
id = value;
|
||||
tmp = 0;
|
||||
break;
|
||||
case 962111:
|
||||
id = 0;
|
||||
tmp = 0;
|
||||
|
||||
break;
|
||||
default :
|
||||
tmp = value;
|
||||
printf("valeur recue = %i id=%i\n", tmp, id);
|
||||
break;
|
||||
}
|
||||
|
||||
Serial.print(" id=");
|
||||
Serial.print(id);
|
||||
|
||||
Serial.print(" value=");
|
||||
Serial.print(tmp);
|
||||
|
||||
Serial.println("");
|
||||
|
||||
char buf[7];
|
||||
char nom[200] = "curl \"http://localhost:8080/json.htm?type=command¶m=udevice&"; //idx=107&svalue=";
|
||||
|
||||
boolean envoi = false;
|
||||
if (tmp != 0) {
|
||||
if (id == 1969 && tmp < 10000 ) {
|
||||
// sprintf(buf,"%.2f", tmp / 100.0);
|
||||
toString(&buf[0], tmp / 100.0);
|
||||
strcat(nom, "idx=122&svalue=");
|
||||
temp = tmp / 100.0;
|
||||
envoi = true;
|
||||
} else if (id == 2069 && tmp < 12000 && tmp > 7000) {
|
||||
// sprintf(buf,"%.2f", tmp / 10.0);
|
||||
toString(&buf[0], tmp / 10.0);
|
||||
strcat(nom, "idx=121&svalue=");
|
||||
bar = tmp / 10.0;
|
||||
envoi = true;
|
||||
} else if (id == 2169 && tmp < 12000 && tmp > 7000) {
|
||||
// sprintf(buf,"%.2f", tmp / 10.0);
|
||||
toString(&buf[0], tmp / 10.0) ;
|
||||
strcat(nom, "idx=123&svalue=");
|
||||
envoi = true;
|
||||
} else if (id == 2269 && tmp < 1024) {
|
||||
// sprintf(buf,"%.2f", tmp);
|
||||
toString(&buf[0], tmp);
|
||||
strcat(nom, "idx=158&svalue=");
|
||||
lum = tmp;
|
||||
envoi = true;
|
||||
} else if (id == 2369 && tmp < 100 && tmp > 20) {
|
||||
// sprintf(buf,"%.2f", tmp);
|
||||
toString(&buf[0], tmp);
|
||||
//strcat(nom, "idx=158&svalue=");
|
||||
hum = tmp;
|
||||
} else if (id == 331969 && tmp > 0) {
|
||||
sprintf(buf,"%.2f;%.2f", tmp, tmp);
|
||||
strcat(nom, "idx=166&svalue=");
|
||||
strcat(nom,buf);
|
||||
strcat(nom,"\"");
|
||||
printf("%s\n",nom);
|
||||
// FIXME std::system(nom);
|
||||
envoi=false;
|
||||
}
|
||||
if (envoi) {
|
||||
strcat(nom,buf);
|
||||
strcat(nom,"\"");
|
||||
printf("%s\n",nom);
|
||||
|
||||
Serial.println(nom);
|
||||
// FIXME std::system(nom);
|
||||
}
|
||||
}
|
||||
}
|
||||
char buf[8];
|
||||
|
||||
if (/*lum > 0 &&*/ bar > 0 && temp > 0 && hum > 0) {
|
||||
// /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT;BAR;BAR_FOR
|
||||
char nom[200] = "curl \"http://localhost:8080/json.htm?type=command¶m=udevice&idx=160&svalue=";
|
||||
// Température
|
||||
// sprintf(buf,"%.2f;", temp);
|
||||
toString(&buf[0], temp);
|
||||
|
||||
strcat(nom, buf); //strcat(nom, ";");
|
||||
// Humidité
|
||||
//sprintf(buf,"%.2f;", hum);
|
||||
toString(&buf[0], hum);
|
||||
|
||||
strcat(nom, buf); //strcat(nom, ";");
|
||||
// Hum stat
|
||||
//sprintf(buf,"%.2f;", hum);
|
||||
toString(&buf[0], hum);
|
||||
|
||||
strcat(nom, buf); //strcat(nom, ";");
|
||||
// Bar
|
||||
// sprintf(buf,"%.2f;", bar);
|
||||
toString(&buf[0], bar);
|
||||
strcat(nom, buf); //strcat(nom, ";");
|
||||
// Bar Forecast
|
||||
// sprintf(buf,"%.2f", bar);
|
||||
toString(&buf[0], bar);
|
||||
strcat(nom, buf); //strcat(nom, ";");
|
||||
// Fin de chaine
|
||||
strcat(nom,"\"");
|
||||
//Commande
|
||||
printf("%s\n",nom);
|
||||
// Exec
|
||||
//FIXME std::system(nom);
|
||||
Serial.println(nom);
|
||||
lum = 0;
|
||||
hum = 0;
|
||||
bar = 0;
|
||||
temp = 0;
|
||||
}
|
||||
|
||||
// Prepare for more input
|
||||
mySwitch.resetAvailable();
|
||||
}
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
void toString(char *p, float f) {
|
||||
int i = ((int) f);
|
||||
p += sprintf(p, "%i", i);
|
||||
p += sprintf(p, ".%i", ((int) ((f - i) * 100)));
|
||||
// etc
|
||||
}
|
||||
Reference in New Issue
Block a user