This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Sample dictionary | |
carDetails = { | |
"car_brand":"TATA", | |
"model":"Nexon", | |
"details":"XZA", | |
"fuel":"Petrol" | |
} | |
## Access |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: StatefulSet | |
metadata: | |
name: swittons | |
spec: | |
serviceName: vernemq | |
replicas: 2 | |
selector: | |
matchLabels: | |
app: vernemq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>VAMS</title> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
$(document).ready(function() { | |
var socket = io.connect('http://' + document.domain + ':' + location.port); | |
socket.on('mqtt_message', function(data) { | |
console.log(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/') | |
def index(): | |
return render_template('index.html') | |
def gen(camera): | |
while True: | |
frame = camera.get_frame() | |
yield (b'--frame\r\n' | |
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mqtt.on_connect() | |
def handle_connect(client, userdata, flags, rc): | |
mqtt.subscribe(data['mqtt_topic']) | |
@mqtt.on_message() | |
def handle_mqtt_message(client, userdata, message): | |
data = dict( | |
topic=message.topic, | |
payload=message.payload.decode() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socketio = SocketIO(app) | |
bootstrap = Bootstrap(app) | |
mqtt=Mqtt(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#MQTT CONFIG | |
with open('mqtt_config.json') as json_data_file: | |
data=json.load(json_data_file) | |
app = Flask(__name__) | |
app.config['MQTT_BROKER_URL']=data['mqtt_host'] | |
app.config['MQTT_PORT']=data['mqtt_port'] | |
app.config['MQTT_USERNAME'] = '' | |
app.config['MQTT_PASSWORD'] = '' | |
app.config['MQTT_KEEPALIVE'] = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template, Response | |
from camera import VideoCamera | |
from flask_mqtt import Mqtt | |
from flask_socketio import SocketIO | |
from flask_bootstrap import Bootstrap | |
import json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## OBD | |
def init_connection(baud_rate,com_port,fast): | |
connection = obd.Async(com_port,baudrate=baud_rate, fast=fast) | |
connection.watch(obd.commands.RPM, callback=new_rpm) | |
connection.watch(obd.commands.SPEED, callback=new_speed) | |
connection.watch(obd.commands.COOLANT_TEMP, callback=new_coolant_temperature) | |
connection.watch(obd.commands.THROTTLE_POS, callback=new_throttle_position) | |
connection.start() | |
print("hello") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## MQTT | |
def on_connect(client, userdata, flags, rc): | |
print(mqtt_topic) | |
client.subscribe(mqtt_topic,qos=1) | |
print("Connected") | |
def on_publish(client, userdata, mid): | |
print("mid: "+str(mid)) | |
NewerOlder