Homeduino IR - Empfänger homeduino_ir

Einrichtung, Nutzung und Hilfe zu RaspberryMatic (OCCU auf Raspberry Pi)

Moderatoren: jmaus, Co-Administratoren

Antworten
komoloko
Beiträge: 14
Registriert: 22.12.2014, 20:56

Homeduino IR - Empfänger homeduino_ir

Beitrag von komoloko » 05.12.2018, 06:48

Hallo,

da wir in ein neues Haus gezogen sind, habe ich auch eine neue Homematic-Umgebung. Bisher habe ich die CCU2 genutzt und auch einen Homeduino als Umsetzer Infrarot-Homematic genutzt.
Jetzt benutze ich einen Raspberry und es funktioniert nicht mehr. IP Adressen im Sketch habe ich angepasst, kann auch die IR-Signale per Browser aufrufen. Allerdings wird die Systemvariable Homeduino_ir nicht mehr in die Homematic geschoben.
Gibt es ein generelles Problem mit dem Raspberry oder sollte das funktionieren? Und kann es sein dass ich Ports freigeben muss damit die Variable Homeduino_ir übertragen wird?

Vielen Dank im Voraus!

Xel66
Beiträge: 14085
Registriert: 08.05.2013, 23:33
System: Alternative CCU (auf Basis OCCU)
Wohnort: Nordwürttemberg
Hat sich bedankt: 580 Mal
Danksagung erhalten: 1492 Mal

Re: Homeduino IR - Empfänger homeduino_ir

Beitrag von Xel66 » 05.12.2018, 10:39

Die neue Firmware hat eine verbesserte Firewall. Externe Zugriffe müssen unter den Sicherheiteinstellungen speziell freigeschaltet werden.

Gruß Xel66
-------------------------------------------------------------------------------------------
524 Kanäle in 146 Geräten und 267 CUxD-Kanäle in 34 CUxD-Geräten:
343 Programme, 334 Systemvariablen und 183 Direktverknüpfungen,
RaspberryMatic Version: 3.65.11.20221005 + Testsystem: CCU2 2.61.7
-------------------------------------------------------------------------------------------
Einsteigerthread, Programmlogik-Thread, WebUI-Handbuch

komoloko
Beiträge: 14
Registriert: 22.12.2014, 20:56

Re: Homeduino IR - Empfänger homeduino_ir

Beitrag von komoloko » 05.12.2018, 11:20

Ah okay danke!
Also der Port 80, ist das korrekt? Schaue mit das an wenn ich daheim bin.
Oder kann mir jemand kurz eine Beschreibung geben wie ich diese Freigabe einrichten muss?

komoloko
Beiträge: 14
Registriert: 22.12.2014, 20:56

Re: Homeduino IR - Empfänger homeduino_ir

Beitrag von komoloko » 05.12.2018, 21:34

Ich habe jetzt mal alles in den Sicherheitseinstellungen deaktiviert, es funktioniert aber immer noch nicht. Eventuell habe ich einen Fehler in der Arduino-Programmierung? Das Signal will einfach nicht in der Raspberrymatic landen.

Code: Alles auswählen

//Versionsbezeichner "homeduino_21.ino / Stand: 2014.09.13"; 
// fuer Arduino Mega 2560 mit Arduino 1.5.6r2
//Verfasser: Eugen Stall
// diese Software erlaubt die Steuerung der Pinfunktionen mit einfachen Browserbefehlen
//verwendete Quellen fuer libraires und Programme siehe Beschreibung und Erläuterungen im Quelltext
//die aktuellste Version ist immer hier:
//http://www.stall.biz/?project=homeduino-der-universelle-lanwlan-arduino-fur-die-hausautomation
 
#include <Ethernet.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <RCSwitch.h>
#include <IRremote.h>
#include <Time.h>
#include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
#include <SFE_BMP180.h>
#include <EEPROM.h>
 
String ver = "homeduino_20.ino / Stand: 2014.09.13"; // Versionsbezeichner
 
////////////////////////////////////////////////////////////////////////
//Netzwerk-Konfiguration muss individuell hier eingegeben werden
byte ip[] = { 192, 168, 188, 58 }; //das ist die IP des Arduino //<<user-eingabe<<
byte gateway[] = { 192, 168, 188, 1 }; //das ist die IP des Routers //<<user-eingabe<<
byte subnet[] = { 255, 255, 255, 0 }; //wie immer //<<user-eingabe<<
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //nur 1x im Netz //<<user-eingabe<<
EthernetServer server(80); //server port 80
 
byte ccu[] = { 192, 168, 188, 79 }; //das ist die IP der CCU //<<user-eingabe<< 
EthernetClient client;
 
//Variablendefinitionen:
boolean reading = false;
boolean valid_command = false;
String command = String(200); // string for fetching data from address
String befehl = String(20);
String parameter = String(20);
String header = String(20);
 
String ip_adresse = String(15);
int param;
long param1;
int param2;
int param3;
String message = String(60);
boolean test = false;
unsigned long currentMillis;
unsigned long time;
unsigned long last_get;
unsigned long akt_zeit;
unsigned long next_update;
 
float tempNTC;
float B_wert = 3950; //aus dem Datenblatt des NTC //<<user-eingabe<<
float Tn = 298.15; //25°Celsius in °Kelvin 
float Rv = 10000; //Vorwiderstand
float Rn = 10000; //NTC-Widerstand bei 25°C
float Rt ; 
 
int data[10];
int datum;
 
int PWM;
 
