SI7021 with Nodemanager



  • Hi all, today i tested my SI7021 sensors and Nodemanager, but they not working very well.

    After power on sensor, i receive presentation of two channels (temp and humidity), but then i receive only V_TEMP updates and never recived V_HUM, have anyone working sketch with nodemanager or can check my code, i start from template from nodemanager examples, i also checked sensor with my MCP2221 I2C<>USB converter and here it works.

    /*
    * The MySensors Arduino library handles the wireless radio link and protocol
    * between your home built sensors/actuators and HA controller of choice.
    * The sensors forms a self healing radio network with optional repeaters. Each
    * repeater and gateway builds a routing tables in EEPROM which keeps track of the
    * network topology allowing messages to be routed to nodes.
    *
    * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
    * Copyright (C) 2013-2017 Sensnology AB
    * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    *
    * Documentation: http://www.mysensors.org
    * Support Forum: http://forum.mysensors.org
    *
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * version 2 as published by the Free Software Foundation.
    */
    
    /**************************
    Template
    
    This sketch can be used as a template since containing the most relevant MySensors library configuration settings, 
    NodeManager's settings, all its the supported sensors commented out and a sketch structure fully functional to operate with
    NodeManager. Just uncomment the settings you need and the sensors you want to add and configure the sensors in before()
    */
    
    /**********************************
     * MySensors node configuration
     */
    
    // General settings
    #define SKETCH_NAME "SI7021"
    #define SKETCH_VERSION "1.0"
    //#define MY_DEBUG
    #define MY_NODE_ID 100
    
    // NRF24 radio settings
    #define MY_RADIO_RF24
    //#define MY_RF24_ENABLE_ENCRYPTION
    //#define MY_RF24_CHANNEL 125
    //#define MY_RF24_PA_LEVEL RF24_PA_HIGH
    //#define MY_DEBUG_VERBOSE_RF24
    //#define MY_RF24_DATARATE RF24_250KBPS
    
    // RFM69 radio settings
    //#define MY_RADIO_RFM69
    //#define MY_RFM69_FREQUENCY RFM69_433MHZ
    //#define MY_IS_RFM69HW
    //#define MY_RFM69_NEW_DRIVER
    //#define MY_RFM69_ENABLE_ENCRYPTION
    //#define MY_RFM69_NETWORKID 100
    //#define MY_DEBUG_VERBOSE_RFM69
    //#define MY_RF69_IRQ_PIN D1
    //#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
    //#define MY_RF69_SPI_CS D2
    //#define MY_RFM69_ATC_MODE_DISABLED
    
    // RFM95 radio settings
    //#define MY_RADIO_RFM95
    //#define MY_RFM95_FREQUENCY (RFM95_868MHZ)
    //#define MY_DEBUG_VERBOSE_RFM95
    //#define MY_RFM95_MAX_POWER_LEVEL_DBM (20)
    //#define MY_RFM95_IRQ_PIN D1
    //#define MY_RFM95_IRQ_NUM MY_RFM95_IRQ_PIN
    //#define MY_RFM95_CS_PIN D8
    
    // RS485 serial transport settings
    //#define MY_RS485
    //#define MY_RS485_BAUD_RATE 9600
    //#define MY_RS485_DE_PIN 2
    //#define MY_RS485_MAX_MESSAGE_LENGTH 40
    //#define MY_RS485_HWSERIAL Serial1
    
    // Message signing settings
    //#define MY_SIGNING_SOFT
    //#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
    //#define MY_SIGNING_REQUEST_SIGNATURES
    //#define MY_SIGNING_ATSHA204
    //#define MY_SIGNING_ATSHA204_PIN 4
    //#define MY_SIGNING_REQUEST_SIGNATURES
    
    // OTA Firmware update settings
    //#define MY_OTA_FIRMWARE_FEATURE
    //#define OTA_WAIT_PERIOD 300
    //#define FIRMWARE_MAX_REQUESTS 2
    //#define MY_OTA_RETRY 2
    
    // OTA debug output
    //#define MY_DEBUG_OTA (0)
    //#define MY_OTA_LOG_SENDER_FEATURE
    //#define MY_OTA_LOG_RECEIVER_FEATURE
    //#define MY_DEBUG_OTA_DISABLE_ACK
    
    // Advanced settings
    //#define MY_BAUD_RATE 9600
    //#define MY_SMART_SLEEP_WAIT_DURATION_MS 500
    #define MY_SPLASH_SCREEN_DISABLED
    //#define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE
    //#define MY_SIGNAL_REPORT_ENABLED
    
    // Optimizations when running on 2032 Coin Cell. Also set nodeManager.setSleepBetweenSend(500) and run the board at 1Mhz
    #define MY_TRANSPORT_UPLINK_CHECK_DISABLED
    //#define MY_TRANSPORT_WAIT_READY_MS  5000
    //#define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 2000
    //#define MY_PARENT_NODE_ID 0
    //#define MY_PARENT_NODE_IS_STATIC
    
    /**********************************
     * MySensors gateway configuration
     */
     
    // Common gateway settings
    //#define MY_REPEATER_FEATURE
    
    // Serial gateway settings
    //#define MY_GATEWAY_SERIAL
    
    // Ethernet gateway settings
    //#define MY_GATEWAY_W5100
    
    // ESP8266 gateway settings
    //#define MY_GATEWAY_ESP8266
    //#define MY_ESP8266_SSID ""
    //#define MY_ESP8266_PASSWORD ""
    
    // Gateway networking settings
    //#define MY_IP_ADDRESS 192,168,178,87
    //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    //#define MY_PORT 5003
    //#define MY_GATEWAY_MAX_CLIENTS 2
    //#define MY_USE_UDP
    
    // Gateway MQTT settings
    //#define MY_GATEWAY_MQTT_CLIENT
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
    //#define MY_PORT 1883
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    //#define MY_MQTT_CLIENT_ID "mysensors-1"
    //#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    //#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Gateway inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    //#define MY_INCLUSION_BUTTON_FEATURE
    //#define MY_INCLUSION_MODE_DURATION 60
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Gateway Leds settings
    //#define MY_DEFAULT_ERR_LED_PIN 4
    //#define MY_DEFAULT_RX_LED_PIN  5
    //#define MY_DEFAULT_TX_LED_PIN  6
    
    /***********************************
     * NodeManager configuration
     */
    
    #define NODEMANAGER_DEBUG OFF
    #define NODEMANAGER_INTERRUPTS OFF
    #define NODEMANAGER_SLEEP ON
    #define NODEMANAGER_RECEIVE OFF
    #define NODEMANAGER_DEBUG_VERBOSE OFF
    #define NODEMANAGER_POWER_MANAGER OFF
    #define NODEMANAGER_CONDITIONAL_REPORT OFF
    #define NODEMANAGER_EEPROM OFF
    #define NODEMANAGER_TIME OFF
    #define NODEMANAGER_RTC OFF
    #define NODEMANAGER_SD OFF
    #define NODEMANAGER_HOOKING OFF
    #define NODEMANAGER_OTA_CONFIGURATION OFF
    #define NODEMANAGER_SERIAL_INPUT OFF
    
    // import NodeManager library (a nodeManager object will be then made available)
    #include <MySensors_NodeManager.h>
    
    /***********************************
     * Add your sensors
     */
    
    #include <sensors/SensorSI7021.h>
    SensorSI7021 si7021;
    
    /***********************************
     * Main Sketch
     */
    
    // before
    void before() {
    	
      /***********************************
       * Configure your sensors
       */
      // EXAMPLES:
      // report measures of every attached sensors every 10 seconds
      nodeManager.setReportIntervalSeconds(10);
      // report measures of every attached sensors every 10 minutes
      //nodeManager.setReportIntervalMinutes(10);
      // set the node to sleep in 30 seconds cycles
      //nodeManager.setSleepSeconds(30);
      // set the node to sleep in 5 minutes cycles
      //nodeManager.setSleepMinutes(5);
      // report battery level every 10 minutes
      //battery.setReportIntervalMinutes(60);
      // set an offset to -1 to a thermistor sensor
      //thermistor.setOffset(-1);
      // change the id of a the first child of a sht21 sensor
      //sht21.children.get(1)->setChildId(5);
      // report only when the analog value is above 40%
      //analog.children.get(1)->setMinThreshold(40);
      // power all the nodes through dedicated pins
      //nodeManager.setPowerManager(power);
    
      // call NodeManager before routine
      nodeManager.before();
    }
    
    // presentation
    void presentation() {
      // call NodeManager presentation routine
      nodeManager.presentation();
    }
    
    // setup
    void setup() {
      // call NodeManager setup routine
      nodeManager.setup();
    }
    
    // loop
    void loop() {
      // call NodeManager loop routine
      nodeManager.loop();
    }
    
    #if NODEMANAGER_RECEIVE == ON
    // receive
    void receive(const MyMessage &message) {
      // call NodeManager receive routine
      nodeManager.receive(message);
    }
    #endif
    
    #if NODEMANAGER_TIME == ON
    // receiveTime
    void receiveTime(unsigned long ts) {
      // call NodeManager receiveTime routine
      nodeManager.receiveTime(ts);
    }
    #endif
    
    

    at compilig i got two warnings:

    In file included from C:\Users\Libor\Documents\Arduino\libraries\NodeManager-master/MySensors_NodeManager.h:87:0,
                     from C:\Users\Libor\Documents\Arduino\projects\NodeManager_test\NodeManager_test.ino:176:
    C:\Users\Libor\Documents\Arduino\libraries\NodeManager-master/nodemanager/Sensor.cpp: In member function 'void Sensor::presentation()':
    C:\Users\Libor\Documents\Arduino\libraries\NodeManager-master/nodemanager/Sensor.cpp:135:54: warning: invalid conversion from 'uint8_t {aka unsigned char}' to 'mysensors_sensor_t' [-fpermissive]
       present(child->getChildId(), child->getPresentation(), child->getDescription(), nodeManager.getAck());
                                    ~~~~~~~~~~~~~~~~~~~~~~^~
    In file included from C:\Users\Libor\Documents\Arduino\libraries\MySensors/MySensors.h:433:0,
                     from C:\Users\Libor\Documents\Arduino\libraries\NodeManager-master/MySensors_NodeManager.h:43,
                     from C:\Users\Libor\Documents\Arduino\projects\NodeManager_test\NodeManager_test.ino:176:
    C:\Users\Libor\Documents\Arduino\libraries\MySensors/core/MySensorsCore.cpp:375:6: note:   initializing argument 2 of 'bool present(uint8_t, mysensors_sensor_t, const char*, bool)'
     bool present(const uint8_t childSensorId, const mysensors_sensor_t sensorType,
          ^~~~~~~
    
    


  • I changed to development version of Nodemanager this remove compilation errors and then found that recomended library from Sparkfun not work. Then i edited header file SensorSI7021.h to work with Adafruit library and it works 🙂
    my SensorSI7021.h:

    /*
    * The MySensors Arduino library handles the wireless radio link and protocol
    * between your home built sensors/actuators and HA controller of choice.
    * The sensors forms a self healing radio network with optional repeaters. Each
    * repeater and gateway builds a routing tables in EEPROM which keeps track of the
    * network topology allowing messages to be routed to nodes.
    *
    * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
    * Copyright (C) 2013-2017 Sensnology AB
    * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    * 2021 modified by Libor Kozak to work with Adafruit library: https://github.com/adafruit/Adafruit_Si7021
    *
    * Documentation: http://www.mysensors.org
    * Support Forum: http://forum.mysensors.org
    *
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * version 2 as published by the Free Software Foundation.
    */
    #ifndef SensorSI7021_h
    #define SensorSI7021_h
    
    /*
    SensorSI7021: temperature and humidity sensor
    */
    
    #include <Wire.h>
    //#include <SI7021.h>
    #include <Adafruit_Si7021.h>
    
    class SensorSI7021: public Sensor {
    protected:
    	Adafruit_Si7021* _si7021;//SI7021* _si7021;
    	
    public:
    	SensorSI7021(uint8_t child_id = 0): Sensor(-1) {
    		_name = "SI7021";
    		children.allocateBlocks(2);
    		new Child(this,FLOAT,nodeManager.getAvailableChildId(child_id),S_TEMP,V_TEMP,_name);
    		new Child(this,FLOAT,child_id > 0 ? nodeManager.getAvailableChildId(child_id+1) : nodeManager.getAvailableChildId(child_id),S_HUM,V_HUM,_name);
    	};
    	
    	// define what to do during setup
    	void onSetup() {
    		_si7021 = new Adafruit_Si7021();
    		_si7021->begin();
    	};
    
    	// define what to do during loop
    	void onLoop(Child* child) {
    		// temperature sensor
    		if (child->getType() == V_TEMP) {
    			// read the temperature
    			float temperature = _si7021->readTemperature();
    			// convert it
    			//temperature = nodeManager.celsiusToFahrenheit(temperature);
    			// store the value
    			child->setValue(temperature);
    		}
    		// Humidity Sensor
    		else if (child->getType() == V_HUM) {
    			// read humidity
    			float humidity = _si7021->readHumidity();
    			// store the value
    			child->setValue(humidity);
    		}
    	};
    };
    #endif
    

Log in to reply
 

Suggested Topics

  • 2
  • 1
  • 2
  • 16
  • 1
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts