Skip to main content

MQTT set up Flask

 MQTT

Introduction:

It is message broker which holds the data when ever a consumer will connected to the topic then he will receive the data . mqtt is a machine to machine message broker, mainly used in IOT application, the default port is 1883


 

Installation:

sudo apt-get update
sudo apt-get install mosquitto

Command line execution:

Producer

mosquitto_pub -h 127.0.0.1 -t 'topic_name' -m '{'name':'Sony'}'

Subscriber

mosquitto_sub -h 127.0.0.1 -t 'topic_name'


-h : it is the host address

-t : topic name

-m : message payload

QOS in MQTT:

QOS(quality of services) there are mainly 3 services are available in mqtt 

  1. qos=0
  2. qos=1
  3. qos=2

QOS (0,0):

At most once service, publisher will send a message to broker at most once, the broker passes a message to subscriber one time 
 

 

Comments

Popular posts from this blog

Making a Geographic Heatmap with Python

      We have a requirement like need to create a map where user is traveled.There are many libraries available in python to draw a map if you have list of co-ordinates with you like(longitude and latitude)  To name few packages : vincent, bokeh, plot.ly and matplotlib and folium   Things to consider while choosing the library: 1. Open source 2. Painless to use 3. built in support for heat-maps 4. actively maintained Folium is the lib which will satisfy above all use cases Requirements: pip install folium pip install geopands (for adding other geo json files) pip install pands (to read csv of excel files which are having the co-ordinates data) Creating the map: import pandas as pd import folium from folium.plugins import HeatMap map_df = pd.read_csv('map.csv', sep='\t') max_amount = float(map_df['Amount'].max()) hmap = folium.Map(location=[42.5, -75.5], zoom_start=7, ) hm_wide = HeatMap( list(zip(map_df.lat.values,         ...

Save Rendered Templates in Flask

 Flask:     We can return multiple types of responses using flask like HTTP Responses , XML responses and Templates responses. Consider the use case like you wanted to save html pages which are dynamically rendered    Packages required: 1. jinja2 2. Flask   Create a Folder structure:     Template        |-   image        |-   fonts        |-   js          index.html   index.html: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>{{name}}</h1> <p>{{address}}</p> </body> </html>     code: #imports from jinja2 import Environment , select_autoescape , FileSystemLoader #fetch the index.html file using the FilesystemLoader path = os . path . dirname ( os . path . abspath ( __file_...