Skip to content

Commit

Permalink
Merge pull request #13 from AdamMiltonBarker/main
Browse files Browse the repository at this point in the history
Release 2.0.1
  • Loading branch information
AdamMiltonBarker authored Sep 12, 2021
2 parents beaf5be + 400e657 commit e43389e
Show file tree
Hide file tree
Showing 20 changed files with 589 additions and 854 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

![HIASBCH MQTT Blockchain Agent](assets/images/project-banner.jpg)

[![CURRENT RELEASE](https://img.shields.io/badge/CURRENT%20RELEASE-2.0.0-blue.svg)](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/tree/2.0.0) [![UPCOMING RELEASE](https://img.shields.io/badge/CURRENT%20DEV%20BRANCH-3.0.0-blue.svg)](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/tree/3.0.0) [![Contributions Welcome!](https://img.shields.io/badge/Contributions-Welcome-lightgrey.svg)](CONTRIBUTING.md) [![Issues](https://img.shields.io/badge/Issues-Welcome-lightgrey.svg)](issues)
[![CURRENT RELEASE](https://img.shields.io/badge/CURRENT%20RELEASE-2.0.1-blue.svg)](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/tree/release-2.0.1) [![UPCOMING RELEASE](https://img.shields.io/badge/DEV%20BRANCH-develop-blue.svg)](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/tree/develop) [![Contributions Welcome!](https://img.shields.io/badge/Contributions-Welcome-lightgrey.svg)](CONTRIBUTING.md) [![Issues](https://img.shields.io/badge/Issues-Welcome-lightgrey.svg)](issues)

[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/) [![Documentation Status](https://readthedocs.org/projects/hiasbch-mqtt-blockchain-agent/badge/?version=latest)](https://hiasbch-mqtt-blockchain-agent.readthedocs.io/en/latest/?badge=latest) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4980/badge)](https://bestpractices.coreinfrastructure.org/projects/4980)

Expand All @@ -30,9 +30,9 @@

# Introduction

A **HIASBCH Blockchain Agent** is a bridge between **HIAS IoT Agents**, and **HIASBCH Private Ethereum Blockhain**. The **HIASBCH MQTT Blockchain Agent** is a HIAS AI Agent that receives authenticated data and stores an immutable hash in the **HIASBCH iotJumpWay Smart Contract**.
A **HIASBCH Blockchain Agent** is a bridge between **HIAS IoT Agents**, and **HIASBCH Private Ethereum Blockchain**. The **HIASBCH MQTT Blockchain Agent** is an extension of the HIAS IoT Agent that receives authenticated data and stores an immutable hash in the **HIASBCH Data Integrity Smart Contract**.

The HIASBCH iotJumpWay Smart Contract stores permissions for all HIAS network devices and applications, and immutable hashes of data received from the HIAS network. These immutable hashes allow data integrity checks to be carried out on data stored in the historical database by comparing the hash of the data and the hash stored in HIASBCH.
The HIASBCH Data Integrity Smart Contract stores data permissions for all HIAS network devices and applications, and immutable hashes of data received from the HIAS network. These immutable hashes allow data integrity checks to be carried out on data stored in the historical database by comparing the hash of the data and the hash stored in HIASBCH.

 

Expand All @@ -46,23 +46,23 @@ The protocol is publish-subscribe (Pub/Sub) communication protocol that runs ove

# Blockchain

A blockchain is a immutable decentralized digital ledger of transactions stored in **blocks**. HIASBCH is a private [Ethereum](https://ethereum.org/en/) blockchain that hosts Smart Contracts that allow the HIAS network to function.
A blockchain is a immutable decentralized digital ledger of transactions stored in **blocks**. HIASBCH is a private [Ethereum](https://ethereum.org/en/) blockchain that hosts smart contracts that allow the HIAS network to function.

 

# HIAS

![HIAS - Hospital Intelligent Automation Server](assets/images/hias-network.jpg)
![HIAS - Hospital Intelligent Automation Server](assets/images/hias-network-v3.jpg)

[HIAS - Hospital Intelligent Automation Server](https://github.com/AIIAL/HIAS-Core) is an open-source automation server designed to control and manage an intelligent network of IoT connected devices and applications.
[HIAS - Hospital Intelligent Automation Server](https://github.com/aiial/hias-core) is an open-source server for hospitals and medical centers, designed to control and manage a network of intelligent IoT connected devices and applications.

## HIASBCH Smart Contracts

The core Smart Contracts used on the HIAS network are:

- **HIAS Permissions Smart Contract** - Stores permissions for all HIAS devices, applications, agents and users.

- **HIAS iotJumpWay Smart Contract** - Stores iotJumpWay permissions for all HIAS devices, applications, agents and users. Stores immutable hashes of data received from the HIAS network.
- **HIAS Data Integrity Smart Contract** - Stores data permissions for all HIAS devices, applications, agents and users. Stores immutable hashes of data received from the HIAS network.

## HIASBCH Blockchain Agents

Expand Down
163 changes: 75 additions & 88 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,128 +43,115 @@
import sys
import time

from abc import ABC, abstractmethod
from datetime import datetime
from flask import Flask, request, Response
from threading import Thread

from modules.AbstractAgent import AbstractAgent


class agent(AbstractAgent):
""" HIASBCH Blockchain Agent Class
""" HIASBCH Blockchain Agent Class
HIASBCH Blockchain Agent Class process all data coming from IoT Agents and store
immutable hashes in the HIASBCH Blockchain providing the functionality
to perform data integrity checks.
"""
HIASBCH Blockchain Agent Class process all data coming from IoT Agents
and store immutable hashes in the HIASBCH Blockchain providing
the functionality to perform data integrity checks.
"""

def actuatorCallback(self, topic, payload):
pass
def integrity_callback(self, topic, payload):
"""Called in the event of an integrity payload
def lifeCallback(self, topic, payload):
pass
Args:
topic (str): The topic the payload was sent to.
payload (:obj:`str`): The payload.
"""

def statusCallback(self, topic, payload):
pass
data = json.loads(payload.decode("utf-8"))
split_topic = topic.split("/")

def sensorsCallback(self, topic, payload):
pass
if split_topic[1] not in self.ignore_types:
entity_type = split_topic[1][:-1]
else:
entity_type = split_topic[1]

def integrityCallback(self, topic, payload):
"""Called in the event of an integrity payload
if entity_type in ["Robotics", "Application", "Staff"]:
entity = split_topic[2]
else:
entity = split_topic[3]

Args:
topic (str): The topic the payload was sent to.
payload (:obj:`str`): The payload.
"""
self.helpers.logger.info(
"Received " + entity_type + " Integrity: " + str(data))

data = json.loads(payload.decode("utf-8"))
splitTopic = topic.split("/")
attrs = self.get_attributes(entity_type, entity)
bch = attrs["blockchain"]

if splitTopic[1] not in self.ignoreTypes:
entityType = splitTopic[1][:-1]
else:
entityType = splitTopic[1]
if not self.hiasbch.iotjumpway_access_check(bch):
return

if entityType in ["Robotics", "Application", "Staff"]:
entity = splitTopic[2]
else:
entity = splitTopic[3]
entity = attrs["id"]
location = attrs["location"]
zone = attrs["zone"] if "zone" in attrs else "NA"

self.helpers.logger.info(
"Received " + entityType + " Integrity: " + str(data))
Thread(target=self.hiasbch.store_hash, args=(
data["_id"], self.hiasbch.hash(data), int(time.time()),
location, entity, bch, entity_type), daemon=True).start()

attrs = self.getRequiredAttributes(entityType, entity)
bch = attrs["blockchain"]
self.helpers.logger.info(entity_type + " " + entity + " status update OK")

if not self.hiasbch.iotJumpWayAccessCheck(bch):
return
def respond(self, response_code, response):
""" Returns the request repsonse """

entity = attrs["id"]
location = attrs["location"]
zone = attrs["zone"] if "zone" in attrs else "NA"
return Response(response=json.dumps(response, indent=4), status=response_code,
mimetype="application/json")

Thread(target=self.hiasbch.storeHash, args=(data["_id"], self.hiasbch.hash(data), int(time.time()),
location, entity, bch, entityType), daemon=True).start()

self.helpers.logger.info(entityType + " " + entity + " status update OK")

def respond(self, responseCode, response):
""" Returns the request repsonse """

return Response(response=json.dumps(response, indent=4), status=responseCode,
mimetype="application/json")

def signal_handler(self, signal, frame):
self.helpers.logger.info("Disconnecting")
self.mqtt.disconnect()
sys.exit(1)
def signal_handler(self, signal, frame):
self.helpers.logger.info("Disconnecting")
self.mqtt.disconnect()
sys.exit(1)

app = Flask(__name__)
agent = agent()

@app.route('/About', methods=['GET'])
def about():
"""
Returns Agent details
Responds to GET requests sent to the North Port About API endpoint.
"""

return agent.respond(200, {
"Identifier": agent.credentials["iotJumpWay"]["entity"],
"Host": agent.credentials["server"]["ip"],
"NorthPort": agent.credentials["server"]["port"],
"CPU": psutil.cpu_percent(),
"Memory": psutil.virtual_memory()[2],
"Diskspace": psutil.disk_usage('/').percent,
"Temperature": psutil.sensors_temperatures()['coretemp'][0].current
})
"""
Returns Agent details
Responds to GET requests sent to the North Port About API endpoint.
"""

return agent.respond(200, {
"Identifier": agent.credentials["iotJumpWay"]["entity"],
"Host": agent.credentials["server"]["ip"],
"NorthPort": agent.credentials["server"]["port"],
"CPU": psutil.cpu_percent(),
"Memory": psutil.virtual_memory()[2],
"Diskspace": psutil.disk_usage('/').percent,
"Temperature": psutil.sensors_temperatures()['coretemp'][0].current
})

def main():

signal.signal(signal.SIGINT, agent.signal_handler)
signal.signal(signal.SIGTERM, agent.signal_handler)
signal.signal(signal.SIGINT, agent.signal_handler)
signal.signal(signal.SIGTERM, agent.signal_handler)

agent.hiascdiConn()
agent.hiasbchConn()
agent.mqttConn({
"host": agent.credentials["iotJumpWay"]["host"],
"port": agent.credentials["iotJumpWay"]["port"],
"location": agent.credentials["iotJumpWay"]["location"],
"zone": agent.credentials["iotJumpWay"]["zone"],
"entity": agent.credentials["iotJumpWay"]["entity"],
"name": agent.credentials["iotJumpWay"]["name"],
"un": agent.credentials["iotJumpWay"]["un"],
"up": agent.credentials["iotJumpWay"]["up"]
})
agent.hiascdi_connection()
agent.hiasbch_connection()
agent.mqtt_connection({
"host": agent.credentials["iotJumpWay"]["host"],
"port": agent.credentials["iotJumpWay"]["port"],
"location": agent.credentials["iotJumpWay"]["location"],
"zone": agent.credentials["iotJumpWay"]["zone"],
"entity": agent.credentials["iotJumpWay"]["entity"],
"name": agent.credentials["iotJumpWay"]["name"],
"un": agent.credentials["iotJumpWay"]["un"],
"up": agent.credentials["iotJumpWay"]["up"]
})

agent.mqtt.integrityCallback = agent.integrityCallback
agent.mqtt.integrity_callback = agent.integrity_callback

agent.threading()
agent.threading()

app.run(host=agent.helpers.credentials["server"]["ip"],
port=agent.helpers.credentials["server"]["port"])
app.run(host=agent.helpers.credentials["server"]["ip"],
port=agent.helpers.credentials["server"]["port"])

if __name__ == "__main__":
main()
main()
Binary file added assets/images/hias-network-v3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/hias-network.jpg
Binary file not shown.
4 changes: 0 additions & 4 deletions configuration/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
},
"proxy": {
"up": ""
},
"hiasbch": {
"un": "",
"up": ""
}
}
}
Binary file modified docs/img/hias-iotjumpway-agents.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/hias-network-v3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/img/hias-network.jpg
Binary file not shown.
18 changes: 9 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

![HIASBCH MQTT Blockchain Agent](img/project-banner.jpg)

[![CURRENT RELEASE](https://img.shields.io/badge/CURRENT%20RELEASE-2.0.0-blue.svg)](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/tree/2.0.0) [![UPCOMING RELEASE](https://img.shields.io/badge/CURRENT%20DEV%20BRANCH-3.0.0-blue.svg)](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/tree/3.0.0) [![Contributions Welcome!](https://img.shields.io/badge/Contributions-Welcome-lightgrey.svg)](CONTRIBUTING.md) [![Issues](https://img.shields.io/badge/Issues-Welcome-lightgrey.svg)](issues) [![LICENSE](https://img.shields.io/badge/LICENSE-MIT-blue.svg)](LICENSE)
[![CURRENT RELEASE](https://img.shields.io/badge/CURRENT%20RELEASE-2.0.1-blue.svg)](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/tree/release-2.0.1) [![UPCOMING RELEASE](https://img.shields.io/badge/DEV%20BRANCH-develop-blue.svg)](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/tree/develop) [![Contributions Welcome!](https://img.shields.io/badge/Contributions-Welcome-lightgrey.svg)](CONTRIBUTING.md) [![Issues](https://img.shields.io/badge/Issues-Welcome-lightgrey.svg)](issues)

# Introduction

A **HIASBCH Blockchain Agent** is a bridge between **HIAS IoT Agents**, and **HIASBCH Private Ethereum Blockhain**. The **HIASBCH MQTT Blockchain Agent** is a HIAS AI Agent that receives authenticated data and stores an immutable hash in the **HIASBCH iotJumpWay Smart Contract**.
A **HIASBCH Blockchain Agent** is a bridge between **HIAS IoT Agents**, and **HIASBCH Private Ethereum Blockchain**. The **HIASBCH MQTT Blockchain Agent** is an extension of the HIAS IoT Agent that receives authenticated data and stores an immutable hash in the **HIASBCH Data Integrity Smart Contract**.

The HIASBCH iotJumpWay Smart Contract stores permissions for all HIAS network devices and applications, and immutable hashes of data received from the HIAS network. These immutable hashes allow data integrity checks to be carried out on data stored in the historical database by comparing the hash of the data and the hash stored in HIASBCH.
The HIASBCH Data Integrity Smart Contract stores data permissions for all HIAS network devices and applications, and immutable hashes of data received from the HIAS network. These immutable hashes allow data integrity checks to be carried out on data stored in the historical database by comparing the hash of the data and the hash stored in HIASBCH.

 

Expand All @@ -28,17 +28,17 @@ A blockchain is a immutable decentralized digital ledger of transactions stored

# HIAS

![HIAS - Hospital Intelligent Automation Server](img/hias-network.jpg)
![HIAS - Hospital Intelligent Automation Server](img/hias-network-v3.jpg)

[HIAS - Hospital Intelligent Automation Server](https://github.com/AIIAL/HIAS-Core) is an open-source automation server designed to control and manage an intelligent network of IoT connected devices and applications.
[HIAS - Hospital Intelligent Automation Server](https://github.com/aiial/hias-core) is an open-source server for hospitals and medical centers, designed to control and manage a network of intelligent IoT connected devices and applications.

## HIASBCH Smart Contracts

The core Smart Contracts used on the HIAS network are:

- **HIAS Permissions Smart Contract** - Stores permissions for all HIAS devices, applications, agents and users.

- **HIAS iotJumpWay Smart Contract** - Stores iotJumpWay permissions for all HIAS devices, applications, agents and users. Stores immutable hashes of data received from the HIAS network.
- **HIAS Data Integrity Smart Contract** - Stores data permissions for all HIAS devices, applications, agents and users. Stores immutable hashes of data received from the HIAS network.

## HIASBCH Blockchain Agents

Expand All @@ -58,7 +58,7 @@ To get started, follow the following guides:
# Contributing
Asociación de Investigacion en Inteligencia Artificial Para la Leucemia Peter Moss encourages and welcomes code contributions, bug fixes and enhancements from the Github community.

Please read the [CONTRIBUTING](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/blob/main/CONTRIBUTING.md "CONTRIBUTING") document for a full guide to forking our repositories and submitting your pull requests. You will also find our code of conduct in the [Code of Conduct](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/blob/main/CODE-OF-CONDUCT.md) document.
Please read the [CONTRIBUTING](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/blob/main/CONTRIBUTING.md "CONTRIBUTING") document for a full guide to forking our repositories and submitting your pull requests. You will also find our code of conduct in the [Code of Conduct](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/blob/main/CODE-OF-CONDUCT.md) document.

## Contributors
- [Adam Milton-Barker](https://www.leukemiaairesearch.com/association/volunteers/adam-milton-barker "Adam Milton-Barker") - [Asociación de Investigacion en Inteligencia Artificial Para la Leucemia Peter Moss](https://www.leukemiaresearchassociation.ai "Asociación de Investigacion en Inteligencia Artificial Para la Leucemia Peter Moss") President/Founder & Lead Developer, Sabadell, Spain
Expand All @@ -71,9 +71,9 @@ We use SemVer for versioning.
 

# License
This project is licensed under the **MIT License** - see the [LICENSE](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/blob/main/LICENSE "LICENSE") file for details.
This project is licensed under the **MIT License** - see the [LICENSE](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/blob/main/LICENSE "LICENSE") file for details.

 

# Bugs/Issues
We use the [repo issues](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/issues "repo issues") to track bugs and general requests related to using this project. See [CONTRIBUTING](https://github.com/AIIAL/HIASBCH-MQTT-Blockchain-Agent/CONTRIBUTING.md "CONTRIBUTING") for more info on how to submit bugs, feature requests and proposals.
We use the [repo issues](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/issues "repo issues") to track bugs and general requests related to using this project. See [CONTRIBUTING](https://github.com/aiial/hiasbch-mqtt-blockchain-agent/CONTRIBUTING.md "CONTRIBUTING") for more info on how to submit bugs, feature requests and proposals.
Loading

0 comments on commit e43389e

Please sign in to comment.