int onewire_pin;
float temp_tur;
 
int rf_key;
String rfkey;
 
RCSwitch mySwitch = RCSwitch();
 
boolean Ax_alt [6];
boolean ir_enable = 1; // 1 wenn ein ir-receiver an pin D2 verwendet wird
boolean rf_enable = 0; // 1 wenn ein rf-receiver an pin D3 verwendet wird
int schaltschwelle_high[]= {1023,1023,1023,510,510,510}; //schaltschwelle der Analogeingänge , //<<user-eingabe<<
 //wenn analogwert grösser, dann high
int schaltschwelle_low[]= {0,0,0,100,100,100}; //schaltschwelle der Analogeingänge , //<<user-eingabe<<
 //wenn analogwert kleiner, dann low 
 
int RECV_PIN = 2; 
IRrecv irrecv(RECV_PIN); //2 ist der IR- Empfangspin D2
IRsend irsend; // sendepin ist beim MEGA2650  D9!
decode_results results;
String code_type;
int ir_key;
String irkey;
int decod;
unsigned long val;
int bitss;
unsigned int address;
int rawl; 
String hersteller;
// Storage for the recorded code
int codeType = -1; // The type of code
unsigned long codeValue; // The code value if not raw
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
int count;
int STATUS_PIN = 13;
int addr;
 
SFE_BMP180 pressure;
int altitude = 229.0; // hoehe des barometer-standortes
boolean lcd_text_anzeigen; 
 
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
char status;
double T,P,p0,a;
 
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void setup()
{ Serial.begin(9600); //Pins 10,11,12 & 13 fuer ethernet shield verwendet
 Ethernet.begin(mac, ip, gateway, subnet); 
 server.begin(); 
 ip_adresse = String(ip[0]) + "." + String(ip[1]) + "." +String(ip[2]) + "." + String(ip[3]);
 header = "arduino IP: " + ip_adresse + "\n\r";
 
 next_update = now() + 600; // nächste regelabtastung der analogen digitaleingänge alle 600 sec 
 last_get = now() +3;
 mySwitch.enableReceive(1); //receiver on interrupt 1 => that is pin D3
 
 if (ir_enable = true) {irrecv.enableIRIn();irrecv.blink13(true);pinMode(9, OUTPUT); //lED leuchtet während der Abarbeitung der Befehle
 digitalWrite(9, HIGH);} // Start the ir-receiver auf pin D2
 if (rf_enable = true) {mySwitch.enableReceive(1);} //start rf receiver auf pin D3
 
 lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines and turn on backlight
 lcd.backlight();
 }
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void loop()
{ 
 command = ""; //String(100);
 EthernetClient client = server.available();
 if (client) 
 { // an http request ends with a blank line
 boolean currentLineIsBlank = true;
 while (client.connected())
 { if (client.available()) 
 { char c = client.read();
 if (reading && c == ' ') reading =false;
 if (c == '?') reading = true; // beginn der Befehlssequenz 
 if (reading) 
 { //read char by char HTTP request
 if (command.length() < 100) 
 { //store characters to string
 command = command + c;
 }
 } 
 if (c == '\n' && currentLineIsBlank) break;
 if (c == '\n') 
 { currentLineIsBlank = true;} else if (c != '\r') 
 { currentLineIsBlank = false;}
 }
 }
////////////////////////////////////////////////////////////////////////
pinMode(13, OUTPUT); //lED leuchtet während der Abarbeitung der Befehle
digitalWrite(13, HIGH);
 
//jetzt wird das command ausgeführt 
// befehl herausmaskieren
int colonPosition = command.indexOf(':');
befehl = command.substring(1,colonPosition);
command = command.substring((colonPosition+1)); //Rest-command bilden
 
client.print(header);
valid_command = false;
//###########################################################################
if (befehl == "setpin") 
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 pinMode(param, OUTPUT);
 digitalWrite(param, HIGH);
 client.print("Pin D" + parameter + " = 1 port is digital output E\n\r"); 
 }
}
//###########################################################################
if (befehl == "resetpin") 
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 pinMode(param, OUTPUT);
 digitalWrite(param, LOW);
 client.print("Pin D" + parameter + " = 0 port is digital output E\n\r"); 
 }
}
//###########################################################################
if (befehl == "digitalin") 
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 pinMode(param, INPUT);
 digitalWrite(param, HIGH);
 client.print("Pin D" + parameter + " = " + digitalRead(param) + " port is digital input E\n\r");
 }
}
//###########################################################################
if (befehl == "analogin") 
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 client.print("Pin A" + parameter + " = " + analogRead(param) + " port is analog input E\n\r");
 }
}
//###########################################################################
if (befehl == "pwm_out") 
{ valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false;}; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 PWM = command.toInt();
 pinMode(param, OUTPUT);
 analogWrite(param, PWM); 
 client.print("PWM D" + parameter + " = " + PWM + "% duty cycle at output E\n\r");
 
}
 
//###########################################################################
//Quellen: https://github.com/shirriff/Arduino-IRremote
if ((befehl == "ir_receive")&& (ir_enable == true)) //
 {valid_command = true; 
 decode_results results;
 irrecv.enableIRIn(); // Start the receiver
 unsigned long time_rf0 = millis();
 unsigned long time_rf1 = millis();
 
 while ((time_rf1 - time_rf0) < 3000)
 { time_rf1 = millis(); 
   if (irrecv.decode(&results))
        {dump(&results);
         client.print(hersteller );
         //client.print(decod);
         client.print("-code: ");
         client.print(val);
         client.print("  bits: "); 
         client.print(bitss);
         if ( address >0) {client.print(" opt.adress: ");
                           client.print(address);}
         client.print("   raw pulses: "); 
         client.print(rawl); 
         client.print("  0.5us-ticks\n\r");
         irrecv.resume(); // weitermachen mit empfangen
        } 
 }
 client.print("end ir_receive :" + command + " \n\r"); 
 }
