Skip to content
  • 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. Development
  3. RS485/RS232/Serial transport class for mysensors.org
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

RS485/RS232/Serial transport class for mysensors.org

Scheduled Pinned Locked Moved Development
rs485 serialrs485
143 Posts 27 Posters 102.8k Views 27 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.
  • P Offline
    P Offline
    pjr
    wrote on last edited by
    #51

    @andriej remember to calculate how much current you can take thru cat5e and how much load there can be with one pair.
    From wikipedia: "Maximum current per conductor 0.577A". So this would make P=UxI -> 12Vx0.577A=6.92W. There is calculations where one nano can take max 1.4Watts. You could use more wires of the car5e for power or lift voltage upper. 48Vx0.577A=27.70W ;)

    A 1 Reply Last reply
    0
    • P pjr

      @andriej remember to calculate how much current you can take thru cat5e and how much load there can be with one pair.
      From wikipedia: "Maximum current per conductor 0.577A". So this would make P=UxI -> 12Vx0.577A=6.92W. There is calculations where one nano can take max 1.4Watts. You could use more wires of the car5e for power or lift voltage upper. 48Vx0.577A=27.70W ;)

      A Offline
      A Offline
      andriej
      wrote on last edited by
      #52

      @pjr I'm aware of that :-)
      Still struggling with decision either to use the CAT5e just as a loooong cable to (doorbell) switch or use it to PoE small nanos all over the place and run i.e. MQTT on each wall-switch separate.
      In second option the RS485 protocol would be the best, because of small form factor (smaller than ethernet port inside switch) and possibility to use MySensors too ;-)

      :-)

      1 Reply Last reply
      0
      • K kimot

        I think, that CAN transceiver chip is better then RS485 transceiver chip.
        Then we dont need direction setting pin and bus state is better determined, becose CAn bus is prepered for bus collisions, RS485 not.
        I mean only CAN bus transceiver, not CAN controller ! For example MCP2551 or MCP2562.
        And we can use normal serial library.

        A Offline
        A Offline
        andriej
        wrote on last edited by
        #53

        @kimot what has to be done to prepare MySensors to use CAN?
        I'm thinking about ordering some modules for tests. :-)

        :-)

        K 2 Replies Last reply
        0
        • T Offline
          T Offline
          TimO
          Hero Member
          wrote on last edited by
          #54

          @andriej said:

          use it to PoE small nanos all over the place

          Which components do you have in mind? I 'm thinking in that direction too.

          A 1 Reply Last reply
          0
          • T TimO

            @andriej said:

            use it to PoE small nanos all over the place

            Which components do you have in mind? I 'm thinking in that direction too.

            A Offline
            A Offline
            andriej
            wrote on last edited by
            #55

            @TimO this small W5100 module: http://www.aliexpress.com/item/TOP-Mini-W5100-LAN-Ethernet-Shield-Network-Module-board-Best/32457200047.html with step-down dc converter. :-)
            Cheaper than the PoE standard version.

            :-)

            1 Reply Last reply
            0
            • A andriej

              @kimot what has to be done to prepare MySensors to use CAN?
              I'm thinking about ordering some modules for tests. :-)

              K Offline
              K Offline
              kimot
              wrote on last edited by
              #56

              @andriej
              It is a pity that not paying more attention mysensors.org for nodes interconnected by wires. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. I think that used ICSC library does not address this matter satisfactorily and with a larger number of sensor problems arise. ICSC library uses a Serial Software library by heavyweight each node on the bus, because all must be checke every bit transmitted on the bus. Look at different implementation:

              www.mrbus.org

              I think, thet using hardware UART is absolutely necessary.
              Or why when we use a separate module for radio transmission, we use the special module for robust message transfer over the wired bus? CAN controllers are not so expensive in this days:

              http://www.ebay.com/itm/MCP2515-CAN-Bus-Module-Board-TJA1050-receiver-SPI-For-51-MCU-ARM-controller-M2-/381500570180?hash=item58d334ba44:g:OhcAAOSw3KFWfANk

              After correct CAN controller configuration, we simply write a message to the CAN controller and forgot about it. No check or bus arbitration. And through interrupt pin from the controller just pick up the incoming message with our ID or broadcast.

              I know it's not as simple as using only RS485 transmitter itself, but we are guaranteed connecting maximum of 110 nodes and various libraries for Arduino for this CAN controller exist.

              L 1 Reply Last reply
              1
              • A andriej

                @kimot what has to be done to prepare MySensors to use CAN?
                I'm thinking about ordering some modules for tests. :-)

                K Offline
                K Offline
                kimot
                wrote on last edited by
                #57

                @andriej
                But on the other side, with simply CANbus, we have got only 8 byte payload for our data.

                A 1 Reply Last reply
                0
                • K kimot

                  @andriej
                  But on the other side, with simply CANbus, we have got only 8 byte payload for our data.

                  A Offline
                  A Offline
                  andriej
                  wrote on last edited by
                  #58

                  @kimot so the only thing that's left is TCP/IP and MQTT...

                  :-)

                  1 Reply Last reply
                  0
                  • K kimot

                    @andriej
                    It is a pity that not paying more attention mysensors.org for nodes interconnected by wires. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. I think that used ICSC library does not address this matter satisfactorily and with a larger number of sensor problems arise. ICSC library uses a Serial Software library by heavyweight each node on the bus, because all must be checke every bit transmitted on the bus. Look at different implementation:

                    www.mrbus.org

                    I think, thet using hardware UART is absolutely necessary.
                    Or why when we use a separate module for radio transmission, we use the special module for robust message transfer over the wired bus? CAN controllers are not so expensive in this days:

                    http://www.ebay.com/itm/MCP2515-CAN-Bus-Module-Board-TJA1050-receiver-SPI-For-51-MCU-ARM-controller-M2-/381500570180?hash=item58d334ba44:g:OhcAAOSw3KFWfANk

                    After correct CAN controller configuration, we simply write a message to the CAN controller and forgot about it. No check or bus arbitration. And through interrupt pin from the controller just pick up the incoming message with our ID or broadcast.

                    I know it's not as simple as using only RS485 transmitter itself, but we are guaranteed connecting maximum of 110 nodes and various libraries for Arduino for this CAN controller exist.

                    L Offline
                    L Offline
                    LeoDesigner
                    wrote on last edited by LeoDesigner
                    #59

                    @kimot
                    Thanks for pointing to mrbus.org.
                    I have seen this before - it's really nice implementation of RS485 bus management.
                    It's worth trying to implement it. However, I can see only one weak point of ICSC lib. It's a moment when both nodes listening a bus and starting to transmit at the same time. In this case the both packets will be lost. (This situation can occur only during the transmission of the first starting byte, so higher bus speed can make this situation rare.)
                    I have both the radio and wired mysensors network. And wired network in order of magnitude is more reliable. I have a really small amount of lost packets. The packets are retransmitted only due delay in the code of the nodes.

                    1 Reply Last reply
                    0
                    • radekzmR Offline
                      radekzmR Offline
                      radekzm
                      wrote on last edited by
                      #60

                      HELP: Please instructions on how I can run this RS485 transport class for beginners.

                      Some basic questions:

                      1. First point instructions: File "SerialTransport.h" and "SerialTransport.cpp" download to C:\Program Files (x86)\Arduino\libraries\MySensors[here]. is this correct ?
                      2. On the second point instructions: "Add #include <SerialTransport.h> to your .ino sketch" but examples do not have this:
                        https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/MotionSensorRS485
                        https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/GatewaySerialRS485
                        way ?
                        In what file i must put this line "#include <SerialTransport.h>" ? main sketch ?
                      3. The third point instructions: Replace transport class with: "Replace transport class with: " where exactly ? Maybe I have a different version MySensors because I can not find the declaration "#define MY_RADIO_RF24" and replace it with a "#define MY_RS485". I do not know how to change the NRF to RS485 in lib MySensors. Please precise instructions with examples for the current version lib MySensors.
                      4. Can I get examples of sketch (confirmed that work with the physical bus RS485) Gateway and sensor.

                      I use Windows, path of arduino lib is: C:\Program Files (x86)\Arduino\libraries.

                      The only thing that works:
                      When I connect RS485 to USB on Raspberry Pi (domoticz) and on the other side sensor (Arduino Pro Mini + DHT22) received on Raspberry:

                      radek@raspberrypi $ cat /dev/ttyUSB0
                      radi init fail
                      

                      It sent the sensor by the RS485 to Rasberry PI. So the RS485 is working properly.

                      Sorry for my English and thank you for your help.

                      L 1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pjr
                        wrote on last edited by pjr
                        #61

                        I think those instructions are written for older version of the library. Now you could just copy those examples and try without changing anything.... I think ;)

                        1 Reply Last reply
                        0
                        • radekzmR Offline
                          radekzmR Offline
                          radekzm
                          wrote on last edited by
                          #62

                          In the examples, there is no information on how to disable the radio NRF24 and enable RS485, this is my main problem.

                          MySensors still try init Radio NRF, because no radio connected in sending "radio init fail"

                          Renovate the house and so I want to use it:
                          Raspberry Pi (Domoticz) <--- USB ---> MySensor Gateway RS485 <--- RS485 (Cat5e) ---> MySensors Sensors & Actuators (x 20)

                          Will show photos when I finish.

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

                            @radekzm said:

                            In the examples, there is no information on how to disable the radio NRF24 and enable RS485, this is my main problem.

                            It is this line that activates the RS485 transport (also note that no radio is activated).
                            https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewaySerialRS485/GatewaySerialRS485.ino#L56

                            I haven't had the opportunity to test this thoroughly. So there might be issues.

                            1 Reply Last reply
                            0
                            • radekzmR Offline
                              radekzmR Offline
                              radekzm
                              wrote on last edited by
                              #64

                              I think that constat value:

                              #define MY_RS485
                              

                              https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewaySerialRS485/GatewaySerialRS485.ino#L56

                              It is doing nothing and changes nothing. This constat value is only on exmaple sketch. It is not a reference to the constat value in the library MySensros and mysensors-serial-transport.

                              Searching 1628 files for "MY_RS485"
                              0 matches

                              ??? I still do not know how to use the RS485 instead of NRF24 ???

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

                                What do you mean?

                                If surely affects things here:
                                https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/MySensor.h#L237-L268

                                1 Reply Last reply
                                1
                                • radekzmR Offline
                                  radekzmR Offline
                                  radekzm
                                  wrote on last edited by
                                  #66

                                  That's exactly what I looking for !. In my version of the library that are missing.
                                  In my version of the library that (supports RS485) are missing.
                                  I downloaded the Library https://github.com/mysensors/Arduino/archive/master.zip this is my problem.
                                  Should I download from https://github.com/mysensors/Arduino/tree/development/libraries/MySensors.

                                  The last question: Do I have just these two files download and replace from second url and that all ?

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

                                    You'll have to download replace everything in MySensors library folder.

                                    1 Reply Last reply
                                    0
                                    • radekzmR radekzm

                                      HELP: Please instructions on how I can run this RS485 transport class for beginners.

                                      Some basic questions:

                                      1. First point instructions: File "SerialTransport.h" and "SerialTransport.cpp" download to C:\Program Files (x86)\Arduino\libraries\MySensors[here]. is this correct ?
                                      2. On the second point instructions: "Add #include <SerialTransport.h> to your .ino sketch" but examples do not have this:
                                        https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/MotionSensorRS485
                                        https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/GatewaySerialRS485
                                        way ?
                                        In what file i must put this line "#include <SerialTransport.h>" ? main sketch ?
                                      3. The third point instructions: Replace transport class with: "Replace transport class with: " where exactly ? Maybe I have a different version MySensors because I can not find the declaration "#define MY_RADIO_RF24" and replace it with a "#define MY_RS485". I do not know how to change the NRF to RS485 in lib MySensors. Please precise instructions with examples for the current version lib MySensors.
                                      4. Can I get examples of sketch (confirmed that work with the physical bus RS485) Gateway and sensor.

                                      I use Windows, path of arduino lib is: C:\Program Files (x86)\Arduino\libraries.

                                      The only thing that works:
                                      When I connect RS485 to USB on Raspberry Pi (domoticz) and on the other side sensor (Arduino Pro Mini + DHT22) received on Raspberry:

                                      radek@raspberrypi $ cat /dev/ttyUSB0
                                      radi init fail
                                      

                                      It sent the sensor by the RS485 to Rasberry PI. So the RS485 is working properly.

                                      Sorry for my English and thank you for your help.

                                      L Offline
                                      L Offline
                                      LeoDesigner
                                      wrote on last edited by LeoDesigner
                                      #68

                                      @radekzm said:

                                      HELP: Please instructions on how I can run this RS485 transport class for beginners.

                                      You have to use a stable 1.5.2 version for my RS485 transport class. Not a development branch. You also may want to try development version too. The instruction was written for 1.5 (1.5.2) version of mysensors libs.

                                      Some basic questions:

                                      1. First point instructions: File "SerialTransport.h" and "SerialTransport.cpp" download to C:\Program Files (x86)\Arduino\libraries\MySensors[here]. is this correct ?

                                      ...\Arduino\libraries\SerialTransport\ [HERE]

                                      1. On the second point instructions: "Add #include <SerialTransport.h> to your .ino sketch" but examples do not have this:
                                        https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/MotionSensorRS485
                                        https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/GatewaySerialRS485
                                        way ?

                                      They are for development version - not for stable 1.5.2

                                      In what file i must put this line "#include <SerialTransport.h>" ? main sketch ?
                                      Yes.

                                      1. The third point instructions: Replace transport class with: "Replace transport class with: " where exactly ? Maybe I have a different version MySensors because I can not find the declaration "#define MY_RADIO_RF24" and replace it with a "#define MY_RS485". I do not know how to change the NRF to RS485 in lib MySensors. Please precise instructions with examples for the current version lib MySensors.

                                      Please check examples for version 1.5 (1.5.2)

                                      1. Can I get examples of sketch (confirmed that work with the physical bus RS485) Gateway and sensor.
                                      /*
                                      * MockMySensors 485
                                      *
                                      * This skecth is intended to crate fake sensors which register and respond to the controller
                                      * 
                                      * Barduino 2015
                                      */
                                      
                                      #include <MySigningNone.h>
                                      //#include <MyTransportRFM69.h>
                                      //#include <MyTransportNRF24.h>
                                      #include <MyHwATMega328.h>
                                      #include <MySigningAtsha204Soft.h>
                                      #include <MySigningAtsha204.h>
                                      
                                      #include <SPI.h>
                                      #include <MySensor.h>  
                                      #include <MyMessage.h>
                                      
                                      #include <SerialTransport.h>
                                      
                                      
                                      #define RADIO_ERROR_LED_PIN 9  // Error led pin
                                      #define RADIO_RX_LED_PIN    8  // Receive led pin
                                      #define RADIO_TX_LED_PIN    7  // the PCB, on board LED
                                      
                                      
                                      // Wait times
                                      #define LONG_WAIT 500
                                      #define SHORT_WAIT 50
                                      
                                      #define SKETCH_NAME "FakeMySensors 485 241"
                                      #define SKETCH_VERSION "v0.2"
                                      
                                      // Global Vars
                                      // unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
                                      unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
                                      
                                      boolean metric = true;
                                      long randNumber;
                                      
                                      // Instanciate MySersors Gateway
                                      //MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
                                      //MyTransportRFM69 transport;
                                      MyTransportSerial transport(Serial,241,6); // serial port, node, dePin (-1 disabled)
                                      
                                      
                                      // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
                                      //MySigningNone signer;
                                      //MySigningAtsha204Soft signer;
                                      //MySigningAtsha204 signer;
                                      
                                      // Hardware profile 
                                      MyHwATMega328 hw;
                                      
                                      // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
                                      // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
                                      #ifdef WITH_LEDS_BLINKING
                                      MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
                                      #else
                                      MySensor gw(transport, hw /*, signer*/);
                                      #endif
                                      
                                      //Instanciate Messages objects
                                      
                                      #ifdef ID_S_DOOR
                                        MyMessage msg_S_DOOR(ID_S_DOOR,V_TRIPPED);
                                      #endif
                                      
                                      
                                      ......
                                      ......
                                      

                                      I use Windows, path of arduino lib is: C:\Program Files (x86)\Arduino\libraries.

                                      You have to decide which version of the library to use.
                                      My SerialTransport is written only for version 1.5.2
                                      It's tested and working. BTW, I will upload updated version in a few minutes to github.

                                      1 Reply Last reply
                                      0
                                      • radekzmR Offline
                                        radekzmR Offline
                                        radekzm
                                        wrote on last edited by
                                        #69

                                        I still have a few questions:

                                        Use: https://github.com/mysensors/Arduino/tree/development/libraries/MySensors.

                                        1) Architecture: Do I understand correctly, example test:
                                        raspberry pi domoticz [USB] <---- USB RS232 built-in Arduino nano ----> (hardware RS232, PIN: tx/rx) Arduino Nano (Gatwey RS485) (AltSoftSerial, PIN: 2,7,8) <---- RS485 AltSoftSerial ----> (AltSoftSerial, PIN: 2,7,8) Arduino Pro Mini <------ PIN 3, DHT22

                                        2) Gatwey RS485 Arduino Nano:

                                        • USB port of the Arduino Nano plugs in to Raspberry PI and set MySensors USB gateway in Domoticz ?
                                        • Gatwaey to communicate with RS485 uses AltSoftSerial ? Whta PIN ? R0 / DI ?
                                        • Gatwey Arduino Nano to communicate with Raspberry PI (Domoticz) use hardware USB (built in RS232) ?
                                        • Gatweway don't have Debug mode (no free RS) ? When uploading have I must turn of debug mode in MyConfig.h when use RS485?
                                        • DE PIN 2 ?
                                        • RO PIN 8 ?
                                        • DI PIN 9 ?
                                        • PIN 2/8/9 connected directly without pull-up resistors or current limiting ?
                                          /**
                                        ...
                                         * The gateway uses AltSoftSerial to handle two serial links 
                                         * on one Arduino. Use the following pins for RS485 link
                                         * 
                                         *  Board          Transmit  Receive   PWM Unusable
                                         * -----          --------  -------   ------------
                                         * Teensy 3.0 & 3.1  21        20         22
                                         * Teensy 2.0         9        10       (none)
                                         * Teensy++ 2.0      25         4       26, 27
                                         * Arduino Uno        9         8         10  <----- Form https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html .... (& other ATMEGA328)
                                         * Arduino Leonardo   5        13       (none)
                                         * Arduino Mega      46        48       44, 45
                                         * Wiring-S           5         6          4
                                         * Sanguino          13        14         12
                                         * 
                                         */
                                        
                                        // Enable debug prints to serial monitor
                                        #define MY_DEBUG 
                                        
                                        // Enable RS485 transport layer
                                        #define MY_RS485
                                        
                                        // Define this to enables DE-pin management on defined pin 
                                        #define MY_RS485_DE_PIN 2
                                        
                                        // Set RS485 baud rate to use
                                        #define MY_RS485_BAUD_RATE 9600
                                        
                                        // 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 4  // Error led pin
                                        #define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
                                        #define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
                                        
                                        #include <SPI.h>
                                        #include <MySensor.h>  
                                        
                                        void setup() { 
                                          // Setup locally attached sensors
                                        }
                                        
                                        void presentation() {
                                         // Present locally attached sensors 
                                        }
                                        
                                        void loop() { 
                                          // Send locally attached sensor data here 
                                        }
                                        
                                        

                                        3) Sensor Arduino Pro mini

                                        • What uses to communicate with RS485 bus ? Hardware RS232 Pin RX /TX or AltSoftSerial Pin 2/7/8 ?
                                        • If use AltSoftSerial: PIN 2/8/9 connected directly without pull-up resistors or current limiting ?
                                        • When uploading have I must turn of debug mode in MyConfig.h when use RS485?
                                        /**
                                        ...
                                        // Enable RS485 transport layer
                                        #define MY_RS485
                                        
                                        // Define this to enables DE-pin manag ement on defined pin 
                                        #define MY_RS485_DE_PIN 2
                                        
                                        // Set RS485 baud rate to use
                                        #define MY_RS485_BAUD_RATE 9600
                                        
                                        #include <SPI.h>
                                        #include <MySensor.h>
                                        #include <DHT.h>  
                                        
                                        #define MY_NODE_ID 15
                                        #define CHILD_ID_HUM 0
                                        #define CHILD_ID_TEMP 1
                                        #define HUMIDITY_SENSOR_DIGITAL_PIN 3
                                        unsigned long SLEEP_TIME = 2000; // Sleep time between reads (in milliseconds)
                                        
                                        // Initialize sensors
                                        DHT dht;
                                        float lastTemp;
                                        float lastHum;
                                        boolean metric = true; 
                                        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                                        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                                        
                                        // Debug
                                        //#include <SoftwareSerial.h>
                                        //SoftwareSerial mySerial(3, 4); // RX, TX
                                        
                                        void setup()  
                                        {    
                                          //mySerial.begin(4800);
                                          //mySerial.println("Hello, world?");  
                                          dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                                          metric = getConfig().isMetric;  
                                        }
                                        
                                        
                                        void presentation()  { 
                                          // Send the Sketch Version Information to the Gateway
                                          sendSketchInfo("Falskiego LED salon", "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);
                                        }
                                        
                                        
                                        void loop()     
                                        {     
                                          delay(dht.getMinimumSamplingPeriod());
                                         
                                          // Fetch temperatures from DHT sensor
                                          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));
                                            #ifdef MY_DEBUG
                                            Serial.print("T: ");
                                            Serial.println(temperature);
                                            #endif
                                          }
                                          
                                          // Fetch humidity from DHT sensor
                                          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));
                                              #ifdef MY_DEBUG
                                              Serial.print("H: ");
                                              Serial.println(humidity);
                                              #endif
                                          }
                                          
                                          sleep(SLEEP_TIME); //sleep a bit
                                        }
                                        
                                        

                                        Schema
                                        Schema
                                        Schema

                                        1 Reply Last reply
                                        0
                                        • P Offline
                                          P Offline
                                          pjr
                                          wrote on last edited by
                                          #70
                                          This post is deleted!
                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          11

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 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
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular