Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

  1. ioBroker Community Home
  2. Русский
  3. аппаратные средства
  4. Железо
  5. Rcswitch

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.2k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    1.9k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    15
    1
    2.3k

Rcswitch

Geplant Angeheftet Gesperrt Verschoben Железо
1 Beiträge 1 Kommentatoren 1.9k Aufrufe
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • aurodionovA Offline
    aurodionovA Offline
    aurodionov
    schrieb am zuletzt editiert von
    #1

    Пользую некоторое количество розеток на 433.92, решил прикрутить к iobroker.

    Работает на arduino+ethernet+китайские приёмник и передатчик.

    Скетч взят на http://majordomo.smartliving.ru/forum/v … f=8&t=1717, за что им спасибо, и поправлен под себя

    скрипт

    ! ````
    createState('javascript.0.rcswitch', '');
    ! on({id: 'javascript.0.rcswitch', change: 'any'}, function (obj) {
    var temp = obj.newState.val;
    log(' приняли по радио :' + temp);
    toLog(' приняли по радио :' + temp, true);
    ! var rcswitch = obj.newState.val;

    if (rcswitch == '472151'){
        toLog('вкл чего-то');
    }
    else if (rcswitch == '472177'){
        toLog('выкл чего-то');
    }
    

    });

    
    код для дуинки
    
    >! ````
    #include <rcswitch.h>#include <rcswitch.h>#include <avr wdt.h="">#include <spi.h>//#include <uipethernet.h>// HR911105A 
    #include <ethernet.h>// w5100 
    >! // Параметры
    >! #define HOST_NAME "RCSW_"      // Название устройства
    #define StaticIP
    #define BUFSIZ 48
    #define BUFSend 120
    >! #define SendTry 3
    >! //#define ALIVETIMER             // Флаг присутствия
    //#define ALIVETIMEOUT 300000    // Тайминг присутствия - 5min
    #define REPEATTIMEOUT 1500     // Таймаут повторного запроса
    >! #define RCControl              // Флаг управления RC
    >! //#define UIP_CONNECT_TIMEOUT = 5; // Таймаут соединения
    >! uint8_t mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC}; // MAC
    >! // Сеть
    IPAddress deviceip(192,168,55,70);
    IPAddress sendip(192,168,55,170);
    >! //----------------
    char buf[BUFSend];
    >! unsigned long lasttime; // Last commin time
    char lastbuf[BUFSend];      // Last buffer
    >! #ifdef ALIVETIMER
      unsigned long AliveTime;
    #endif  
    >! RCSwitch mySwitch = RCSwitch();
    EthernetClient client;
    >! #ifdef RCControl
      EthernetServer server = EthernetServer(80);
    >! const char HTMLH[] PROGMEM = 
      "HTTP/1.1 200 OK\r\n"
      "Content-Type: text/html\r\n"
      "\r\n"
      "<title>RC Switch gate</title>";
    
    const char HTMLE[] PROGMEM =   
      "\r\n";  
    #endif 
    >! unsigned long GetTickDiff(unsigned long AOldTickCount, unsigned long ANewTickCount){
      // This is just in case the TickCount rolled back to zero
      if (ANewTickCount >= AOldTickCount){
        return ANewTickCount - AOldTickCount;
      } else {
        return 0xFFFFFFFF - AOldTickCount + ANewTickCount;
      }
    }
    >! bool sendHTTPRequest() {  
      bool ret = true;
    
      if (client.connect(sendip, 8087)) {
         Serial.println("connected");
    
        // Make a HTTP request:
        client.println(buf);
        client.println("User-Agent: arduino-ethernet");     
        client.println("Connection: close");     
        client.println();
    
        Serial.println(buf);   
      } else {
        Serial.println("Timeout connected");
        ret = false;
      }
    
      client.stop(); 
      return ret;
    }
    >! void setup() {
      wdt_disable();
      delay(5000);
    
      Serial.begin(9600);
      #ifndef StaticIP
        Serial.println("Read DHCP config");  
        if (!Ethernet.begin(mac)){
          Serial.println("Failed to configure Ethernet using DHCP");
      #endif
        Ethernet.begin(mac, deviceip);
      #ifndef StaticIP  
        }   
      #endif  
    >!   wdt_enable(WDTO_8S);
    
      Serial.print("localIP: ");
      Serial.println(Ethernet.localIP());
      Serial.print("subnetMask: ");
      Serial.println(Ethernet.subnetMask());
      Serial.print("gatewayIP: ");
      Serial.println(Ethernet.gatewayIP());
      Serial.print("dnsServerIP: ");
      Serial.println(Ethernet.dnsServerIP());
    
      mySwitch.enableReceive(1);
      mySwitch.enableTransmit(4);  
    
      #ifdef RCControl
        server.begin();  
      #endif  
    
      #ifdef ALIVETIMER
        AliveTime = millis();
      #endif  
      lasttime = millis();
    }
    >! void loop() {
      wdt_reset();
    >!   // RCSwitch
      if (mySwitch.available()) {    
        sprintf(buf, "GET /set/javascript.0.rcswitch?value=%ld HTTP/1.0", mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedProtocol() );
    
        // Test double quest   
        if ( (strcmp(buf, lastbuf) != 0) || (GetTickDiff(lasttime, millis()) >= REPEATTIMEOUT)){
          if ( sendHTTPRequest() ){
            strncpy(lastbuf, buf, BUFSend);
            lasttime = millis();
          } 
        }
    
        mySwitch.resetAvailable();    
      }  
    
      // ALIVETIMER
      #ifdef ALIVETIMER
        if (GetTickDiff(AliveTime, millis()) >= ALIVETIMEOUT){
          sprintf(buf, "GET /set/javascript.0.rcswitch=rcswitch&rcswitch HTTP/1.0" );
          sendHTTPRequest();
          AliveTime = millis();
        }
      #endif
    >!   // HTTP
      #ifdef RCControl
        if (EthernetClient sclient = server.available()) {
          char header[BUFSIZ];
          byte index = 0;
    
          boolean currentLineIsBlank = true;
          while (sclient.available()) {
            char c = sclient.read();
            if (index < BUFSIZ){        
              header[index] = c;
              index++;
              header[index] = 0;
            }
    
            // Ansfer
            if (c == '\n' && currentLineIsBlank){ 
              break; 
            }
            if (c == '\n') {
              currentLineIsBlank = true;
            } else if (c != '\r') {
              currentLineIsBlank = false;
            }        
          }
    >!       char delimiters[] = "/?,= ";
    >!       // Head
          char * istr = strtok(header, delimiters);
          char * status = "";
    
          // Type
          istr = strtok(NULL, delimiters);
          if (strcmp(istr, "RCSwitch") == 0){
            // id        
            int unsigned long id   = strtol( strtok(NULL, delimiters), NULL, 10 );
    >!         // bits        
            int unsigned long bits = strtol( strtok(NULL, delimiters), NULL, 10 );
    
            //Serial.print("Send command: ");
            Serial.print( id );
            Serial.print( "," );
            Serial.println( bits );
    
            // Send try
            for (int n=0; n < SendTry; n++){
              mySwitch.send( id, bits );
            }
    >!         status = "Command send OK";
          } else {        
            Serial.print("Error type: ");
            Serial.println( istr );
    
            status = "Command send ERROR";
          }
    
          //-- response --  
          sclient.print(HTMLH);
          sclient.print( status );
          sclient.print(HTMLE);
    
          sclient.stop();
        }   
      #endif    
    }</ethernet.h></uipethernet.h></spi.h></avr></rcswitch.h></rcswitch.h> 
    

    Пока работает только приём, кто может помогите с передачей

    Пишу с пульта….

    1 Antwort Letzte Antwort
    0
    Antworten
    • In einem neuen Thema antworten
    Anmelden zum Antworten
    • Älteste zuerst
    • Neuste zuerst
    • Meiste Stimmen


    Support us

    ioBroker
    Community Adapters
    Donate

    625

    Online

    32.4k

    Benutzer

    81.4k

    Themen

    1.3m

    Beiträge
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
    ioBroker Community 2014-2025
    logo
    • Anmelden

    • Du hast noch kein Konto? Registrieren

    • Anmelden oder registrieren, um zu suchen
    • Erster Beitrag
      Letzter Beitrag
    0
    • Home
    • Aktuell
    • Tags
    • Ungelesen 0
    • Kategorien
    • Unreplied
    • Beliebt
    • GitHub
    • Docu
    • Hilfe