//###########################################################################
//Quellen: https://github.com/shirriff/Arduino-IRremote
if (befehl == "ir_send") 
{ valid_command = true; 
 colonPosition = command.indexOf(':');
 code_type = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 //param = parameter.toInt(); 
 colonPosition = command.indexOf(':');
 parameter = command.substring(0,colonPosition);
 param1 = parameter.toInt(); 
 parameter = command.substring((colonPosition+1));
 param2 = parameter.toInt(); 
 
 if (code_type == "nec") {for (int i = 0; i < 1; i++) {
 irsend.sendNEC(param1, param2); // NEC code
 delay(40);}}
 
 if (code_type == "sony") {for (int i = 0; i < 3; i++) {
 irsend.sendSony(param1, param2); // Sony code
 delay(40);}} 
 
 if (code_type == "rc5") {for (int i = 0; i < 3; i++) {
 irsend.sendRC5(param1, param2); // rc5 code
 delay(40);}} 
 
 if (code_type == "rc6") {for (int i = 0; i < 3; i++) {
 irsend.sendRC6(param1, param2); // rc6 code
 delay(40);}} 
 
 client.print("ir_send mit Sendecode :" + command + " \n\r"); 
} 
//###########################################################################
//Quellen: https://github.com/shirriff/Arduino-IRremote
if (befehl == "ir_rawstore")
 {valid_command = true; 
  colonPosition = command.indexOf(':');
  if (colonPosition > 2) {valid_command = false;}; //speicherplaetze max 2 stellen erlaubt
  parameter = command.substring(0,colonPosition);
  param = parameter.toInt(); 
 
  decode_results results;
  irrecv.enableIRIn(); // Start the receiver
  unsigned long time_rf0 = millis();
  unsigned long time_rf1 = millis();
 
  while ((time_rf1 - time_rf0) < 3000)
    {time_rf1 = millis(); 
     if(irrecv.decode(&results))
       { digitalWrite(STATUS_PIN, HIGH);
         storeCode(&results);  
         //IR-Code im EEPROM speichern, Werte wieder zurueckholen und ausgeben
         addr = 200*param + 2*99;
         codeLen = 256* EEPROM.read(addr) + EEPROM.read(addr+1);
         int k = 1;
         for (int i = 1; i <= (codeLen); i++)//zurückspeichern aus EEPROM
           {int addr = 200*param + 2*(i-1);
            rawCodes[i - 1] = 256* EEPROM.read(addr) + EEPROM.read(addr+1);
            if (i % 2) {client.print(" m");} else {client.print(" s");}
            client.print(rawCodes[i - 1],DEC); 
            k= k+1;
            if (k>10) {k=1; client.print("\n\r");
           }
       }
     client.print("\n\r");
     if (codeLen > 98){client.print("zu grosse und fehlerhafte ");}
     client.print("Codelaenge : ");
     client.print(codeLen);
     client.print("\n\r");
 
     irrecv.resume(); // resume receiver
     digitalWrite(STATUS_PIN, LOW);
    } 
 }
 client.print("end ir_rawstore auf Speicherplatz: " + parameter + " \n\r"); 
}
//###########################################################################
//Quellen: https://github.com/shirriff/Arduino-IRremote
if (befehl == "ir_rawsend") 
 { valid_command = true; 
   colonPosition = command.indexOf(':');
   if (colonPosition > 2) {valid_command = false;}; //speicherplaetze max 2 stellen erlaubt
   parameter = command.substring(0,colonPosition);
   param = parameter.toInt(); 
 
   addr = 200*param + 2*99;
   codeLen= 256* EEPROM.read(addr) + EEPROM.read(addr+1);
   int k = 1;
   for (int i = 1; i <= (codeLen); i++)//zurückspeichern aus EEPROM
     {addr = 200*param + 2*(i-1);
      rawCodes[i - 1] = 256* EEPROM.read(addr) + EEPROM.read(addr+1);
      if (i % 2) {client.print(" m");} else {client.print(" s");}
      client.print(rawCodes[i - 1],DEC); 
      k= k+1;
      if (k>10) {k=1; client.print("\n\r");}
     }
   client.print("\n\r");
   client.print("Codelaenge : ");
   client.print(codeLen);
   client.print("\n\r");
   irsend.sendRaw(rawCodes, codeLen, 38);// Assume 38 KHz
   client.print("ir_rawsend von Speicherplatz :" + parameter + " \n\r"); 
 }
 
