Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. tandobkhcm
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by tandobkhcm

    • Building a MQTT Gateway

      Hi Guys! I'm newbie.I want to do smarthome with MQTT and OpenHab. I start to build a MQTT Gateway (Ethernet Shield w5100). This result :

      alt text

      it's working?. i don't see line "Sending message on topic: mygateway1-out/2/1/1/0/49"

      My Sketch :

      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enables and select radio type (if attached)
      //#define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_GATEWAY_MQTT_CLIENT
      
      // Set this node's subscribe and publish topic prefix
      #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out/2/1/1/0/49"
      #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in/2/1/1/0/49"
      
      // Set MQTT client id
      #define MY_MQTT_CLIENT_ID "mysensors-1"
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // 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.
      //#if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
       // #define MY_SOFTSPI
       // #define MY_SOFT_SPI_SCK_PIN 14
      //  #define MY_SOFT_SPI_MISO_PIN 16
       // #define MY_SOFT_SPI_MOSI_PIN 15
      //#endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
       // #ifndef MY_RF24_CE_PIN
        //#define MY_RF24_CE_PIN 5
        //#endif
        //#ifndef MY_RF24_CS_PIN
       // #define MY_RF24_CS_PIN 6
      //#endif
      
      // Enable these if your MQTT broker requires usenrame/password
      //#define MY_MQTT_USER "username"
      //#define MY_MQTT_PASSWORD "password"
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      #define MY_IP_ADDRESS 192,168,10,103
      
      // If using static ip you need to define Gateway and Subnet address as well
      #define MY_IP_GATEWAY_ADDRESS 192,168,10,1
      #define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      // MQTT broker ip address or url. Define one or the other.
      //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
      #define MY_CONTROLLER_IP_ADDRESS 192, 168, 10, 102
      
      // The MQTT broker port to to open
      #define MY_PORT 1883
      
       /*
      // 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
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
      */
      
      #include <Ethernet.h>
      #include <MySensors.h>
      #include <SPI.h>
      #include <DHT.h>
      
      // set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 2
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      // Sleep time between sensor updates (in milliseconds)
      // Must be >1000ms for DHT22 and >2000ms for DHT11
      static const uint64_t UPDATE_INTERVAL = 30000;
      
      // Force sending an update of the temperature after n sensor reads, so a controller showing the
      // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
      // the value didn't change since;
      // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      bool metric = true;
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      DHT dht;
      
      void setup() {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
        }
        // Sleep for the time of the minimum sampling period to give the sensor time to power up
        // (otherwise, timeout errors might occure for the first reading)
        sleep(dht.getMinimumSamplingPeriod());
      }
      
      void presentation() {
        // Present locally attached sensors here
        // Send the sketch version information to the gateway
        sendSketchInfo("TemperatureAndHumidity", "1.1");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
      
        metric = getConfig().isMetric;
      }
      
      
      void loop() {
        // Send locally attached sensors data here
        // Force reading sensor, so it works also after sleep()
        dht.readSensor(true);
      
        // Get temperature from DHT library
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT!");
        } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          // Reset no updates counter
          nNoUpdatesTemp = 0;
          temperature += SENSOR_TEMP_OFFSET;
          send(msgTemp.set(temperature, 1));
      
          #ifdef MY_DEBUG
          Serial.print("T: ");
          Serial.println(temperature);
          #endif
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
      
        // Get humidity from DHT library
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 1));
      
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
        } else {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
      
        // Sleep for a while to save energy
        sleep(UPDATE_INTERVAL);
      }
      

      i combine sketch "humiditysensor" and " MQTTGateway". is it right?
      thank you for help !

      posted in Troubleshooting
      tandobkhcm
      tandobkhcm
    • RE: partial upgrade of nodes to v2.0 library?

      Hi @abrasha ! I'm doing this tutorial "http://www.makeuseof.com/tag/diy-smart-home-sensors-arduino-mysensors-openhab/" . but i have many problem because humiditysensors is not have in mysensors v2.0. i found humiditysensor in v1.5.4 and convert skecth to v2.0 but it's not working. Can you send me your code if it's working?. thanks

      posted in Development
      tandobkhcm
      tandobkhcm
    • RE: Problems with Node sensor

      Hi @mfalkvidd !. Thank you for that infomations. I'll read https://ci.mysensors.org/job/Verifiers/job/MySensorsArduino/branch/development/Doxygen_HTML/group__MyTransportgrp.html#details.

      After I convert Mysensors 1.5.x -> 2.0 it's probably working. But i don't see temperature and humidity to display serial monitor
      alt text

      My code for Humiditysensor :

      #define MY_NODE_ID 1 // Sets a static id for a node
      
      #define MY_DEBUG    // Enables debug messages in the serial log
      
      #define MY_RF24_CE_PIN 9    // Radio specific settings for RF24
      #define MY_RF24_CS_PIN 10 // Radio specific settings for RF24 (you'll find similar config for RFM69)
      
      
       //Enabdle if use NRF24
       #define MY_RADIO_NRF24
       //Enable if use RFM69
       //#define MY_RADIO_RFM69
       //Enable iff use RS485
       //#define MY_RS485
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <DHT.h>  
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define HUMIDITY_SENSOR_DIGITAL_PIN 2
      unsigned long SLEEP_TIME = 30000; // 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);
      
      
      void presentation()  
      { 
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // Send the Sketch Version Information to the Gateway
        sendSketchInfo("Humidity", "1.0");
      
        // Register all sensors (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        
        metric = getConfig().isMetric;
      }
      
      void loop()      
      {  
        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);
        }
      
        sleep(SLEEP_TIME); //sleep a bit
      }
      
      

      For gateway

      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enables and select radio type (if attached)
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_GATEWAY_MQTT_CLIENT
      
      // Set this node's subscribe and publish topic prefix
      #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
      #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
      
      // Set MQTT client id
      #define MY_MQTT_CLIENT_ID "mysensors-1"
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // 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.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
        #define MY_SOFTSPI
        #define MY_SOFT_SPI_SCK_PIN 14
        #define MY_SOFT_SPI_MISO_PIN 16
        #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
        #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
        #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable these if your MQTT broker requires usenrame/password
      //#define MY_MQTT_USER "username"
      //#define MY_MQTT_PASSWORD "password"
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      #define MY_IP_ADDRESS 192,168,10,103
      
      // If using static ip you need to define Gateway and Subnet address as well
      #define MY_IP_GATEWAY_ADDRESS 192,168,10,1
      #define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      // MQTT broker ip address or url. Define one or the other.
      //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
      #define MY_CONTROLLER_IP_ADDRESS 192, 168, 10, 102
      
      // The MQTT broker port to to open
      #define MY_PORT 1883
      
       /*
      // 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
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
      */
      
      #include <Ethernet.h>
      #include <MySensors.h>
      
      void setup() {
      }
      
      void presentation() {
        // Present locally attached sensors here
      }
      
      
      void loop() {
        // Send locally attached sensors data here
      }
      

      My router
      alt text

      posted in Troubleshooting
      tandobkhcm
      tandobkhcm
    • Problems with Node sensor

      Hello guys!. I got tutorial "http://www.makeuseof.com/tag/diy-smart-home-sensors-arduino-mysensors-openhab/". But i didn't see humiditysensor in library. Then, i got code from https://www.mysensors.org/build/humidity and uploaded sketch on my sensors node and serial monitor look like this alt text
      and
      alt text
      it's different to what i see in tutorial alt text
      what is "st=bc"?
      Thank you for taking the time to help and sorry because my English is not good.

      posted in Troubleshooting
      tandobkhcm
      tandobkhcm