Sensors on Gateway?



  • Just getting started with mysensors and would like to know if its possible to have sensors directly attached to the gateway arduino? I cant find any examples of such a configuration but seems like it might be useful in certain situations.

    Thanks in advance!


  • Admin

    Not right now. Working on it.



  • Wow amazing prompt reply! I thought that might be the case as i could find any documentation. Thanks for the reply though. 🙂



  • @hek said:

    Not right now. Working on it.

    hello Hek.. any news or timeframe on having a sensor on the gateway?

    Thanks!


  • Admin

    You can do it right now using the development branch.



  • haha.. time to give it a shot! thanks



  • Hello again Hek,

    Just one more question... how? I have crated a serial gateway following this http://www.mysensors.org/build/serial_gateway#wiring-things-up
    and then added the relavent parts from here http://www.mysensors.org/build/humidity

    but am not getting anything showing up in my controller (MyContoller.org). am I on the right path, or going in the wrong direction?

    here is my code for reference

    #define NO_PORTB_PINCHANGES  
    
    #include <MySigningNone.h>
    #include <MyTransportRFM69.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningAtsha204.h>
    
    #include <SPI.h>  
    #include <MyParserSerial.h>  
    #include <MySensor.h>  
    #include <stdarg.h>
    #include <PinChangeInt.h>
    #include "GatewayUtil.h"
    #include <DHT.h> 
    
    #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
    #define INCLUSION_MODE_PIN  3 // Digital pin used for inclusion mode button
    #define RADIO_ERROR_LED_PIN 4  // Error led pin
    #define RADIO_RX_LED_PIN    6  // Receive led pin
    #define RADIO_TX_LED_PIN    5  // the PCB, on board LED
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 22
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    //MyTransportRFM69 transport;
    
    // 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
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
    int inputPos = 0;
    boolean commandComplete = false;  // whether the string is complete
    
    void parseAndSend(char *commandBuffer);
    
    void output(const char *fmt, ... ) {
       va_list args;
       va_start (args, fmt );
       vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
       va_end (args);
       Serial.print(serialBuffer);
    }
    
      
    void setup()  
    { 
      gw.begin(incomingMessage, 0, true, 0);
    
      setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
    
      // Add interrupt for inclusion button to pin
      PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
    
    
      // Send startup log message on serial
      serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
    
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      gw.sendSketchInfo("Humidity", "1.0");
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      metric = gw.getConfig().isMetric;
    }
    
    void loop()  
    { 
      gw.process();
    
      checkButtonTriggeredInclusion();
      checkInclusionFinished();
      
      if (commandComplete) {
        // A command wass issued from serial interface
        // We will now try to send it to the actuator
        parseAndSend(gw, inputString);
        commandComplete = false;  
        inputPos = 0;
      }
      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);
        }
        gw.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;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
    }
    
    
    /*
      SerialEvent occurs whenever a new data comes in the
     hardware serial RX.  This routine is run between each
     time loop() runs, so using delay inside loop can delay
     response.  Multiple bytes of data may be available.
     */
    void serialEvent() {
      while (Serial.available()) {
        // get the new byte:
        char inChar = (char)Serial.read(); 
        // if the incoming character is a newline, set a flag
        // so the main loop can do something about it:
        if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) { 
          if (inChar == '\n') {
            inputString[inputPos] = 0;
            commandComplete = true;
          } else {
            // add it to the inputString:
            inputString[inputPos] = inChar;
            inputPos++;
          }
        } else {
           // Incoming message too long. Throw away 
            inputPos = 0;
        }
      }
    }
    
    
    
    

  • Admin

    This looks like code from master branch (1.5). Make sure to download and install the development branch. Then Just take the humidity example and add:

    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    

    And remove the MY_RADIO_NRF24 define if you don't have any radio attached.



  • Tanks for that. I have it all working now! And also thanks for the quick reply!



  • I have also tested this and it is working fine with the humidity sensor code(Both on the serial monitor and with Domoticz) but i have also tried the AirQuality sensor code but i cannot make it work . I can see in Serial monitor the values but when i connect the gateway (with the Attached AirQuality) to Domoticz i cannot see any sensor.



  • I wonder why do we have to use the a development branch instead of master?
    If I want to disable the radio (because I don't have it yet on my serial gateway connected to the controller via usb) so why it is not possible on the master branch?

    Maybe it is possible to comment out few definitions in myconfig.h or somewhere else in source cpp code?


  • Admin

    @Alex-B-Goode

    The code that made it possible to have sensors directly on the GW, is only available in development branch, and haven't been migrated to master branch.

    You could always emulate the serial protocol on the GW your self, and inject that in the sensor data stream. But depending on the MCU you are using, you might run your head against the flash size wall..


Log in to reply
 

Suggested Topics

  • 87
  • 3
  • 1
  • 10
  • 5
  • 7

25
Online

11.4k
Users

11.1k
Topics

112.7k
Posts