//###########################################################################
// Quellen: http://code.google.com/p/rc-switch/
if (befehl == "rf_send") 
{ valid_command = true; 
 colonPosition = command.indexOf(':');
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 colonPosition = command.indexOf(':');
 parameter = command.substring(0,colonPosition);
 param1 = parameter.toInt(); 
 parameter = command.substring((colonPosition+1));
 param2 = parameter.toInt(); 
 
 //RCSwitch mySwitch = RCSwitch();
 mySwitch.enableTransmit(param);
 // Optional set pulse length.
 // mySwitch.setPulseLength(320);
 // Optional set protocol (default is 1, will work for most outlets)
 // mySwitch.setProtocol(2);
 // Optional set number of transmission repetitions.
 // mySwitch.setRepeatTransmit(15);
 
 mySwitch.send(param1, param2);
 client.print("rf_send mit Sendecode :" + command + " \n\r"); 
} 
//###########################################################################
//Quellen http://code.google.com/p/rc-switch/ 
if ((befehl == "rf_receive")&& (rf_enable == true)) 
 { valid_command = true; 
 //mySwitch.enableReceive(1); //receiver on interrupt 1 => that is pin D3
 unsigned long time_rf0 = millis();
 unsigned long time_rf1 = millis();
 while ((time_rf1 - time_rf0) < 3000)
 { time_rf1 = millis();
 if (mySwitch.available()) 
 { int value = mySwitch.getReceivedValue();
 if (value == 0) {client.print("Unknown encoding");} 
 else 
 {client.print("Pin D3 received : ");
 client.print (mySwitch.getReceivedValue() );
 client.print (" / ");
 client.print( mySwitch.getReceivedBitlength() );
 client.print("bit Protocol: ");
 client.println( mySwitch.getReceivedProtocol() + " \n\r" );
 }
 mySwitch.resetAvailable();
 }
 } 
 client.print("end rf_receive :" + command + " \n\r"); 
 } 
//########################################################################### 
if (befehl == "onewire") 
{ valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 onewire_pin = parameter.toInt();
//Setup onewire//////////////////////////////////////////////////////////////////////
//long intervall_onewire =10000; //onewire-Operation alle 10sec
//long lastTime_onewire =0;
float tempC[10]; // 10 Onewire-Sensoren werden maximal verwendet
 
OneWire oneWire(onewire_pin); 
DallasTemperature sensors(&oneWire);
DeviceAddress TempSensor[] = //Adress-Array definieren
{ 
 { 0x28, 0x37, 0x35, 0xB6, 0x05, 0x00, 0x00, 0x8D }, //<<user-eingabe<<
 { 0x28, 0xA5, 0x0A, 0xDD, 0x05, 0x00, 0x00, 0xBD }, //<<user-eingabe<< 
 { 0x28, 0x31, 0x60, 0xDD, 0x05, 0x00, 0x00, 0x7C }, //<<user-eingabe<<
 { 0x28, 0xA2, 0x4B, 0xB5, 0x05, 0x00, 0x00, 0x90 }, //<<user-eingabe<<
 { 0x10, 0xC7, 0xBA, 0xDD, 0x01, 0x08, 0x00, 0x52 }, //<<user-eingabe<<
 { 0x10, 0x8E, 0xB8, 0xDD, 0x01, 0x08, 0x00, 0x32 }, //<<user-eingabe<<
 { 0x10, 0xC7, 0xBA, 0xDD, 0x01, 0x08, 0x00, 0x52 }, //<<user-eingabe<<
 { 0x10, 0x8E, 0xB8, 0xDD, 0x01, 0x08, 0x00, 0x32 }, //<<user-eingabe<<
 { 0x10, 0xC7, 0xBA, 0xDD, 0x01, 0x08, 0x00, 0x52 }, //<<user-eingabe<<
 { 0x10, 0x8E, 0xB8, 0xDD, 0x01, 0x08, 0x00, 0x32 }, //<<user-eingabe<<
};
 // Start up the library
 sensors.begin();
 // aufloesung 10 bit
 sensors.setResolution(TempSensor[0], 10);
 sensors.setResolution(TempSensor[1], 10);
 sensors.setResolution(TempSensor[2], 10);
 sensors.setResolution(TempSensor[3], 10);
 sensors.setResolution(TempSensor[4], 10);
 sensors.setResolution(TempSensor[5], 10); 
 sensors.setResolution(TempSensor[6], 10);
 sensors.setResolution(TempSensor[7], 10);
 sensors.setResolution(TempSensor[8], 10);
 sensors.setResolution(TempSensor[9], 10);
 
//Setup onewire//////////////////////////////////////////////////////////////////////
 while (command.length() > 1 ) 
 { colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 sensors.requestTemperatures();
 tempC[param] = sensors.getTempC(TempSensor[param]);
 client.print("onewire T" + parameter + " = " + tempC[param] + " Celsius / pin D" + onewire_pin + " as input \n\r");
 } 
} 
//###########################################################################
//Quellen: http://tushev.org/articles/arduino/item/52-how-it-works-ds18b20-and-arduino
if (befehl == "1wire") /// Unterprogramm fuer 1wire Abfrage von einzelnen Sensoren
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 
 OneWire ds(param); 
 #define DS18S20_ID 0x10
 #define DS18B20_ID 0x28 
 byte i;
 byte present = 0;
 byte data[12];
 byte addr[8];
 if (!ds.search(addr)) { ds.reset_search(); temp_tur = -1000; } //find a device
 if (OneWire::crc8( addr, 7) != addr[7]) {temp_tur = -1000; }
 if (addr[0] != DS18S20_ID && addr[0] != DS18B20_ID) {temp_tur = -1000;}
 if (temp_tur > -1000) 
 { ds.reset(); 
 ds.select(addr); 
 ds.write(0x44, 1); // Start conversion
 delay(850); // Wait some time...
 present = ds.reset(); 
 ds.select(addr);
 ds.write(0xBE); // Issue Read scratchpad command
 for ( i = 0; i < 9; i++) { data[i] = ds.read(); } // Receive 9 bytes
 temp_tur = ( (data[1] << 8) + data[0] )*0.0625; // Calculate temperature value 18B20
 //temp_tur = ( (data[1] << 8) + data[0] )*0.5    // Calculate temperature value 18S20
 }
 client.print("1wire T" + parameter + " = " + temp_tur + " Celsius / pin D" + param + " as input \n\r");
 }
}
//###########################################################################
//Quellen:http://fluuux.de/2012/09/arduino-adressen-aller-ds1820-ermitteln/
if (befehl == "1wire_address") /// Unterprogramm fuer Auslesen der Sensoradresse
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 
 OneWire ds(param);
 byte address[8];
 int i=0;
 byte ok = 0, tmp = 0;
 client.print("--Suche gestartet--\n\r");
 while (ds.search(address))
 {tmp = 0; 
 if (address[0] == 0x10) { client.print("Device is a DS18S20 : "); tmp = 1;} //0x10 = DS18S20
 else { if (address[0] == 0x28) { client.print("Device is a DS18B20 : "); tmp = 1; } //0x28 = DS18B20
 }
 if (tmp == 1) //display the address, if tmp is ok 
 {if (OneWire::crc8(address, 7) != address[7]) { client.print("but it doesn't have a valid CRC!\n\r"); }
 else { for (i=0;i<8;i++) //all is ok, display it
 { 
 client.print("0x");
 if (address[i] < 9) { client.print("0");}
 client.print(address[i],HEX);
 if (i<7) { client.print(", ");}
 }
 client.print("\n\r");
 ok = 1;
 }
 }//end if tmp
 }//end while
 if (ok == 0){client.print("Keine Sensoren gefunden\n\r"); }
 client.print("--Suche beendet--\n\r");
 }
} 
//###########################################################################
if (befehl == "w_data") 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 datum = command.toInt();
 data[param] = datum;
 client.print("w_data" + parameter + " = " + datum + " set w_data E\n\r");
}
//###########################################################################
if (befehl == "r_data") 
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false;break;}; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 client.print("r_data" + parameter + " = " + data[param]+ " Wert der Variablen E\n\r");
 }
}
//###########################################################################
if (befehl == "dist") // messung mit ultraschallsensor an "beliebigen pin
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt(); 
 
 long duration, cm; 
 pinMode(param, OUTPUT);
 digitalWrite(param, LOW);
 delayMicroseconds(2);
 digitalWrite(param, HIGH);
 delayMicroseconds(5);
 digitalWrite(param, LOW);
 pinMode(param, INPUT);
 duration = pulseIn(param, HIGH);
 cm = duration /29/2; 
 delay(100);
 
 client.print("ultrasonic an Pin D" + parameter + " = " + cm + " cm E\n\r");
 }
}
//###########################################################################
if (befehl == "w_msg") 
{ message = command;
 valid_command = true; 
 client.print("w_msg :" + message + "\n\r");
} 
//###########################################################################
if (befehl == "r_msg") 
{ valid_command = true; 
 client.print("r_msg :" + message + "\n\r");
} 
//###########################################################################
if (befehl == "ntc_in") 
{ while (command.length() > 1 ) 
 { valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; break; }; //kanalnummern max 2 stellen erlaubt
 parameter = command.substring(0,colonPosition);
 command = command.substring((colonPosition+1));
 param = parameter.toInt();
 
 Rt = Rv/((1024.0/analogRead(param))- 1.0);
 tempNTC = (B_wert * Tn / ( B_wert + (Tn * log(Rt/Rn)))) -Tn +25.0 ;
 client.print("NTC an A" + parameter + " = " + tempNTC + " gradCelsius E\n\r");
 } 
} 
//###########################################################################
if (befehl == "set_time")
{ valid_command = false; 
 if (command.length() == 0) {time = now();parameter = String(time); valid_command = true;}
 if (command.length() == 11) 
 {valid_command = true;
 parameter = command.substring(0,10);
 time = parameter.toInt(); 
 setTime(time);
 time = now();
 parameter = String(time);}
 client.print("homeduino zeit /s ist: " + parameter + " \n\r");
} 
 
