Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
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

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. [n00b]]Ethernet GW - without NF24

[n00b]]Ethernet GW - without NF24

Scheduled Pinned Locked Moved My Project
31 Posts 4 Posters 15.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brix7be
    wrote on last edited by
    #22

    Is there anyone who have done a sketch to connect sensor directly on an ethernet gateway ?
    Iam searching a working exemple or a working draft to see the process to build my own code.
    Thank everyone for your advices.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brix7be
      wrote on last edited by brix7be
      #23

      Hi Hek, Everyone,

      I've clean the approximative sketch I've made before to simply try to see the value of a DS18b20 sensor trough a serial gw in domoticz.
      So i've placed the merged code below to have your advices.
      In domoticz's log i can see the declaration of the gw but neither the dallas sensor!?

      Does someone could check my sketch please?
      To be sure that the arduino see the dallas, i've tested a sketch wich send the value to the serial terminal (it works properly :-).

      Thank you in advance for your help.
      Have a nice sunday all. (clouday in belgium today ;-)).

      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable serial gateway
      #define MY_GATEWAY_SERIAL
      
      // Flash leds on rx/tx/err
      //#define MY_LEDS_BLINKING_FEATURE
      // Set blinking period
      //#define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Enable inclusion mode
      //#define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      // Set inclusion mode duration (in seconds)
      //#define MY_INCLUSION_MODE_DURATION 60 
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3 
      
      //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  9  // the PCB, on board LED
      
      #include <SPI.h>
      #include <MySensor.h>  
      #include <DallasTemperature.h>
      #include <OneWire.h>
      
      #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
      
      #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
      #define MAX_ATTACHED_DS18B20 16
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
      DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
      float lastTemperature[MAX_ATTACHED_DS18B20];
      int numSensors=0;
      boolean receivedConfig = false;
      boolean metric = true; 
      // Initialize temperature message
      MyMessage msg(0,V_TEMP);
      
      void setup() { 
        // Setup locally attached sensors
        
        // Startup up the OneWire library
        sensors.begin();
        // requestTemperatures() will not block current thread
        sensors.setWaitForConversion(false);
      }
      
      void presentation() {
       // Present locally attached sensors 
       
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Temperature Sensor", "1.1");
      
        // Fetch the number of attached temperature sensors  
        numSensors = sensors.getDeviceCount();
      
        // Present all sensors to controller
        for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
           present(i, S_TEMP);
        }
      }
      
      void loop() { 
        // Send locally attached sensor data here
      
        // Fetch temperatures from Dallas sensors
        sensors.requestTemperatures();
      
        // query conversion time and sleep until conversion completed
        int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
        // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
        sleep(conversionTime);
      
        // Read temperatures and send them to controller 
        for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
       
          // Fetch and round temperature to one decimal
          float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
       
          // Only send data if temperature has changed and no error
          #if COMPARE_TEMP == 1
          if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
          #else
          if (temperature != -127.00 && temperature != 85.00) {
          #endif
       
            // Send in the new temperature
            send(msg.setSensor(i).set(temperature,1));
            // Save new temperatures for next compare
            lastTemperature[i]=temperature;
          }
        }
        sleep(SLEEP_TIME);
      }
      

      To be complete, there is the domoticz log.

      2015-10-25 10:44:40.157 MySensors: Using serial port: COM3
      2015-10-25 10:44:41.892 MySensors: Gateway Ready...
      2015-10-25 10:44:41.892 MySensors: Node: 0, Sketch Name: Temperature Sensor
      2015-10-25 10:44:41.946 MySensors: Node: 0, Sketch Version: 1.1
      
      1 Reply Last reply
      0
      • B Offline
        B Offline
        brix7be
        wrote on last edited by
        #24

        No idea?

        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #25

          Sensors attached to gateway (node id=0) is a new feature.
          Might be Domoticz filtering these type of messages perhaps?

          @GizMoCuz might know if this is the case.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            afick
            wrote on last edited by
            #26

            Hello,
            I have created ethernet gateway :) with 2 sensors :) (DHT11, and door/windows sensor) all data are send to domoticz without problem.But when i adds "przekaznik" - one channel relay - i can't send/receive data about this relay. Can anyone check why ?

            sorry for mess in code

            // Enable debug prints to serial monitor
            #define MY_DEBUG
            
            // Enable gateway ethernet module type
            #define MY_GATEWAY_W5100
            
            // Enable Soft SPI for NRF radio (note different radio wiring is required)
            // The W5100 ethernet module seems to have a hard time co-operate with
            // radio on the same spi bus.
            #define MY_SOFTSPI
            #define MY_SOFT_SPI_SCK_PIN 14
            #define MY_SOFT_SPI_MISO_PIN 16
            #define MY_SOFT_SPI_MOSI_PIN 15
            
            // When W5100 is connected we have to move CE/CSN pins for NRF radio
            #define MY_RF24_CE_PIN 5
            #define MY_RF24_CS_PIN 6
            
            // Enable to UDP
            //#define MY_USE_UDP
            
            #define MY_IP_ADDRESS 192,168,0,250   // If this is disabled, DHCP is used to retrieve address
            // Renewal period if using DHCP
            //#define MY_IP_RENEWAL_INTERVAL 60000
            // The port to keep open on node server mode / or port to contact in client mode
            #define MY_PORT 5003
            
            // Controller ip address. Enables client mode (default is "server" mode).
            // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
            //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
            
            // The MAC address can be anything you want but should be unique on your network.
            // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
            // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
            #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
            
            // Flash leds on rx/tx/err
            #define MY_LEDS_BLINKING_FEATURE
            // Set blinking period
            #define MY_DEFAULT_LED_BLINK_PERIOD 300
            
            // Enable inclusion mode
            #define MY_INCLUSION_MODE_FEATURE
            // Enable Inclusion mode button on gateway
            #define MY_INCLUSION_BUTTON_FEATURE
            // Set inclusion mode duration (in seconds)
            #define MY_INCLUSION_MODE_DURATION 60
            // Digital pin used for inclusion mode button
            #define MY_INCLUSION_MODE_BUTTON_PIN  3
            
            #define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
            #define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
            #define MY_DEFAULT_TX_LED_PIN  9  // the PCB, on board LED
            
            //Przekaznik
            #define MY_REPEATER_FEATURE
            
            #define RELAY_1  22  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
            #define NUMBER_OF_RELAYS 1 // Total number of attached relays
            #define RELAY_ON 1  // GPIO value to write to turn on attached relay
            #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
            
            #include <SPI.h>
            
            #if defined(MY_USE_UDP)
            #include <EthernetUdp.h>
            #endif
            
            
            #include <Ethernet.h>
            #include <MySensor.h>
            #include <DHT.h>   //dodany czujnik
            
            //czujnik temp i wilgotnosci
            #define CHILD_ID_HUM 0
            #define CHILD_ID_TEMP 1
            #define HUMIDITY_SENSOR_DIGITAL_PIN 3
            #define DOOR_ID1 4
            #define DOOR_ID1_PIN A0
            
            unsigned long SLEEP_TIME = 300; // Sleep time between reads (in milliseconds)
            DHT dht;
            float lastTemp;
            float lastHum;
            boolean metric = true;
            MyMessage msgHum(CHILD_ID_HUM, V_HUM);
            MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
            
            MyMessage msgDOOR_ID1(DOOR_ID1, V_TRIPPED);
            int old_DOOR_ID1_STATE = -1;
            
            
            void setup()
            {
            
              //temp + hum
              dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
              metric = getConfig().isMetric;
            
              //  kontaktron DOOR_ID1
              pinMode(DOOR_ID1_PIN, INPUT);
            
              //  //przekaznik
              for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
              //    // Then set relay pins in output mode
                  pinMode(pin, OUTPUT);
              //    // Set relay to last known state (using eeprom storage)
                  digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
                }
            
            }
            
            void presentation()
            {
            
              //temp + hum
              // Send the Sketch Version Information to the Gateway
              sendSketchInfo("Humidity", "1.0");
              // Register all sensors to gw (they will be created as child devices)
              present(CHILD_ID_HUM, S_HUM);
              present(CHILD_ID_TEMP, S_TEMP);
              present(DOOR_ID1, S_DOOR);
            
              //przekaznik
              // Send the sketch version information to the gateway and Controller
              sendSketchInfo("Relay", "1.0");
            
              for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
                // Register all sensors to gw (they will be created as child devices)
                present(sensor, S_LIGHT);
                Serial.print("Petla presentation");
              }
            
            }
            
            void loop()
            {
              //temp + hum
              delay(dht.getMinimumSamplingPeriod());
              float temperature = dht.getTemperature();
              if (isnan(temperature)) {
                Serial.println("Failed reading temperature from DHT");
              } else if (temperature != lastTemp) {
                lastTemp = temperature;
                if (!metric) {
                  temperature = dht.toFahrenheit(temperature);
                }
                send(msgTemp.set(temperature, 1));
                Serial.print("T: ");
                Serial.println(temperature);
              }
            
              float humidity = dht.getHumidity();
              if (isnan(humidity)) {
                Serial.println("Failed reading humidity from DHT");
              } else if (humidity != lastHum) {
                lastHum = humidity;
                send(msgHum.set(humidity, 1));
                Serial.print("H: ");
                Serial.println(humidity);
              }
            
            
              int DOOR_ID1_STATE = analogRead(DOOR_ID1_PIN);
              Serial.print("Analog= ");
              Serial.println(DOOR_ID1_STATE);
              Serial.println(old_DOOR_ID1_STATE);
            
              if (DOOR_ID1_STATE == 0) {
                DOOR_ID1_STATE = 0;
                send(msgDOOR_ID1.set(DOOR_ID1_STATE));
                old_DOOR_ID1_STATE = DOOR_ID1_STATE;
                Serial.print("drzwi_1=");
                Serial.println(DOOR_ID1_STATE);
            
              } else {
                DOOR_ID1_STATE = 1;
                send(msgDOOR_ID1.set(DOOR_ID1_STATE));
                old_DOOR_ID1_STATE = DOOR_ID1_STATE;
                Serial.print("drzwi_2=");
                Serial.println(DOOR_ID1_STATE);
              }
            }
            
            void receive(const MyMessage &message) {
              // We only expect one type of message from controller. But we better check anyway.
              if (message.type == V_LIGHT) {
                // Change relay state
                digitalWrite(message.sensor - 1 + RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF);
                // Store state in eeprom
                saveState(message.sensor, message.getBool());
                // Write some debug info
                Serial.print("Incoming change for sensor:");
                Serial.print(message.sensor);
                Serial.print(", New status: ");
                Serial.println(message.getBool());
              }
            }
            
            
            1 Reply Last reply
            0
            • hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by
              #27

              Just did some verification of message receiving in gateway on the ESP8266 sent from my shell (using netcat). Messages is showing up in receive() just fine here.

              Are you sending to node 0 from Domoticz? What does the log say in the gateway?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                afick
                wrote on last edited by afick
                #28

                Nothing special

                0;0;3;0;9;Starting...
                IP: 192.168.0.250
                0;0;3;0;9;gateway started, id=0, parent=0, distance=0
                

                Domoticz log

                 2015-11-09 23:09:50.588 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:09:53.599 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:09:56.614 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:09:56.620 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:00.632 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:00.680 (GW) Lighting 2 (Security Sensor)
                2015-11-09 23:10:03.706 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:07.718 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:12.730 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:17.745 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:21.762 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:22.770 (GW) Lighting 2 (Security Sensor)
                2015-11-09 23:10:27.791 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:31.805 (GW) Temp + Humidity (TempHum)
                2015-11-09 23:10:32.812 (GW) Temp + Humidity (TempHum) 
                

                I'm receiving only this kind of information.

                How can i send "0" from domoticz to GW ?

                1 Reply Last reply
                0
                • hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #29

                  Your have messed up the presentation of your S_LIGHT devices in the loop. They start with id 1 in the loop. But that id has already been used by CHILD_ID_TEMP.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    afick
                    wrote on last edited by
                    #30

                    Even if i change CHILD_ID_RELAY (to 5 or 6 ) sill the same.

                    1 Reply Last reply
                    0
                    • zaphodusZ Offline
                      zaphodusZ Offline
                      zaphodus
                      wrote on last edited by
                      #31

                      I had the same problem as you and I have found a possible solution. The arduino has default auto reset on serial connection. So when you connect gateway to controller trough USB, the gateway is rebooting immediately and processing presentation(). In case of wireless gateway (esp8266) this does not happen. The presentation() runs only on startup of the gateway. I made little change in MyGatewayTransportEthernet.cpp and now the gateway processes presentation() when the controller is connecting to it.

                      You can find here my solution:
                      https://github.com/zaphodus/Arduino/commit/ce93db73513f1da45637b186787c9b2501e5d882

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      18

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular