Giter Club home page Giter Club logo

flask_iiot's Introduction

Flask IIOT

A IIOT application for traditional factory

alt text

User

Not usable as it is a work in progress

Flask Contributor

Data Collector: OPC-UA

Simple Connection

from opcua import Client, ua

client = Client("opc.tcp://localhost:4840")
try:
    client.connect()
    print("OPCUA connection success!")
finally:
    client.disconnect()

Reading node

from opcua import Client, ua

client = Client("opc.tcp://localhost:4840")
try:
    client.connect()
    node = client.get_node('node_id')
    while True:
        print(node.get_value())
        sleep(1)
finally:
    client.disconnect()

Data Collector: Modbus TCP/IP

Reading holding registers from address 0 to 124 at port 502.

from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('localhost', port=502)
print(client.read_holding_registers(address=0, count=124, unit=1).registers)
client.close()

MQTT Publisher

Publish message at port 1883

from time import sleep
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    print("rc: "+str(rc))
    
def on_publish(client, userdata, mid):
    print("mid: "+str(mid))
    
client = mqtt.Client()
client.on_connect = on_connect
client.on_publish = on_publish
client.connect(host='test.mosquitto.org', port=1883, keepalive=60)
client.loop_start()

while True:
    client.publish('test/123', 'message', qos=2)
    sleep(1)

Web App

@app.route('/')
def hello_world():
    return 'Hello, World!'

ES Indexer

Index data to ES

from datetime import datetime
from elasticsearch import Elasticsearch
msg = {
    "workingcode": "yaypython!",
    "string": "abcABC",
    "whole": 123,
    "float": 654.321,
    "timestamp": datetime.now(),
}
es = Elasticsearch()
es.indices.create(index='python-helloworld', ignore=400)
es.index(index="python-helloworld",
         doc_type="test-jsontype",
         id=42,
         body=msg)

getting data

es.get(index="python-helloworld", doc_type="test-jsontype", id=42)

Using bulk action

import json
from time import sleep
from datetime import datetime

from elasticsearch import Elasticsearch
from elasticsearch import helpers

es = Elasticsearch()

dict_data = {}
while True:
	# update dict_data
    actions = [
        {
            "_index": "python_data",
            "_type": "data",
            "_source": dict_data
        }]
    helpers.bulk(es, actions)

Web Contributor

MQTT Subscriber

Future

  • IOT homepage: app status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.