//###########################################################################
//Quellen: https://github.com/sparkfun/BMP180_Breakout/archive/master.zip
//library: https://github.com/sparkfun/BMP180_Breakout/tree/master/software/Arduino/libraries/SFE_BMP180
if (befehl == "barometer") 
{ valid_command = true; 
  colonPosition = command.indexOf(':');
  if (colonPosition > 4) {valid_command = false;}; //maximal 4 stellen erlaubt
   parameter = command.substring(0,colonPosition);
   param = parameter.toInt(); 
 
  if (pressure.begin()) 
     { //client.print("BMP180 gestartet\n\r");
      delay(1000);
      char status;
      double T,P,p0,a;
      // Start a temperature measurement:
  // If request is successful, the number of ms to wait is returned.
  // If request is unsuccessful, 0 is returned.
 
  client.print("Meereshoehe NN : ");
  client.print(parameter);
  client.print(" m\n\r"); 
 
  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);
 
    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.
    status = pressure.getTemperature(T);
    if (status != 0)
    { // Print out the measurement:
      client.print("Temperatur     : ");
      client.print(T,1);
      client.print(" gradC \n\r");  
 
      // Start a pressure measurement:
      // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
      // If request is successful, the number of ms to wait is returned.
      // If request is unsuccessful, 0 is returned.
      status = pressure.startPressure(3);
      if (status != 0)
      { // Wait for the measurement to complete:
        delay(status);
 
        // Retrieve the completed pressure measurement:
        // Note that the measurement is stored in the variable P.
        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.
 
        status = pressure.getPressure(P,T);
        if (status != 0)
        { // Print out the measurement:
          client.print("Druck absolut  : ");
          client.print(P,2);
          client.print(" mb\n\r"); 
 
          // The pressure sensor returns abolute pressure, which varies with altitude.
          // To remove the effects of altitude, use the sealevel function and your current altitude.
          // This number is commonly used in weather reports.
          // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
          // Result: p0 = sea-level compensated pressure in mb
 
          p0 = pressure.sealevel(P,param); //Messung
 
          client.print("Druck bei NN   : ");
          client.print(p0,2);
          client.print(" mb\n\r"); 
 
        }
        else {client.print("error");}
      }
      else {client.print("error"); }
    }
    else {client.print("error"); }
  }
  else {client.print("error"); }
 
 }  
     else
       {client.print("BMP180 nicht da\n\r");} 
} 
//###########################################################################
//Quelle source code:  http://arduino-info.wikispaces.com/LCD-Blue-I2C#v3
// library hier :https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/LiquidCrystal_V1.2.1.zip
if (befehl == "display") 
{ valid_command = true; 
 colonPosition = command.indexOf(':');
 if (colonPosition > 2) {valid_command = false; }; //spalten max 2 Stellen erlaubt
 if (command.length() < 2) {lcd.clear();} //display loeschen nur mit befehl /?display:
 parameter = command.substring(0,colonPosition);
 param2 = parameter.toInt(); //spalte ist param2
 command = command.substring((colonPosition+1));
 colonPosition = command.indexOf(':');
 if (colonPosition > 1) {valid_command = false; }; //zeilen max 2 Stellen erlaubt
 parameter = command.substring(0,colonPosition);
 param3 = parameter.toInt(); //zeile ist param3
 command = command.substring((colonPosition+1));
 command.replace("%20", " ");//hier http-leerzeichen ersetzen
 //langere strings werden in 20-zeichen-haeppchen zerlegt
 //weil display sonst zeile ueberspringt. fehler in library ??
 int m = 0; //laufvariable
 String zeilennummer;
 while (command.length() > 20)
 {String zeile = command.substring(0,20);
  command = command.substring(20);
  lcd.setCursor(0,(param3 + m));
  zeilennummer = String(param3 + m);
  lcd.print(zeile);
  client.print("lcd_display zeile " + zeilennummer + ": " + zeile + " \n\r");
  m = m+1;
  param2 = 0;
 }
 zeilennummer = String(param3 + m);
 lcd.setCursor(param2,param3 + m);
 lcd.print(command);
 client.print("lcd_display zeile " + zeilennummer + ": " + command + " \n\r"); 
 
} 
//###########################################################################
if (befehl == "help") 
{ valid_command = true; 
 client.print("IP-Adresse/?Befehl:Param1:Param2: ...\n\r");
 client.print( 
   ip_adresse + "/?setpin:4:5:               >> Pins D4,D5 auf HIGH setzen und Pins als Output setzen \n\r" 
 + ip_adresse + "/?resetpin:7:4:8:           >> Pins D7,D4,D8 auf LOW setzen und Pinsals Output setzen \n\r" 
 + ip_adresse + "/?digitalin:5:4:            >> Pins D5,D4 lesen und Pins als Input setzen \n\r"
 + ip_adresse + "/?analogin:0:5:             >> Pins A0,A5 lesen und Pins auf Analoginput setzen \n\r");
 client.print( 
   ip_adresse + "/?pwm_out:4:96:             >> PWM-Signal mit Tastverhältnis 96% an Digitalpin D4 ausgeben \n\r"
 + ip_adresse + "/?onewire:6:0:5:1:          >> An D6 die 1-Wire Sensoren Nr.0, Nr.5 und Nr.0 einlesen \n\r"
 + ip_adresse + "/?1wire:7:                  >> An D7 den 1-Wire Sensor einlesen \n\r"
 + ip_adresse + "/?1wire_address:8:          >> An D8 alle Adressen der 1-Wire Sensoren auslesen \n\r");
 client.print( 
   ip_adresse + "/?rf_send:4:4523029:24:     >> An D4 das RF-Telegramm 4523029 mit 24bit-Kodierung ausgeben \n\r"
 + ip_adresse + "/?rf_receive:               >> An D3 auf rf-Signal 3s warten und RF-Telegramm anzeigen \n\r"
 + ip_adresse + "/?ir_send:nec:1086136543:32 >> An D9 das IR-Telegramm 1086136543 mit 36 bit laenge ausgeben \n\r"
 + ip_adresse + "/?ir_receive:               >> An D2 auf IR-Signal 3s warten und IR-Telegramm anzeigen \n\r");
 client.print( 
   ip_adresse + "/?ir_rawstore:5:            >> 3sec empfangen und IR-Signal auf Speicherplatz 5 wegspeichern\n\r"
 + ip_adresse + "/?ir_rawsend:5:             >> sendet IR-Signal von Speicherplatz 5 \n\r"
 + ip_adresse + "/? \n\r"
 + ip_adresse + "/? \n\r");
 client.print( 
   ip_adresse + "/?w_data:0:1425:            >> Homeduino-Integervariablen \"w_data[0]\" mit Wert 1525 setzen \n\r"
 + ip_adresse + "/?r_data:4:5:               >> Homeduino-Integervariablen \"w_data[4]\" und \"w_data[5]\" auslesen \n\r"
 + ip_adresse + "/?dist:6:                   >> Entfernung in cm mit Ultraschallsensor an Pin D6 einlesen \n\r"
 + ip_adresse + "/?w_msg:abcdef              >> \"abcdef\" in Homeduino-String \"message\" speichern \n\r");
 client.print( 
   ip_adresse + "/?set_time:174393838:       >> Homeduino-Zeit (Sekunden seit 1.1.1970) setzen/auslesen \n\r"
 + ip_adresse + "/?display:0:3:meldung       >> zeigt auf Display in Position 0 in Zeile 3 den Text \"meldung\" \n\r" 
 + ip_adresse + "/?display:                  >> loescht Display komplett\n\r" 
 + ip_adresse + "/?barometer:229             >> zeigt Daten vom Barometer-Sensor BMP180 bezogen auf Meereshoehe 229m >> \n\r"); 
 client.print( 
   ip_adresse + "/?r_msg:                    >> Homeduino-String \"message\" auslesen \n\r"
 + ip_adresse + "/?ntc_in:0:5:               >> NTC-Temperaturen von Pin A0 und A5 lesen \n\r" 
 + ip_adresse + "/?help:                     >> Anzeige der Befehlsliste \n\r" 
 + ip_adresse + "/?ver:                      >> Anzeige der Firmware-Version \n\r");
 
 }
