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. Remote controlled switches (433MHz) and temperature sensors

Remote controlled switches (433MHz) and temperature sensors

Scheduled Pinned Locked Moved My Project
17 Posts 5 Posters 10.5k Views 1 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.
  • CaptainZapC Offline
    CaptainZapC Offline
    CaptainZap
    wrote on last edited by CaptainZap
    #2

    Looking in the Vera logs this is what I actually see when I try to control one switch from the interface :

    08      02/26/15 18:23:50.791   JobHandler_LuaUPnP::HandleActionRequest device: 57 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x2f6a5680>
    08      02/26/15 18:23:50.791   JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=57 <0x2f6a5680>
    08      02/26/15 18:23:50.791   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:SwitchPower1 <0x2f6a5680>
    08      02/26/15 18:23:50.792   JobHandler_LuaUPnP::HandleActionRequest argument action=SetTarget <0x2f6a5680>
    08      02/26/15 18:23:50.792   JobHandler_LuaUPnP::HandleActionRequest argument newTargetValue=0 <0x2f6a5680>
    08      02/26/15 18:23:50.792   JobHandler_LuaUPnP::HandleActionRequest argument rand=0.6773929147942098 <0x2f6a5680>
    50      02/26/15 18:23:50.795   luup_log:34: Arduino: Sending: 19;1;1;1;2;0 <0x2b772000>
    51      02/26/15 18:23:50.796   0x31 0x39 0x3b 0x31 0x3b 0x31 0x3b 0x31 0x3b 0x32 0x3b 0x30 0xd 0xa (19;1;1;1;2;0\r\n) <0x2b772000>
    52      02/26/15 18:23:50.852   0x30 0x3b 0x30 0x3b 0x33 0x3b 0x30 0x3b 0x39 0x3b 0x73 0x65 0x6e 0x64 0x3a 0x20 0x30 0x2d 0x30 0x2d 0x31 0x39 0x2d 0x31 0x39 0x20 0x73 0x3d 0x31 0x2c 0x63 0x3d 0x31 0x2c 0x74 0x3d 0x32 0x2c 0x70 0x74 0x3d 0x30 0x2c 0x6c 0x3d 0x31 0x2c 0x73 0x74 0x3d 0x66 0x61 0x69 0x6c 0x3a 0x30 (0;0;3;0;9;send: 0-0-19-19 s=1,c=1,t=2,pt=0,l=1,st=fail:0) <0x2f8e8680>
    50      02/26/15 18:23:50.853   luup_log:34: Arduino: Log: send: 0-0-19-19 s=1,c=1,t=2,pt=0,l=1,st=fail:0 <0x2f8e8680>
    08      02/26/15 18:23:51.815   JobHandler_LuaUPnP::HandleActionRequest device: 57 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x2f6a5680>
    08      02/26/15 18:23:51.815   JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=57 <0x2f6a5680>
    08      02/26/15 18:23:51.816   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:SwitchPower1 <0x2f6a5680>
    08      02/26/15 18:23:51.816   JobHandler_LuaUPnP::HandleActionRequest argument action=SetTarget <0x2f6a5680>
    08      02/26/15 18:23:51.816   JobHandler_LuaUPnP::HandleActionRequest argument newTargetValue=1 <0x2f6a5680>
    08      02/26/15 18:23:51.816   JobHandler_LuaUPnP::HandleActionRequest argument rand=0.17616296711805424 <0x2f6a5680>
    50      02/26/15 18:23:51.832   luup_log:34: Arduino: Sending: 19;1;1;1;2;1 <0x2b772000>
    51      02/26/15 18:23:51.833   0x31 0x39 0x3b 0x31 0x3b 0x31 0x3b 0x31 0x3b 0x32 0x3b 0x31 0xd 0xa (19;1;1;1;2;1\r\n) <0x2b772000>
    52      02/26/15 18:23:51.883   0x30 0x3b 0x30 0x3b 0x33 0x3b 0x30 0x3b 0x39 0x3b 0x73 0x65 0x6e 0x64 0x3a 0x20 0x30 0x2d 0x30 0x2d 0x31 0x39 0x2d 0x31 0x39 0x20 0x73 0x3d 0x31 0x2c 0x63 0x3d 0x31 0x2c 0x74 0x3d 0x32 0x2c 0x70 0x74 0x3d 0x30 0x2c 0x6c 0x3d 0x31 0x2c 0x73 0x74 0x3d 0x66 0x61 0x69 0x6c 0x3a 0x31 (0;0;3;0;9;send: 0-0-19-19 s=1,c=1,t=2,pt=0,l=1,st=fail:1) <0x2f8e8680>
    50      02/26/15 18:23:51.884   luup_log:34: Arduino: Log: send: 0-0-19-19 s=1,c=1,t=2,pt=0,l=1,st=fail:1 <0x2f8e8680>
    

    From serial monitor I see this output:

    sensor started, id 19
    send: 19-19-0-0 s=255,c=0,t=17,pt=0,l=3,st=fail:1.4
    send: 19-19-0-0 s=255,c=3,t=6,pt=1,l=1,st=fail:0
    send: 19-19-0-0 s=255,c=3,t=11,pt=0,l=5,st=fail:RF433
    send: 19-19-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 19-19-0-0 s=1,c=0,t=3,pt=0,l=3,st=fail:1.4
    send: 19-19-0-0 s=2,c=0,t=3,pt=0,l=3,st=fail:1.4
    send: 19-19-0-0 s=3,c=0,t=3,pt=0,l=3,st=ok:1.4
    send: 19-19-0-0 s=4,c=1,t=0,pt=7,l=5,st=fail:21.1
    
    1 Reply Last reply
    0
    • CaptainZapC CaptainZap

      Hi guys,

      I've been trying to build a 433MHz transmitter and temperature sensor for two Dallas sensors. The goal is to monitor my heating system and turn on/off the recirculating pumps using the 433MHz switches. Up until now this has been done manually (through remote), but I would really love to automate this.

      The problem is that I suck badly at coding, everything goes over my head (sorry), so I've been trying to adapt the currently available code into a single sketch that would help me do this.

      Using the RC Switch library I was able to find out the codes I need to be sending to control my 3 RF switches. Now here comes the funny part, I've used @Dwalt sketch and modified to something I think should work(I am very bad at coding :(). I've also included bits from a multi-sensor sketch I had from @gregl to get at least one temperature sensor added (no idea how to add two).

      I've flashed it on my nano, but when included on the Vera lite (UI5), only the 3 switch devices show up on the interface but no temperature device is created. Using serial monitor I can see that temperature is sent back, but unfortunately the switches from the interface do not seem to control my RF switches.

      I would appreciate any hints on my current issues :

      • how to get two temperature sensors to show up on interface (including the current one)
      • how to correct the RF transmission

      The code is the one below :

      //  Include related libraries
      #include <MySensor.h>
      #include <SPI.h>  
      #include <RF24.h>
      #include <RCSwitch.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      
      //  Define Constants
      #define RF433_CHILD_ID 0
      #define NUMBER_OF_OUTLETS 3 // Each outlet will have 2 OOK codes
      #define SEND_DATA 3 // pin used to send 433MHz data
      #define CLIENT_ID AUTO  // Sets MYSensors client id
      #define RADIO_CH 76  // Sets MYSensors to use Radio Channel
      
      //Temp Sensor bits
      #define ONE_WIRE_BUS 4 // Pin where dallas sensor is connected - on Rboard this is (D4)
      OneWire oneWire(ONE_WIRE_BUS);
      DallasTemperature DallasSensors(&oneWire);
      float lastTemperature ;
      float tempC = DallasSensors.getTempCByIndex(1);
      RCSwitch mySwitch = RCSwitch();
      #define CHILD_ID_T1 4 //CHILD ID for temperature
      
      MySensor gw;
      MyMessage tempMsg(CHILD_ID_T1,V_TEMP);
      
      void setup() 
      {
            
       Serial.begin(115200); // Not sure why this was included
      
       //  The node is mains powered, so why not make it a repeater.
       gw.begin(incomingMessage, CLIENT_ID , false,AUTO,RF24_PA_MAX,RADIO_CH,RF24_250KBPS);
       
        // Send the sketch version information to gateway
       gw.sendSketchInfo("RF433_Temp", "1.0");
        //enable RF 433MHz transmitter
       mySwitch.enableTransmit(SEND_DATA);
       // Register outlets to gw (they will be created as child devices)
       for(int i=0; i<NUMBER_OF_OUTLETS;i++) {
         gw.present(i+1, S_LIGHT);
      
       }
      // Fetch temperatures from Dallas sensors
      DallasSensors.requestTemperatures();
      
      		
      // Only send data if temperature has changed and no error
        if (lastTemperature != tempC && tempC != -127.00) {
      
        // Send in the new temperature
        gw.send(tempMsg.set(tempC,1));
      lastTemperature=tempC;
        } 
      }
      
      void loop() {
        gw.process();
      }
        void incomingMessage(const MyMessage &message) {
      
        if (message.type==V_LIGHT) {
        int incomingLightState =  message.getBool(); 
        int incomingOutlet = message.sensor;
      
        Serial.print("Outlet #: ");
        Serial.println(message.sensor);
        Serial.print("Command: ");
        Serial.println(message.getBool());
      
       if (incomingOutlet==1) {
       if (incomingLightState==1) {
      // Turn on  socket 1
       Serial.println("Turn on Socket 1");
       mySwitch.switchOn("10101", "10000"); // These codes are unique to each outlet
       delay(50); 
       }
       if (incomingLightState==0)  {
      // Turn off socket 1
      Serial.println("Turn off Socket 1");
      mySwitch.switchOff("10101", "10000");
      delay(50); 
       }
       }
       if (incomingOutlet==2) {
       if (incomingLightState==1) {
      // Turn on  socket 2
      Serial.println("Turn on Socket 2");
      mySwitch.switchOn("10101", "01000");
       delay(50); 
       }
       if (incomingLightState==0)  {
      // Turn off socket 2
       Serial.println("Turn off Socket 2");
       mySwitch.switchOff("10101", "01000");
      delay(50); 
       }
       }
       if (incomingOutlet==3) {
       if (incomingLightState==1) {
      // Turn on  socket 3
      Serial.println("Turn on Socket 3");
       mySwitch.switchOn("10101", "00100");
       delay(50); 
       }
       if (incomingLightState==0)  {
      // Turn off socket 3
       Serial.println("Turn off Socket 3");
      mySwitch.switchOff("10101", "00100");
      delay(50); 
       }
       }
       }
       delay(50);
       }
      
      DwaltD Offline
      DwaltD Offline
      Dwalt
      wrote on last edited by
      #3

      @CaptainZap Just a quick look at your sketch and I see that your temp fetching commands are in 'setup' and not 'loop'', that may explain the lack of temp data. As for the 433 commands, I am not familiar with the RCSwitch library and how it works. For my sketch, I spelled out the transmit process by defining a command (in my sketch it was "pt2262Send", which I borrowed from somewhere else but cant remember where off hand) and used that command within the loop when the V_Light message was received. I used the binary code I received from raw sniffing of the signal.

      Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

      1 Reply Last reply
      0
      • CaptainZapC Offline
        CaptainZapC Offline
        CaptainZap
        wrote on last edited by
        #4

        @Dwalt Thank you for pointing that out, I am that bad at coding. Anyway, I've done that and I've tried to rewrite the part for two temperature sensors but they still don't show up on the Vera interface.
        I've done some testing and said that I should ditch RCSwitch library and use instead a simple function they provide, so I've retested the switches, and made sure that the code send is correct but I still can't control any switches. Also the temperature sensors do not show up. I need help guys, I feel I am so close it's kind of frustrating :(

        Below is the revised code :

        #include <MySensor.h>
        #include <SPI.h>  
        #include <RF24.h>
        #include <DallasTemperature.h>
        #include <OneWire.h>
        
        //  Define Constants
        #define RF433_CHILD_ID 0
        #define NUMBER_OF_OUTLETS 3
        #define CLIENT_ID AUTO  // Sets MYSensors client id
        #define RADIO_CH 76  // Sets MYSensors to use Radio Channel
        #define MAX_ATTACHED_DS18B20 2
        unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
        //Temp Sensor bits
        #define ONE_WIRE_BUS 4 // Pin where dallas sensor is connected - on Rboard this is (D4)
        OneWire oneWire(ONE_WIRE_BUS);
        DallasTemperature sensors(&oneWire);
        float lastTemperature[MAX_ATTACHED_DS18B20];
        int numSensors=0; // >> in original temp sketch this is 0 should it be changed to 2 ?
        int RCLpin = 3;
        MySensor gw;
        MyMessage msg(0,V_TEMP);
        
         void RCLswitch(uint16_t code) {
        for (int nRepeat=0; nRepeat<6; nRepeat++) {
            for (int i=4; i<16; i++) {
                RCLtransmit(1,3);
                if (((code << (i-4)) & 2048) > 0) {
                    RCLtransmit(1,3);
                } else {
                    RCLtransmit(3,1);
                }
            }
            RCLtransmit(1,31);    
        }
        }
        
        void RCLtransmit(int nHighPulses, int nLowPulses) {
        digitalWrite(RCLpin, HIGH);
        delayMicroseconds( 350 * nHighPulses);
        digitalWrite(RCLpin, LOW);
        delayMicroseconds( 350 * nLowPulses);
        }
        
        void setup() 
        {
        
         Serial.begin(115200); // Not sure why this was included
        
         //  The node is mains powered, so why not make it a repeater.
         gw.begin(incomingMessage, CLIENT_ID , false,AUTO,RF24_PA_MAX,RADIO_CH,RF24_250KBPS);
        
          // Send the sketch version information to gateway
         gw.sendSketchInfo("RF433&Temp", "1.0b");
        
          //enable RF 433MHz transmitter
         pinMode(RCLpin, OUTPUT);
        
         // Register outlets to gw (they will be created as child devices)
         for(int i=0; i<NUMBER_OF_OUTLETS;i++) {
           gw.present(i+1, S_LIGHT);
        
        // 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++) {   
             gw.present(i, S_TEMP);
        
         }
        }
        }
        
        void loop() {
          gw.process();
          // Fetch temperatures from Dallas sensors
        //DallasSensors.requestTemperatures();
        sensors.requestTemperatures(); 
        	
        // 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>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
        
        // Only send data if temperature has changed and no error
        if (lastTemperature[i] != temperature && temperature != -127.00) {
        
          // Send in the new temperature
          gw.send(msg.setSensor(i).set(temperature,1));
          lastTemperature[i]=temperature;
        }
        }
        }
          void incomingMessage(const MyMessage &message) {
          
          if (message.type==V_LIGHT) {
          int incomingLightState =  message.getBool(); 
          int incomingOutlet = message.sensor;
        
          Serial.print("Outlet #: ");
          Serial.println(message.sensor);
          Serial.print("Command: ");
          Serial.println(message.getBool());
        
         if (incomingOutlet==1) {
         if (incomingLightState==1) {
        // Turn on  socket 1
        Serial.println("Turn on Socket 1");
        RCLswitch(0b101011000001);// These codes are unique to each outlet
         }
         if (incomingLightState==0)  {
        // Turn off socket 1
        Serial.println("Turn off Socket 1");
        RCLswitch(0b101011000010);
         }
         }
         if (incomingOutlet==2) {
         if (incomingLightState==1) {
        // Turn on  socket 2
        Serial.println("Turn on Socket 2");
        RCLswitch(0b101010100001);
         }
         if (incomingLightState==0)  {
        // Turn off socket 2
        Serial.println("Turn off Socket 2");
        RCLswitch(0b101010100010);
         }
         }
         if (incomingOutlet==3) {
         if (incomingLightState==1) {
        // Turn on  socket 3
        Serial.println("Turn on Socket 3");
        RCLswitch(0b101010010001);
         }
         if (incomingLightState==0)  {
        // Turn off socket 3
        Serial.println("Turn off Socket 3");
        RCLswitch(0b101010010010); 
         }
         }
         }
         gw.sleep(SLEEP_TIME);
         }
        
        1 Reply Last reply
        0
        • HeinzH Offline
          HeinzH Offline
          Heinz
          Hero Member
          wrote on last edited by
          #5

          To be sure that the sensor works, you should download myscontroller from here : goo.gl/9DCWNo
          (http://forum.mysensors.org/topic/838/windows-gui-controller-for-mysensors/33)

          Edit the ini file and enter the ip and port of your mysensors-gateway or com port which depends on the type of gateway you are using.
          Start MysController and click the connect button.
          Now power on your sensor and check if the sensor is sending values.

          If everything is ok then something is wrong with your vera integration. If the sensor does not show up then something is wrong with your sensor. You can also send messages to your sensor with myscontroller to check if your incomming function works.

          1 Reply Last reply
          0
          • HeinzH Offline
            HeinzH Offline
            Heinz
            Hero Member
            wrote on last edited by
            #6

            Have a look at this lib
            https://code.google.com/p/rc-switch/

            CaptainZapC 1 Reply Last reply
            0
            • HeinzH Heinz

              Have a look at this lib
              https://code.google.com/p/rc-switch/

              CaptainZapC Offline
              CaptainZapC Offline
              CaptainZap
              wrote on last edited by CaptainZap
              #7

              @Heinz I've used that lib in both my tries (it works with their sketch, but not with mine), but I will try the windows GUI and see how that goes.

              LE: While bringing the serial gateway near my computer, I broke off the mini USB port (on the nano I was testing this), something dropped on it and all hell broke loose. I'll check it out tomorrow, but I would really appreciate if someone could take a look at my code. It has to be something I used incorrectly.

              1 Reply Last reply
              0
              • blaceyB Offline
                blaceyB Offline
                blacey
                Admin
                wrote on last edited by
                #8

                @CaptainZap I would start by trying to eliminate the st=fail: issue in your logs first. That is indicative of a wireless comm problem, at times indicating a message size failure. The root cause in my case was not due to software, but due to the circuit state which I corrected by power cycling, not hard resetting, to stabilize the current/radio.

                CaptainZapC 1 Reply Last reply
                0
                • blaceyB blacey

                  @CaptainZap I would start by trying to eliminate the st=fail: issue in your logs first. That is indicative of a wireless comm problem, at times indicating a message size failure. The root cause in my case was not due to software, but due to the circuit state which I corrected by power cycling, not hard resetting, to stabilize the current/radio.

                  CaptainZapC Offline
                  CaptainZapC Offline
                  CaptainZap
                  wrote on last edited by CaptainZap
                  #9

                  @blacey
                  Thanks for the feedback, today I started from scratch with a brand spanking new arduino nano ready for flashing. I ditched the temperature sensor part because yesterday I was being a bit too cocky, and rewrote the the sketch based on @Dwalt example combined with the TypeA_lightweight example from RC Switch and I can successfully say that I was able to control my switches !!!

                  YAY! , now how do I add the temperature part as I need to monitor two temperature sensors from the device.

                  FYI, this is the sketch I have that works :

                  #include <MySensor.h>
                  #include <SPI.h>  
                  #include <RF24.h>
                  
                  #define NUMBER_OF_OUTLETS 3 // Each outlet will have 2 OOK codes
                  #define SEND_DATA 3
                  
                  MySensor gw;
                  int RCLpin = 3;
                  
                  void RCLswitch(uint16_t code) {
                  for (int nRepeat=0; nRepeat<6; nRepeat++) {
                      for (int i=4; i<16; i++) {
                          RCLtransmit(1,3);
                          if (((code << (i-4)) & 2048) > 0) {
                              RCLtransmit(1,3);
                          } else {
                              RCLtransmit(3,1);
                          }
                      }
                      RCLtransmit(1,31);    
                  }
                  }
                  
                  void RCLtransmit(int nHighPulses, int nLowPulses) {
                  digitalWrite(RCLpin, HIGH);
                  delayMicroseconds( 350 * nHighPulses);
                  digitalWrite(RCLpin, LOW);
                  delayMicroseconds( 350 * nLowPulses);
                  }
                  
                  void setup() 
                  {
                  
                   //  The node is mains powered, so why not make it a repeater.
                   gw.begin(incomingMessage, AUTO, true);
                  
                   // Send the sketch version information to gateway
                   gw.sendSketchInfo("RF433", "0.1");
                  
                   pinMode(RCLpin, OUTPUT);
                  
                   // Register outlets to gw (they will be created as child devices)
                  for(int i=0; i<NUMBER_OF_OUTLETS;i++) {
                     gw.present(i+1, S_LIGHT);
                  
                   }
                  
                  }
                  
                  void loop() {
                    gw.process();
                  }
                    void incomingMessage(const MyMessage &message) {
                  
                    if (message.type==V_LIGHT) {
                    int incomingLightState =  message.getBool(); 
                    int incomingOutlet = message.sensor;
                  
                    Serial.print("Outlet #: ");
                    Serial.println(message.sensor);
                    Serial.print("Command: ");
                    Serial.println(message.getBool());
                  
                   if (incomingOutlet==1) {
                   if (incomingLightState==1) {
                  // Turn on  socket 1
                  Serial.println("Turn on Socket 1");
                   RCLswitch(0b101011000001);// These codes are unique to each outlet
                   delay(50); 
                   }
                   if (incomingLightState==0)  {
                  // Turn off socket 1
                   Serial.println("Turn off Socket 1");
                   RCLswitch(0b101011000010);
                   delay(50); 
                   }
                   }
                   if (incomingOutlet==2) {
                   if (incomingLightState==1) {
                  // Turn on  socket 2
                  Serial.println("Turn on Socket 2");
                   RCLswitch(0b101010100001);
                   delay(50); 
                   }
                   if (incomingLightState==0)  {
                  // Turn off socket 2
                   Serial.println("Turn off Socket 2");
                   RCLswitch(0b101010100010);
                   delay(50); 
                   }
                   }
                   if (incomingOutlet==3) {
                   if (incomingLightState==1) {
                  // Turn on  socket 3
                  Serial.println("Turn on Socket 3");
                   RCLswitch(0b101010010001);
                   delay(50); 
                   }
                   if (incomingLightState==0)  {
                  // Turn off socket 3
                   Serial.println("Turn off Socket 3");
                   RCLswitch(0b101010010010);
                   delay(50); 
                   }
                   }
                   }
                   delay(50);
                   }
                  
                  1 Reply Last reply
                  0
                  • CaptainZapC Offline
                    CaptainZapC Offline
                    CaptainZap
                    wrote on last edited by CaptainZap
                    #10

                    Just an update on this, I've spent several hours today but I was able to get the sketch to show up 1 temperature sensor, and then two temperature sensors. Now the problem I have is that the two temperature sensors display the same value. They are connected to different pins on the arduino, 4 and 5, and are not wired in parallel. This is the temperature sensor part :

                    OneWire oneWire(ONE_WIRE_BUS);
                    DallasTemperature DallasSensors(&oneWire);
                    float lastTemperature ;
                    float lastTemperature1 ;
                    #define CHILD_ID_T1 4 //CHILD ID for temperature sensor1
                    #define CHILD_ID_T2 5 //CHILD ID for temperature sensor2
                    
                    MyMessage tempMsg(CHILD_ID_T1,V_TEMP);
                    MyMessage tempMsg2(CHILD_ID_T2,V_TEMP);
                    
                    
                    void setup() 
                    {
                    
                    {...} // the lights part
                     gw.present(CHILD_ID_T1, S_TEMP);
                     gw.present(CHILD_ID_T2, S_TEMP);
                    }
                    
                    void loop() {
                      gw.process();
                      // Fetch temperatures from Dallas sensors
                    	DallasSensors.requestTemperatures();
                    	float tempC = DallasSensors.getTempCByIndex(1);
                                float tempD = DallasSensors.getTempCByIndex(2);
                    	
                    	// Only send data if temperature has changed and no error
                    	if (lastTemperature != tempC && tempC != -127.00) {
                    		
                    		// Send in the new temperature
                    		gw.send(tempMsg.set(tempC,1));
                    		lastTemperature=tempC;
                    	}  
                              // Only send data if temperature has changed and no error
                    	if (lastTemperature1 != tempD && tempD != -127.00) {
                    		
                    		// Send in the new temperature
                    		gw.send(tempMsg2.set(tempD,1));
                    		lastTemperature1=tempD;
                    	}
                    }
                    

                    Anyone got any hints ? I'm so close on finalizing this ! I've learned a lot over the last couple of days :D

                    LE: After writing this here I realized I didn't declare the second pin in the code and thus was using the same one. I've corrected that and this WAS IT !

                    1 Reply Last reply
                    0
                    • tbowmoT Offline
                      tbowmoT Offline
                      tbowmo
                      Admin
                      wrote on last edited by
                      #11

                      @CaptainZap

                      Why did you connect the two sensors to two different pins on the arduino? Onewire bus is exactly what it says, only a single wire, and a bus (meaning that it supports multiple devices)

                      you have

                      OneWire onewire(ONE_WIRE_BUS)
                      

                      ONE_WIRE_BUS is the pin that all your DS1820 sensors are connected to..

                      CaptainZapC 1 Reply Last reply
                      0
                      • tbowmoT tbowmo

                        @CaptainZap

                        Why did you connect the two sensors to two different pins on the arduino? Onewire bus is exactly what it says, only a single wire, and a bus (meaning that it supports multiple devices)

                        you have

                        OneWire onewire(ONE_WIRE_BUS)
                        

                        ONE_WIRE_BUS is the pin that all your DS1820 sensors are connected to..

                        CaptainZapC Offline
                        CaptainZapC Offline
                        CaptainZap
                        wrote on last edited by CaptainZap
                        #12

                        @tbowmo Because I don't know how to use the library correctly. I don't know how to display two sensors connected to the same port so I've done it how I knew. I am a beginner at coding and I know it can be simplified but this is as much as I know. I would like to see how you would do it :)

                        This is my last code for the temperature part:

                        #define ONE_WIRE_BUS 4 // Pin where dallas sensor is connected - on Rboard this is A0(D14)
                        #define ONE_WIRE_BUS2 5
                        OneWire oneWire(ONE_WIRE_BUS);
                        DallasTemperature DallasSensors(&oneWire);
                        
                        OneWire oneWire2(ONE_WIRE_BUS2);
                        DallasTemperature DallasSensors2(&oneWire2);
                        
                        float lastTemperature ;
                        float lastTemperature1 ;
                        #define CHILD_ID_T1 4 //CHILD ID for temperature sensor1
                        #define CHILD_ID_T2 5 //CHILD ID for temperature sensor2
                        
                        MyMessage tempMsg(CHILD_ID_T1,V_TEMP);
                        MyMessage tempMsg2(CHILD_ID_T2,V_TEMP);
                        
                        void setup() 
                        {
                        
                        {...} // the lights part
                         gw.present(CHILD_ID_T1, S_TEMP);
                         gw.present(CHILD_ID_T2, S_TEMP);
                        }
                        void loop() {
                          gw.process();
                          // Fetch temperatures from Dallas sensors
                        	DallasSensors.requestTemperatures();
                        	float tempC = DallasSensors.getTempCByIndex(1);
                                    DallasSensors2.requestTemperatures();
                                    float tempD = DallasSensors2.getTempCByIndex(1);
                        	
                        	// Only send data if temperature has changed and no error
                        	if (lastTemperature != tempC && tempC != -127.00) {
                        		
                        		// Send in the new temperature
                        		gw.send(tempMsg.set(tempC,1));
                        		lastTemperature=tempC;
                        	}  
                                  // Only send data if temperature has changed and no error
                        	if (lastTemperature1 != tempD && tempD != -127.00) {
                        		
                        		// Send in the new temperature
                        		gw.send(tempMsg2.set(tempD,1));
                        		lastTemperature1=tempD;
                        	}
                        }
                        
                        tbowmoT 1 Reply Last reply
                        0
                        • HeinzH Offline
                          HeinzH Offline
                          Heinz
                          Hero Member
                          wrote on last edited by Heinz
                          #13

                          Indexes usually start at 0 not at 1
                          try getTempCByIndex(0);

                          1 Reply Last reply
                          0
                          • CaptainZapC Offline
                            CaptainZapC Offline
                            CaptainZap
                            wrote on last edited by CaptainZap
                            #14

                            As per @Heinz suggestion I was able to use only one pin to get both temperature values, now I'm looking at lowering the refresh rate interval, now happens very fast. He suggested using millis(), but didn't help much.

                            Also I have one other question, I've noticed that when the node is on my desk (about 5 meters and 1 wall) from the gateway the RF switches no longer work, but the sensors do keep updating without any issues. I don't understand exactly why would this be the case.

                            LE: Seems that the issue with the RF is related to the power output from my USB port, I changed to a different one and it works without issue. Weird anyway.

                            1 Reply Last reply
                            0
                            • CaptainZapC CaptainZap

                              @tbowmo Because I don't know how to use the library correctly. I don't know how to display two sensors connected to the same port so I've done it how I knew. I am a beginner at coding and I know it can be simplified but this is as much as I know. I would like to see how you would do it :)

                              This is my last code for the temperature part:

                              #define ONE_WIRE_BUS 4 // Pin where dallas sensor is connected - on Rboard this is A0(D14)
                              #define ONE_WIRE_BUS2 5
                              OneWire oneWire(ONE_WIRE_BUS);
                              DallasTemperature DallasSensors(&oneWire);
                              
                              OneWire oneWire2(ONE_WIRE_BUS2);
                              DallasTemperature DallasSensors2(&oneWire2);
                              
                              float lastTemperature ;
                              float lastTemperature1 ;
                              #define CHILD_ID_T1 4 //CHILD ID for temperature sensor1
                              #define CHILD_ID_T2 5 //CHILD ID for temperature sensor2
                              
                              MyMessage tempMsg(CHILD_ID_T1,V_TEMP);
                              MyMessage tempMsg2(CHILD_ID_T2,V_TEMP);
                              
                              void setup() 
                              {
                              
                              {...} // the lights part
                               gw.present(CHILD_ID_T1, S_TEMP);
                               gw.present(CHILD_ID_T2, S_TEMP);
                              }
                              void loop() {
                                gw.process();
                                // Fetch temperatures from Dallas sensors
                              	DallasSensors.requestTemperatures();
                              	float tempC = DallasSensors.getTempCByIndex(1);
                                          DallasSensors2.requestTemperatures();
                                          float tempD = DallasSensors2.getTempCByIndex(1);
                              	
                              	// Only send data if temperature has changed and no error
                              	if (lastTemperature != tempC && tempC != -127.00) {
                              		
                              		// Send in the new temperature
                              		gw.send(tempMsg.set(tempC,1));
                              		lastTemperature=tempC;
                              	}  
                                        // Only send data if temperature has changed and no error
                              	if (lastTemperature1 != tempD && tempD != -127.00) {
                              		
                              		// Send in the new temperature
                              		gw.send(tempMsg2.set(tempD,1));
                              		lastTemperature1=tempD;
                              	}
                              }
                              
                              tbowmoT Offline
                              tbowmoT Offline
                              tbowmo
                              Admin
                              wrote on last edited by
                              #15

                              @CaptainZap said:

                              @tbowmo Because I don't know how to use the library correctly. I don't know how to display two sensors connected to the same port so I've done it how I knew. I am a beginner at coding and I know it can be simplified but this is as much as I know. I would like to see how you would do it :)

                              Take a look at the dallas example that comes with the mysensors library it supports multiple ds1820s.

                              http://www.mysensors.org/build/temp

                              Think that everything you need is there.

                              1 Reply Last reply
                              0
                              • HeinzH Offline
                                HeinzH Offline
                                Heinz
                                Hero Member
                                wrote on last edited by
                                #16

                                @CaptainZap I had the same problem with the range.
                                The sensor is able to send data to the gateway but the gateway fails to send commands to the sensor.
                                I found out that the maximum power level of the gateway sender is not set to maximum by default, but the
                                level of the sensor is. I simply changed the value before compiling the gateway in
                                MyConfig.h
                                #define RF24_PA_LEVEL_GW RF24_PA_MAX

                                CaptainZapC 1 Reply Last reply
                                0
                                • HeinzH Heinz

                                  @CaptainZap I had the same problem with the range.
                                  The sensor is able to send data to the gateway but the gateway fails to send commands to the sensor.
                                  I found out that the maximum power level of the gateway sender is not set to maximum by default, but the
                                  level of the sensor is. I simply changed the value before compiling the gateway in
                                  MyConfig.h
                                  #define RF24_PA_LEVEL_GW RF24_PA_MAX

                                  CaptainZapC Offline
                                  CaptainZapC Offline
                                  CaptainZap
                                  wrote on last edited by
                                  #17

                                  @Heinz Thanks for pointing that out, since I plan to have most if not all my sensors ac powered I'll change that.

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


                                  14

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.1k

                                  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