Problem with MQTT

Begonnen von chdid, 22 August 2015, 15:17:58

Vorheriges Thema - Nächstes Thema

chdid

Hello,

I have a problem with MQTT module.

I have two devices : panstamp and netatmo.

For the panstamp, I can publish on the topics. No problem.



# Panstamp
define panstampLesLilas panStamp /dev/ttyAMA0@38400
define node_debordementEAU_cuisine SWAP 1D
attr node_debordementEAU_cuisine IODev panstampLesLilas
attr node_debordementEAU_cuisine ProductCode 0000001E00000002
attr node_debordementEAU_cuisine room cuisine
attr node_debordementEAU_cuisine userReadings voltage:0B {hex(ReadingsVal($name,"0B-Voltage","0"))*0.001}

# MQTT
define MQTT_connect MQTT test.mosquitto.org:1883
define MQTT_eauCuisine MQTT_BRIDGE node_debordementEAU_cuisine
attr MQTT_eauCuisine IODev MQTT_connect
attr MQTT_eauCuisine publish-topic-base nodeCuisine/
attr MQTT_eauCuisine publishReading_0C-EauS0 nodeCuisine/debordementEauLavelinge
attr MQTT_eauCuisine publishReading_0D-EauS1 nodeCuisine/debordementEauLavaisselle
attr MQTT_eauCuisine publishReading_voltage nodeCuisine/voltage
attr MQTT_eauCuisine room cuisine
attr MQTT_eauCuisine stateFormat transmission-state



and the log

2015.08.22 14:55:55 5: panstampLesLilas: 001D00C3001D0C00 -43 48
2015.08.22 14:55:55 5: panstampLesLilas dispatch 001D00C3001D0C00
2015.08.22 14:55:56 4: node_debordementEAU_cuisine -> broadcast (0,0-C3): status node_debordementEAU_cuisine 0C:00
2015.08.22 14:55:56 5: Triggering node_debordementEAU_cuisine (1 changes)
2015.08.22 14:55:56 5: Notify loop for node_debordementEAU_cuisine 0C-EauS0: 00
2015.08.22 14:55:56 5: Notify for node_debordementEAU_cuisine
2015.08.22 14:55:56 5: 0C-EauS0: 00, '0C-EauS0', '00'
2015.08.22 14:55:56 5: MQTT MQTT_connect message sent: Publish/at-most-once nodeCuisine/debordementEauLavelinge
  30 30                                            00
2015.08.22 14:55:56 5: SW: 302700236e6f646543756973696e652f6465626f7264656d656e744561754c6176656c696e67653030
2015.08.22 14:55:56 5: Triggering MQTT_eauCuisine (1 changes)
2015.08.22 14:55:56 5: Notify loop for MQTT_eauCuisine transmission-state: outgoing publish sent
2015.08.22 14:55:56 5: panstampLesLilas: 001D00C4001D0D00 -43.5 48
2015.08.22 14:55:56 5: panstampLesLilas dispatch 001D00C4001D0D00
2015.08.22 14:55:56 4: node_debordementEAU_cuisine -> broadcast (0,0-C4): status node_debordementEAU_cuisine 0D:00
2015.08.22 14:55:56 5: Triggering node_debordementEAU_cuisine (1 changes)
2015.08.22 14:55:56 5: Notify loop for node_debordementEAU_cuisine 0D-EauS1: 00
2015.08.22 14:55:56 5: Notify for node_debordementEAU_cuisine
2015.08.22 14:55:56 5: 0D-EauS1: 00, '0D-EauS1', '00'
2015.08.22 14:55:56 5: MQTT MQTT_connect message sent: Publish/at-most-once nodeCuisine/debordementEauLavaisselle
  30 30                                            00
2015.08.22 14:55:56 5: SW: 302900256e6f646543756973696e652f6465626f7264656d656e744561754c617661697373656c6c653030
2015.08.22 14:55:56 5: Triggering MQTT_eauCuisine (1 changes)
2015.08.22 14:55:56 5: Notify loop for MQTT_eauCuisine transmission-state: outgoing publish sent
2015.08.22 14:55:56 5: panstampLesLilas: 001D00C5001D0B0E23 -43 46
2015.08.22 14:55:56 5: panstampLesLilas dispatch 001D00C5001D0B0E23
2015.08.22 14:55:56 4: node_debordementEAU_cuisine -> broadcast (0,0-C5): status node_debordementEAU_cuisine 0B:0E23
2015.08.22 14:55:56 5: Triggering node_debordementEAU_cuisine (2 changes)
2015.08.22 14:55:56 5: Notify loop for node_debordementEAU_cuisine 0B-Voltage: 0E23
2015.08.22 14:55:56 5: Notify for node_debordementEAU_cuisine
2015.08.22 14:55:56 5: 0B-Voltage: 0E23, '0B-Voltage', '0E23'
2015.08.22 14:55:56 5: voltage: 3.619, 'voltage', '3.619'
2015.08.22 14:55:56 5: MQTT MQTT_connect message sent: Publish/at-most-once nodeCuisine/voltage
  33 2e 36 31 39                                   3.619