//########################################################################### 
if (befehl == "ver") 
{ valid_command = true; 
 client.print(ver + "\n\r");
} 
//###########################################################################
if (valid_command == false) {client.print("no valid command !\n\r");}
//###########################################################################
client.println(); 
 
//###########################################################################
 // delay(100); // give the web browser time to receive the data
 client.stop(); // close the connection:
 }
//###########################################################################
pinMode(13, OUTPUT); //lED leuchtet während der Abarbeitung der Befehle
digitalWrite(13, LOW);
//hierhin kommen eigenständige Steuerung-_Programme, die dauernd zyklisch durchlaufen werden, 
//wenn aktuell keine http-Anfrage abgearbeitet wird:
//////////////////////////////////////////////////////////////////////// 
// IR empfang 
if (ir_enable == true) 
 {if (irrecv.decode(&results)) // IR-Signal da?
 { dump(&results); 
 ir_decode(); //Dekodieren
 irrecv.resume();
 Serial.println(" ir_key : " + irkey ); 
 if (ir_key < 255 )
 {if (client.connect(ccu, 8181)) 
 { String befehl = "GET /xy.exe?antwort=dom.GetObject('homeduino_ir').State(" + irkey + ")";
 client.println(befehl);
 client.println();
 client.stop();
 }
 } 
 }
 }
