Ich habe jetzt mal eben auf die schnelle alles was ihr vermutlich nicht braucht raus geschmissen...
Jetzt ist immer noch die Möglichkeit gegeben über unterschiedliche Bibliotheken zu senden:
RC-Switch und Pilight zusätzlich zu den einfachen Funktionen des Connair.
Also gibt es folgende Möglichkeiten das Ding mit Daten zu befüllen:
Code: Alles auswählen
normal:
TXP:0,0,3,0,360,41,15,5,1,2,1,2,2,1,1,2,1,2,1,2,1,2,2,1,1,2,1,2,2,1,1,2,1,2,1,2,1,2,1,2,2,1,2,1,1,2,1,2,1,2,1,2,2,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,2,1,1,2,1,2,1,2,2,1;
RCSwitch:
send433:1,11111,00001;
Wobei dabei die Lampe mit Master-Code 11111 und Slave-Code 00001 eingeschaltet wird.
PiLight:
pilightRaw:1,c:0000010001010001000001000101000100000101000001010002;p:303,1113,8229@
Wobei die einzelne 1 den Status zum schalten darstellt.
Dies habe ich gemacht da ich Geräte hatte die mit dem Gateway nicht funktionierten und ich den Code nur mit Pilight ausgelesen bekommen hatte.
Also wenn ihr den Pin anpasst, die IP-Addressen und alles richtig verkabelt solltet ihr hiermit ein Connair selbstgebaut haben.
Die Informationen oben sind eher etwas für mrberni um es in die Webapp einzubauen
Leider kann ich weder [spoiler] nutzen noch Dateien anhängen die auf .txt oder .ino enden... deshalb jetzt so..
Code: Alles auswählen
#include <RCSwitch.h>
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // Arduino 1.0 UDP library
#include <string.h>
#include <stdlib.h>
#include <WebServer.h>
#include <RFControl.h> // Pimatic https://github.com/pimatcic/RFControl/blob/master/RFControl.h
int transmitterpin = 7; // The Pin on which your 433mhz transmitter is connected
String versionNumber = "0.0.1";
RCSwitch mySwitch = RCSwitch();
boolean urldebug = false; // true = Serielle Ausgaben, false = keine Seriellen ausgaben...
boolean tempdebug = true;
boolean udpdebug = true;
boolean servicedebug = true;
int arduinoID = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address to use
byte ip[] = { 192, 168, 2, 27 }; // Arduino's IP address
byte gw[] = { 192, 168, 2, 1 }; // Gateway's IP adress
unsigned int localPort = 49880; // Connair port
int repeatloop = 10; // Der eigentliche Code wird häufig wiederholt wenn jemand einen Handsender für ein 10 Dip gedrückt hält wird der Code ebenfalls durchgehened und auch viel öfter als nur die 10 mal gesendet, hier steht die Anzahl die aus dem TXP Befehl übernommen wurde.
const int MAX_STRING_LEN = 500; // set this to the largest string 200
char replyBuffer[300] = "HCGW:VC:dede53;MC:ConnAir;FW:1.00;IP:127.0.0.1;;";
byte parametercounter = 0;
byte arrayreader; // just to count
int packetarray[200]; // i made it 200 but actually i don´t know what the maximum lenght of the parameter txp string can be
EthernetUDP Udp;
EthernetClient client;
EthernetServer server(80);
void setup() {
/**** start the Ethernet and UDP: *******/
Ethernet.begin(mac,ip,gw);
delay(1000);
Udp.begin(localPort);
Serial.begin(9600);
Serial.flush();
delay(100);
server.begin();
mySwitch.enableTransmit(transmitterpin);
/**** Sensoren abfragen ******/
Serial.print("IP_Addresse:");
Serial.println(Ethernet.localIP());
}
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void loop() {
if(Ethernet.localIP() == ip)
{
;
}else{
resetFunc(); //call reset
}
int packetSize = Udp.parsePacket();
if(packetSize){
Serial.println("Empfangen!");
int i = 0;
char data[20][100];
char packetBuffer[MAX_STRING_LEN + 1] = ""; //buffer to hold incoming packet,
char stringBuffer[MAX_STRING_LEN + 1] = "";
Udp.read(packetBuffer, MAX_STRING_LEN);
strncpy(stringBuffer, packetBuffer, MAX_STRING_LEN);
const char* pch = strtok (stringBuffer,":");
while (pch != NULL)
{
if(strlen(pch) == 0){
break;
}
data[i][strlen(pch)];
strcpy( data[i], pch);
i++;
pch = strtok (NULL, ":");
}
if( strcmp(data[0], "send433") == 0 ){
int snapshot = millis();
if(atoi(data[1]) == 1){
mySwitch.switchOn(data[2], data[3]);
}else{
mySwitch.switchOff(data[2], data[3]);
}
Serial.println(millis() - snapshot);
Serial.println("erfolgreich gesendet!");
}
if( strcmp(data[0], "TXP") == 0 ){
char *str;
char *p;
for( str = strtok_r(packetBuffer, ",", &p); // split using comma
str; // loop while str is not null
str = strtok_r(NULL, ",", &p) // get subsequent tokens
)
{
packetarray[parametercounter] = atoi(str); // Write to the place of the Parameterarray the string as number through the atoi function
parametercounter = parametercounter + 1; // just jumping to the next element of the array could also write parametercounter ++
}
repeatloop = 0;
while (repeatloop <= packetarray[2]){
arrayreader = 6;
while (arrayreader <= 5 + (packetarray[5] * 2) ){
digitalWrite(transmitterpin, HIGH);
delayMicroseconds(packetarray[arrayreader] * packetarray [4]);
arrayreader++;
digitalWrite(transmitterpin, LOW);
delayMicroseconds(packetarray[arrayreader] * packetarray [4]);
arrayreader++;
}
repeatloop++;
}
parametercounter = 0;
arrayreader = 0; // resetting the currently read array element
Serial.println("gesendet!");
}
if( strcmp(data[0], "SEARCH HCGW") == 0 ){
Serial.println("Gateway wurde von einem Programm gefunden!");
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(replyBuffer);
Udp.endPacket();
}
if( strcmp(data[0], "pilightRaw") == 0 ){
char *str;
int i = 0;
unsigned long buckets[8] = {};
char *p;
for( str = strtok_r(data[2], ",", &p); // split using comma
str; // loop while str is not null
str = strtok_r(NULL, ",", &p) // get subsequent tokens
)
{
buckets[i] = atoi(str);
i++;
}
int snapshot2 = millis();
RFControl::sendByCompressedTimings(transmitterpin, buckets, data[1], 3);
Serial.println(millis() - snapshot2);
Serial.println("erfolgreich gesendet!");
}
}
// delay(50);
client.stop();
client.flush();
}