Ingenieria Eléctrica

Internet de las Cosas Verde

 Les quiero presentar un proyecto personal de Internet de las Cosas o Internet of Things (IoT) sobre el monitoreo de un árbol de la abundancia.

Se trata de @FlorIoT, un árbol de la abundancia conectado al Internet de las cosas el cual reporta parámetros de temperatura, humedad, fertilidad y detección de luz solar por medio de twitter y por su pagina web

FlorIoT

Este proyecto se llevo acabo utilizando como hardware, una Raspberry pi 3, y un sensor Xiaomi Mi Flora

De software, Nodered, Mosquitto, Python.

Node-RED

Al arbolito se le instaló el sensor y por medio de bluetooth se conectó a la raspberry, esta ultima se encuentra conectada a internet a un servidor web y por medio de NodeRed se manda la informacion a twitter.

El codigo se encuentra en mi GitHub:  https://github.com/fsaldivar/IoT

#Read data from Xiaomi flower monitor, tested on firmware version 2.6.6


import sys

from gattlib import GATTRequester, GATTResponse

from struct import *

import paho.mqtt.client as mqtt


address = sys.argv[1]

requester = GATTRequester(address)

#Read battery and firmware version attribute

data=requester.read_by_handle(0x0038)[0]

battery, version = unpack('<B6s',data)

print "Battery level:",battery,"%"

print "Firmware version:",version

#Enable real-time data reading

requester.write_by_handle(0x0033, str(bytearray([0xa0, 0x1f])))

#Read plant data

data=requester.read_by_handle(0x0035)[0]

temperature, sunlight, moisture, fertility = unpack('<hxIBHxxxxxx',data)

print "Light intensity:",sunlight,"lux"

print "Temperature:",temperature/10.,"C"

print "Soil moisture:",moisture,"%"

print "Soil fertility:",fertility,"uS/cm"


#Sometimes the version contains some funny charcters which throws off the JSON processing. Cleaning string

temp = version

version = " "

for x in temp:

    if x == ".":

        version = version + "."

    if x >= "0" and x <="9":

            version = version + x

version = version.strip()


# Saving information in text file in JSON format

json_file = open(sys.argv[2],"w")

json_file.write("{ \"battery\" : " + str(battery) + ", \"version\" : \"" + version + "\", \"sunlight\" : " + str(sunlight) + ", \"temperature\" : " + str(temperature/10.) + ", \"moisture\" : " + str(moisture) + ", \"fertility\" : " + str(fertility) + " }")

json_file.close()

# End Json file export


# Publishing the results to MQTT

mqttc = mqtt.Client("miflora")

mqttc.username_pw_set("***","*****") #Usuario,Password

mqttc.connect("localhost", 1883)

mqttc.publish("/home/pi", "{ \"battery\" : " + str(battery) + ", \"version\" : \"" + version + "\", \"sunlight\" : " + str(sunlight) + ", \"temperature\" : " + str(temperature/10.) + ", \"moisture\" : " + str(moisture) + ", \"fertility\" : " + str(fertility) + " }")

mqttc.loop(2)

# End of MQTT

Un comentario

Dejar una respuesta

Tu dirección de correo electrónico no será publicada.