Skip to content

Instantly share code, notes, and snippets.

View avirup171's full-sized avatar

Avirup Basu avirup171

View GitHub Profile
@avirup171
avirup171 / python-dict
Created January 6, 2023 18:12
Python dictionaries
## Sample dictionary
carDetails = {
"car_brand":"TATA",
"model":"Nexon",
"details":"XZA",
"fuel":"Petrol"
}
## Access
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: swittons
spec:
serviceName: vernemq
replicas: 2
selector:
matchLabels:
app: vernemq
<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);
@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')
@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()
)
socketio = SocketIO(app)
bootstrap = Bootstrap(app)
mqtt=Mqtt(app)
#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
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
## 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")
## 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))