2015.08.22 14:55:56 5: SW: 301a00136e6f646543756973696e652f766f6c74616765332e363139
2015.08.22 14:55:56 5: Triggering MQTT_eauCuisine (1 changes)
2015.08.22 14:55:56 5: Notify loop for MQTT_eauCuisine transmission-state: outgoing publish sent




But for netatmo, I can't publish.

Configuration

# Netatmo
define netatmoDevice netatmo XXXXXXXXXX XXXXXXXXXXXXX  XXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXXX temperature 60
attr netatmoDevice delay 60

# transmission à Jeedom des informations netatmo
define MQTT_netatmo MQTT_BRIDGE netatmoDevice
attr MQTT_netatmo IODev MQTT_connect
attr MQTT_netatmo publish-topic-base fhem/did/netatmo/
attr MQTT_netatmo publishReading_temperature fhem/did/netatmo/temperature
attr MQTT_netatmo room salon
attr MQTT_netatmo stateFormat transmission-state



and log :

2015.08.22 14:56:11 4: HTTP FHEMWEB:192.168.0.39:57329 GET /fhem?XHR=1&inform=type=status;filter=MQTT_eauCuisine;since=1440248170;fmt=JSON&timestamp=1440248174568
2015.08.22 14:56:19 5: netatmo_GetStatus
2015.08.22 14:56:21 4: netatmoDevice: temperature : 25.9
2015.08.22 14:56:21 5: Triggering netatmoDevice (1 changes)
2015.08.22 14:56:21 5: Notify loop for netatmoDevice temperature : 25.9
2015.08.22 14:56:21 5: Notify for netatmoDevice
2015.08.22 14:56:21 5: temperature : 25.9, 'temperature ', '25.9'
2015.08.22 14:56:21 5: exec at command initRadiateursSalon



Why I can't publish the netatmo infos ?

Have you any idea ?

Thank you.

Chdid

chdid

I found the problem : space and lower/upper case.

For example 'Temperature : 25' became 'Temperature ' and '25'. => first problem : space after temperature.
If the publishReadings is publishReadings_temperature then fhem can't find publishReadings_Temperature => second problem.

I changed notify function in 10_MQTT_BRIDGE.pm. It's OK now.




sub Notify() {
  my ($hash,$dev) = @_;

  Log3($hash->{NAME},5,"Notify for $dev->{NAME}");
 
  foreach my $event (@{$dev->{CHANGED}}) {
 
    $event =~ /^([^:]+)(: )?(.*)$/;
my $valeur = $3;
my $nomChamp = lc($1); # lowercase
$nomChamp =~ s/^\s+|\s+$//g ; # trim

    Log3($hash->{NAME},5,"$event, '".((defined $nomChamp) ? $nomChamp : "-undef-")."', '".((defined $valeur) ? $valeur : "-undef-")."'");
    my $msgid;

    if (defined $valeur and $valeur ne "") {
  if (defined $hash->{publishReadings}->{$nomChamp}) {
    $msgid = send_publish($hash->{IODev}, topic => $hash->{publishReadings}->{$nomChamp}, message => $valeur, qos => $hash->{qos}, retain => $hash->{retain});
        readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
      }
    } else {

      if (defined $hash->{publishState}) {
    $msgid = send_publish($hash->{IODev}, topic => $hash->{publishState}, message => $nomChamp, qos => $hash->{qos}, retain => $hash->{retain});
        readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
      }
    }

    $hash->{message_ids}->{$msgid}++ if defined $msgid;
  }
}


I'm not a perl developer. Perharps, could you optimize this part :
        $event =~ /^([^:]+)(: )?(.*)$/;
   my $valeur = $3;
   my $nomChamp = lc($1); # lowercase
   $nomChamp =~ s/^\s+|\s+$//g ; # trim



Chdid