//###########################################################################
//////////////////////////////////////////////////////////////////////// 
// RF empfang 
if (rf_enable == true) 
 { if (mySwitch.available()) // RF-Signal da?
 { int value = mySwitch.getReceivedValue();
 if (value == 0) {Serial.print("Unknown encoding");} 
 else { Serial.print("Pin D3 received Code : ");
 Serial.print (mySwitch.getReceivedValue() );
 Serial.print (" / ");
 Serial.print( mySwitch.getReceivedBitlength() );
 Serial.print("bit Protocol: ");
 Serial.println( mySwitch.getReceivedProtocol() + " \n\r" );
 rf_decode(); //Dekodieren
 mySwitch.resetAvailable();
 Serial.println(" rf_key : " + rfkey ); 
 if (rf_key < 255 )
 {if (client.connect(ccu, 8181)) 
 { String befehl = "GET /xy.exe?antwort=dom.GetObject('homeduino_rf').State(" + rfkey + ")";
 client.println(befehl);
 client.println();
 client.stop();
 }
 }
 }
 }
 } 
//###########################################################################
// hier werden alternativ die analogeingänge als digitaleingänge verwendet, 
// und bei änderung die entsprechenden gespiegelten HM-Systemvariablen "homeduino_ax" 
// in der ccu entweder bei änderung der eingangssignale oder 
// aber immer alle 10min aktualisiert. 
// umschaltung zwischen analog- und digital-modusmit der variablen variablen ana_as_digital 
int i = 0;
int messwert;
String kanal;
String logikpegel;
String befehl;
akt_zeit = now();
 
if (akt_zeit > next_update)
 { next_update = next_update +600; // nächste zwangsaktualisierung in 10min
 while (i < 6) {Ax_alt[i] = !Ax_alt[i]; i=i+1; } // der altzustand wird komplementiert
 i = 0;
 }
 
if (akt_zeit > (last_get+5)) //sicherstellen, dass nicht häufiger als alle 5sec aktualisiert wird
{
 if (client.connect(ccu, 8181)) 
 { while (i < 6) 
 { messwert = analogRead(i); 
 if ((messwert < schaltschwelle_low[i]) && (Ax_alt[i] == 1 )) //bei aenderung des logikpegels, dann aenderungsmitteilung senden 
 { 
 Ax_alt[i] = 0;
 logikpegel = "0";
 kanal = String(i);
 befehl = "GET /xy.exe?antwort=dom.GetObject('homeduino_a" + kanal +"').State(" + logikpegel + ")"; 
 last_get = now(); 
 client.println(befehl);
 client.println();
 Serial.println("kanal: " + kanal + " logikpegel : " + logikpegel + "\n\r" );
 }
 if ((messwert > schaltschwelle_high[i])&& (Ax_alt[i] == 0 )) 
 { 
 Ax_alt[i] = 1;
 logikpegel = "1";
 kanal = String(i);
 befehl = "GET /xy.exe?antwort=dom.GetObject('homeduino_a" + kanal +"').State(" + logikpegel + ")"; 
 last_get = now(); 
 client.println(befehl);
 client.println();
 Serial.println("kanal: " + kanal + " logikpegel : " + logikpegel + "\n\r" );
 } 
 
 i = i+1; 
 } 
 client.stop(); 
 }
}
//###########################################################################
}
//##################### ende Hauptprogramm #############################
 
 
 
 
//#################### Unterprogramme nachfolgend ######################################
 
