Some beginner questions



  • So I'm trying my first SerialGateway with a attached temp sensor. This is my sketch:

    // Enable serial gateway
    #define MY_GATEWAY_SERIAL 
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    //Temperatur sensor
    #define TEMP_SENSOR_ID 1 // childId
    #define ONE_WIRE_BUS 5
    #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
    float lastTemperature = 0;
    MyMessage tempMsg(0, V_TEMP); // Initialize temperature message
    OneWire oneWire(ONE_WIRE_BUS); 
    DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 
    unsigned long SLEEP_TIME = 4000; // Sleep time between reads (in milliseconds)
    
    void setup(void)
    {
    	// start serial port
    	Serial.begin(115200);
    }
    
    void presentation() 
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Temperature Sensor", "1.1");
    
    	present(TEMP_SENSOR_ID, S_TEMP);
    }
    
    void loop(void)
    { 
    	DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address    
    
    	// For testing purposes, reset the bus every loop so we can see if any devices appear or fall off
    	sensors.begin();
       
    	sensors.requestTemperatures(); // Send the command to get temperatures
    	
    	// Search the wire for address
       if(sensors.getAddress(tempDeviceAddress, 0))
       {
    		float tempC = sensors.getTempC(tempDeviceAddress);
    		
    		Serial.print("Temperature=");
    		Serial.println(tempC); 
    
    		// Only send data if temperature has changed and no error
    #if COMPARE_TEMP == 1
    		if (lastTemperature != tempC && tempC != -127.00 && tempC != 85.00)
    		{
    #else
    		if (tempC != -127.00 && tempC != 85.00)
    		{
    #endif
    			// Send in the new temperature
    			send(tempMsg.setSensor(0).set(tempC, 1));
    			// Save new temperatures for next compare
    			lastTemperature = tempC;
    		}
       } 
           
    	delay(SLEEP_TIME);
    }
    

    And now the questions:

    1. The node has a Unknown sketch name in Domoticz. Why?
    2. When I select the node in Domotics I see one child as expected, but the Type is Unknown and the Name is empty. (Even though I have given the sensor a name in the Devices view)

    After having used Domoticz for only a few days, and only testing things, it already feels like Domoticz is not very intuitive. Maybe powerful, but the design and usage is all but user friendly.



  • The above two questions remain. But I have modified my sketch, and also thought I should test things in MYSController first, to keep it simple.
    And I think that the presentation function never executes. Do I have to do something manually to initiate it? The reason I think it is not executed is not only that I don't get a sketch name, but I also added a relay. And even though I present it it don't appear in MYSController. The only sensor that appears is the temp, and probably only because it sends values.

    // Enable serial gateway
    #define MY_GATEWAY_SERIAL 
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    #define TEMP_ID 1
    #define RELAY_ID 2
    
    //Temperatur sensor
    #define ONE_WIRE_BUS 4
    #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
    float lastTemperature = 0;
    MyMessage tempMsg(TEMP_ID, V_TEMP); // Initialize temperature message
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices 
    DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 
    unsigned long SLEEP_TIME = 4000; // Sleep time between reads (in milliseconds)
    
    #define RELAY_PIN  5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    void setup(void)
    {
    	// start serial port
    	Serial.begin(115200);
    
    	pinMode(RELAY_PIN, OUTPUT);
    	digitalWrite(RELAY_PIN, RELAY_OFF);
    }
    
    void presentation() 
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Temperature Sensor", "1.1");
    
    	present(TEMP_ID, S_TEMP);
    
    	present(RELAY_ID, S_BINARY);
    }
    
    void loop(void)
    { 
    	DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address    
    
    	// For testing purposes, reset the bus every loop so we can see if any devices appear or fall off
    	sensors.begin();
       
    	sensors.requestTemperatures(); // Send the command to get temperatures
    	
    	// Search the wire for address
       if(sensors.getAddress(tempDeviceAddress, 0))
       {
    		float tempC = sensors.getTempC(tempDeviceAddress);
    		
    		// Only send data if temperature has changed and no error
    #if COMPARE_TEMP == 1
    		if (lastTemperature != tempC && tempC != -127.00 && tempC != 85.00)
    		{
    #else
    		if (tempC != -127.00 && tempC != 85.00)
    		{
    #endif
    			// Send in the new temperature
    			send(tempMsg.set(tempC, 1));
    			// Save new temperatures for next compare
    			lastTemperature = tempC;
    		}
       } 
    
    	delay(SLEEP_TIME);
    }
    
    void receive(const MyMessage &message) 
    {
    	// We only expect one type of message from controller. But we better check anyway.
    	if (message.type == V_LIGHT) 
    	{
    		// Change relay state
    		digitalWrite(RELAY_ID, message.getBool() ? RELAY_ON : RELAY_OFF);
    		// Write some debug info
    		Serial.print("Incoming change for sensor:");
    		Serial.print(message.sensor);
    		Serial.print(", New status: ");
    		Serial.println(message.getBool());
    	}
    }

  • Contest Winner

    @raptorjr Not exactly sure what you mean by I don't see a sketch name. With the sensKetchInfo() in the presentation() method you should be able to see "Temperature Sensor" as the node name in the MySensors gateway settings under hardware in Domoticz (I'm doing does out of my head, but it's how I remebered it )

    If you want to be able to see a description of each individual Child of the node, you have to present i with a description:

    present(TEMP_ID, S_TEMP, "My temp", true ); // turn true in false if you don't want ACKs
    present(RELAY_ID, S_BINARY, "My relais", true ); // turn true in false if you don't want ACKs
    

    As concerning you're last question, try to present it as a S_LIGHT. That might help.

    present(RELAY_ID, S_LIGHT, "My relais", true ); // turn true in false if you don't want ACKs
    

    In my experience it's better to solve a problem first, before adding more functionality. But that's just how I do things.



  • @TheoL

    Thank you for your help.

    I thought that I read in the 2.0 release that S_BINARY should be used instead if S_LIGHT?

    By not seeing a sketch name I meant when I press Setup on my added gateway and see a list with my nodes. Sketch name is Unknown and version is 1.0. Not the same as I have in in my sketch "sendSketchInfo("Temperature Sensor", "1.1");"

    Besides the sketch name I thought I had it working, since I got values from my temperature sensor. That is why I added the relay. But since the relay don't appear I realize that the only reason I saw the temperature sensor is because it sends values and was therefore added as a sensor. But a relay don't send values and don't appear since presentation is not executing. (Or something like that.)

    	sendSketchInfo("Temperature Sensor", "1.1");
    
    	present(TEMP_ID, S_TEMP, "Water temperature", true);
    
    	present(RELAY_ID, S_LIGHT, "Water valve", true);
    

    After changing to this I still don't see the relay and don't get the descriptions of the sensor/relay in neither Domoticz or MYSController.
    I am probably missing something simple. I can't imagine it should be this hard to get things working.


  • Contest Winner

    @raptorjr I still haven't played with 2.0 so if docs S_BINARY should be okay. It might be because of MS 2.0 that you experience problems. But since nothing in the serial protocol has changed I doubt. My suggestions work for me in Domoticz for more than 1 year now. So I'm all out of clues.

    Also an S_LIGHT or S_BINARY should appear in Domoticz, because they're treated as actuators. An actuator doesn't always send states back to domoticz, so they should appear.

    Anyway hope someone else can help you.


  • Plugin Developer

    There's a bug in 2.0.0 where a gateway with no radio feature defined does not present itself or local sensors. This has been fixed in the dev branch of mysensors at github.



  • Cool, will try when I get home. Not easy when you are a beginner. Thinking everything is my fault 😃



  • @martinhjelmare

    I choose to download zip from Github. Removed the folder MySensors from libraries, where the Arduino IDE had downloaded and installed the version that is available from the IDE.

    I then unpacked the zip and renamed the folder from MySensors-master to MySensors. I rebuilt my sketch and tried it. But still, presentation function is not executed.

    I have this presentation function:

    void presentation() 
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Temperature Sensor", "1.1");
    
    	present(TEMP_ID, S_TEMP, "Water temperature", true);
    
    	present(RELAY_ID, S_LIGHT, "Water valve", true);
    
    	Serial.println("presentation");
    
    }
    

    But this is what I get in the serial monitor:

    Port closed
    Opening port
    Port open
    0;255;3;0;14;Gateway startup complete.
    0;1;1;0;0;25.9
    0;1;1;0;0;25.9
    

    Never get a presentation message. So the presentation function is never executed. Is there anything else I need to do or have done wrong?



  • Don't know what I did wrong, but I didn't get the latest git version. I guess I somehow downloaded 2.0 again. But after some investigation I got the latest version and everything seems to be working now 😃

    Thank you for your help.


Log in to reply
 

Suggested Topics

  • 5
  • 8
  • 1
  • 5
  • 5
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.6k
Posts