Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] Mosquitto connection disconnection message time

Below is the code which we are using to bind with broker and publish message with LWT and time stamp.

 

#!/usr/bin/python

import paho.mqtt.client as mqtt

import paho.mqtt.publish as publish

import datetime

import socket

import sys

#import fcntl

#import struct

 

#def get_ip_address(ifname):

#        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

#        return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915,  # SIOCGIFADDR  struct.pack('256s', ifname[:15]))[20:24])

 

#ip_addr = get_ip_address('eth0')

#print ip_addr

#socket_id = socket.gethostbyname(socket.gethostname())

#print socket_id

#curr_time = datetime.datetime.now()

#print curr_time.strftime("%Y-%m-%d %H:%M")

def on_connect(client, userdata, rc):

        #mqtt.Client(client_id="REDHAT4", clean_session=True, userdata=None, protocol=mqtt.MQTTv31)

        print("connected with result code "+str(rc))

        client.subscribe("Heart")

        client.will_set("Heart/Lwt", payload=str(datetime.datetime.now())+" Disconnected From Broker", qos=2, retain=False)

        publish.single("Heart/Lwt", "It works!!! Connected With Broker  ", hostname="10.1.1.2")

        return rc

def on_message(client, userdata, msg):

        print(msg.topic+" "+str(msg.payload))

 

client = mqtt.Client(client_id="REDHAT")

client._on_connect_ = on_connect

curr_time = datetime.datetime.now()

client._on_message_ = on_message

client.connect("10.1.1.2", 2000, 30)

client.loop_forever()

 

 

Thanks

Rajeev

 

From: Rajeev Kumar
Sent: Monday, May 23, 2016 4:24 PM
To: mosquitto-dev@xxxxxxxxxxx
Subject: Re: Mosquitto connection disconnection message time

 

Thanks Roger for prompt response.

 

I getting below time difference in below screenshot.

 

 

 

Rajeev



::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.

----------------------------------------------------------------------------------------------------------------------------------------------------


Back to the top