//########################################################################################
//Unterprogramm zur Befehlserkennung der IR-Signale 
//
void rf_decode() 
{switch(mySwitch.getReceivedValue())
 {
 case 924878775: rf_key = 1; break;
 
 case 2787635768: rf_key = 2; break;
 
 case 2837968624: rf_key = 3; break;
 
 case 3295764352: rf_key = 4; break;
 
 case 3278986732: rf_key = 5; break;
 
 case 3933460971: rf_key = 6; break;
 
 case 3950238589: rf_key = 7; break;
 
 case 2385074916: rf_key = 8; break;
 
 case 2334742062: rf_key = 9; break;
 
 case 2989216297: rf_key = 10; break;
 
// bis 254 Codes möglich
 
 default: rf_key = 255;
 }
 rfkey = String(rf_key);
 
} 
 
//########################################################################################
//Unterprogramm zur Befehlserkennung der IR-Signale 
//
void ir_decode() 
{switch(results.value)
 {
 case 924878775: ir_key = 1; break; //LED11
 
 case 1312990725: ir_key = 2; break; //LED12
 
 case 1296213109: ir_key = 3; break; //LED13
 
 case 675294110: ir_key = 4; break; //LED14
 
 case 692071728: ir_key = 5; break; //LED15
 
 case 3728316604: ir_key = 6; break; //LED16
 
 case 3677983750: ir_key = 7; break; //LED17
 
 case 3057064751: ir_key = 8; break; //LED18
 
 case 3040287131: ir_key = 9; break; //LED19
 
 case 3931625651: ir_key = 10; break; //LED20
 
// bis 254 Codes möglich
 
 default: ir_key = 255;
 }
 irkey = String(ir_key);
 
}
//########################################################################################
//Quelle: Beispielprogramm aus der IRremote library
// Dumps out the decode_results structure. 
// Call this after IRrecv::decode()
// void * to work around compiler issue
void dump(void *v) {
decode_results *results = (decode_results *)v;
//void dump(decode_results *results) {
 
//werte als public variable speichern
val =(results->value);
bitss = (results->bits);
address = 0;
rawl = (results->rawlen);
decod =(results->decode_type);
switch(decod)
 { case 1: hersteller = "nec"; break;
   case 2: hersteller = "sony"; break;
   case 3: hersteller = "rc5"; break;
   case 4: hersteller = "rc6"; break;
   case 5: hersteller = "dish"; break;
   case 6: hersteller = "sharp"; break;
   case 7: hersteller = "panasonic"; address =(results->panasonicAddress) ;break;
   case 8: hersteller = "jvc"; break;
   case 9: hersteller = "sanyo"; break;
   case 10: hersteller = "mitsubishi"; break;
   case 11: hersteller = "samsung"; break;
   case 12: hersteller = "lg"; break;
   case -1: hersteller = "unknown"; break;
   default: ir_key = 255;
 }
 }
 
//##############################################################
// Stores the code for later playback Most of this code is just logging
void storeCode(decode_results *results)
{count = results->rawlen;
 codeLen = results->rawlen - 1;
 if (codeLen > 98) {codeLen =99;} //nur codelaengen bis 98 zulaessig
 // To store raw codes: Drop first value (gap) Convert from ticks to microseconds
 // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
 int k = 1;
 int addr;
 for (int i = 1; i <= codeLen; i++) 
 { if (i % 2) {rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS; Serial.print(" m");}// Mark
     else {rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS; Serial.print(" s");}// Space
   Serial.print(rawCodes[i - 1], DEC);
 
   //in EEPROM speichern 200bytes je IR-Code_Speicherplatz
   addr = 200*param + 2*(i-1);
   val = rawCodes[i - 1]/256;
   EEPROM.write(addr, val);  //schreibe High-Byte
   EEPROM.write(addr+1, rawCodes[i - 1] - val);  //schreibe Low-Byte
   k= k+1;
   if (k>10) {k=1; Serial.print("\n\r");}
 }
  //jetzt noch codeLen im EEPROM ablegen
   addr = 200*param + 2*99;
   val = codeLen/256;
   EEPROM.write(addr, val);  //schreibe High-Byte
   EEPROM.write(addr+1, codeLen - val);  //schreibe Low-Byte
   Serial.print("\n\r");
   Serial.print("Codelaenge : ");
   Serial.print(codeLen);
   Serial.print("\n\r");
}

komoloko
Beiträge: 14
Registriert: 22.12.2014, 20:56

Re: Homeduino IR - Empfänger homeduino_ir

Beitrag von komoloko » 10.12.2018, 12:41

Bisher habe ich immer noch keine Verbindung; über die IP-Befehle klappt alles, aber die Systemvariable wird nicht gesetzt.
Hat jemand noch eine Idee? Ich bin hier am verzweifeln.

Antworten

Zurück zu „RaspberryMatic“