Skip to main content

Posts

Showing posts from December, 2019

How to start python script by batch file on window

How to start python script by batch file on window Reference https://datatofish.com/batch-python-script/ Assumption - Your python script is manage.py - Create a batch file "run.bat" which is placed in the same directory with your python script. run.bat source code :: find python.exe path @ for %%i in (python.exe) do @ set py = %%~$PATH:i ::run main program %py% %CD% \manage.py ::wait for stop pause manage.py source code print ( "Surprisingly, The naughty kitten defeated a giant python" ) Looking more sample batch file https://www.robvanderwoude.com/batexamples.php

Develop the first python client test application by Paho mqtt

Develop the first python client application by Paho I. Purpose: 1. Try to send messages between 2 clients via MQTT protocol. Then, we will create 2 clients: - One for publishing (or send) the message. Other for subscribing (or receive message). II. Pre-condition: - You already installed Mosquitto broker, Python. III. Step by step 1. Download example from Github https://github.com/eclipse/paho.mqtt.python 2. Modify subscriber(client) source In folder example/client_sub.py. Modify some pieces of source code. before mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.subscribe("$SYS/#", 0) after mqttc.connect("192.168.203.76", 1883, 60) mqttc.subscribe("test/topic1", 0) note: "192.168.203.76": IP address of machine which Mosquito broker installed on. 1883: mqtt port 3. Modify publisher(client) source In folder example/publish_single.py. before: publish.single("paho/test/sing

How to test Mosquitto broker on Windows machine

Install Mosquito broker https://mosquitto.org/download/ 1. Install service easily by some click. 2. Check operation Reference: http://www.steves-internet-guide.com/install-mosquitto-broker/ - open command prompt and check installed directory cd C:\Program Files\mosquitto mosquitto -h or mosquitto -v - start service mosquitto -p 1883 - check port 1883 is listening or not netstat -a - add system environment variables. Add below string to the system environment path. It helps you call mosquito in the command line window. ;C:\Program Files\mosquitto Example Reference: https://www.win.tue.nl/~lrahman/iot_2016/tutorial/MQTT_2016.pdf 1. Open the first command windows 2. Start mosquitto by command mosquitto -p 1883 3. Open the second command windows 4. Allow client subcribe the topic by command mosquitto_sub -t 'test/topic' -v This time, a client has the ability to handle the message from publisher. 5. Open the third command windows 6. Publish message