Things used in this project

Hardware components:
MikroElektronika Flip&Click
MikroElektronika LoRa Click
MikroElektronika Temp&Hum Click
Medium rn2483 module 47 yyiez9ixb5
Microchip RN2483
Software apps and online services:
Zpm toolbar 1
Zerynth Zerynth Studio
Ttn logo
The Things Network


Zerynth and TTN - LoRa
Zerynth lora node data plotting k6asnjtvti


LoraWAN sensor data LoggingPython
# LoraWAN sensor data Logging
import streams
from microchip.rn2483 import rn2483
from stm.hts221 import hts221
    rst = D16 # reset pin 
    # insert otaa credentials!
    appeui = "YOUAPPEUI"
    appkey =  "YOUAPPKEY"
    if not rn2483.init(SERIAL1, appeui, appkey, rst): # LoRa Click on slot A
        print("denied :(")
        raise Exception
    print("sending first message, res:")
    temp_hum = hts221.HTS221( I2C1,D31 ) # Temp Hum Click on slot C
    while True:
        temp, hum = temp_hum.get_temp_humidity()
        print('temp: ', temp, 'hum: ', hum)
        data = bytearray(4) 
        data[0:2] = bytearray([ int(temp) + 127, int((temp - int(temp)) * 100) ])
        data[2:4] = bytearray([ int(hum) + 127, int((hum - int(hum)) * 100) ])
        r = rn2483.tx_uncnf(data) # send data to TTN
except Exception as e:
# Get and plot data from TTN Console using Python
import paho.mqtt.client as mqtt
import json
import base64
import matplotlib.pyplot as plt
#import DataPlot and RealtimePlot from the file
from plot_data import DataPlot, RealtimePlot
fig, axes = plt.subplots()
plt.title('Data from TTN console')
data = DataPlot()
dataPlotting= RealtimePlot(axes)
def bytes_to_decimal(i,d):
    xx = i - 127
    dec = (-d if xx < 0 else d)/100
    return xx + dec
def on_connect(client, userdata, flags, rc):
def on_message(client, userdata, msg):
    j_msg = json.loads(msg.payload.decode('utf-8'))
    dev_eui = j_msg['hardware_serial']
    tmp_hum = base64.b64decode(j_msg['payload_raw'])
    tmp = bytes_to_decimal(*tmp_hum[0:2])
    hum = bytes_to_decimal(*tmp_hum[2:4])
    # print data
    print('tmp:', tmp, ' hum:', hum)
    print('dev eui: ', dev_eui)
    # plot data
    global count
    data.add(count, tmp , hum)
# set paho.mqtt callback
ttn_client = mqtt.Client()
ttn_client.on_connect = on_connect
ttn_client.on_message = on_message
ttn_client.username_pw_set(APPID, PSW)
ttn_client.connect("", 1883, 60) #MQTT port over TLS
except KeyboardInterrupt:
import time
import math
from collections import deque , defaultdict
import matplotlib.animation as animation
from matplotlib import pyplot as plt
import threading
from random import randint
from statistics import *
class DataPlot:
    def __init__(self, max_entries = 20):
        self.axis_x = deque(maxlen=max_entries)
        self.axis_y = deque(maxlen=max_entries)
        self.axis_y2 = deque(maxlen=max_entries)
        self.max_entries = max_entries
    def add(self, x, y,y2):
class RealtimePlot:
    def __init__(self, axes):
        self.axes = axes
        self.lineplot, = axes.plot([], [], "ro-")
        self.lineplot2, = axes.plot([], [], "go-")
    def plot(self, dataPlot):
        self.lineplot.set_data(dataPlot.axis_x, dataPlot.axis_y)
        self.lineplot2.set_data(dataPlot.axis_x, dataPlot.axis_y2)
        self.axes.set_xlim(min(dataPlot.axis_x), max(dataPlot.axis_x))
        ymin = min([min(dataPlot.axis_y), min(dataPlot.axis_y2)])-10
        ymax = max([max(dataPlot.axis_y), max(dataPlot.axis_y2)])+10
def main():
    fig, axes = plt.subplots()
    plt.title('Plotting Data')
    data = DataPlot();
    dataPlotting= RealtimePlot(axes)
        while True:
            data.add(count, 30 + 1/randint(1,5) , 35 + randint(1,5))
    except KeyboardInterrupt:
        print('\n\nKeyboard exception received. Exiting.')
if __name__ == "__main__": main()


Luigi Francesco Cerfeda

Yet another Tony Stark wannabe



Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Similar projects you might like

VästtraPi: A Personal Bus Stop for Västtrafik Buses
  • 1,675
  • 7

Your own departures screen for Västtrafik buses from Gothenburg, Sweden. Get travel information instantly, like being at a real bus stop!

Control Light via Motion or Web
  • 103
  • 9

This project uses the web or motion to control a light.

DIY Fidget LED Display
  • 1,961
  • 13

Full instructions

Fidget spinners, the simple spinning toy that came out of nowhere. I thought it'd be cool give it some flare and make it a POV display.

Weekly Scheduling for IoT Smart Devices via Web
  • 393
  • 13


Smart devices may need to be able to be set weekly schedules. Some functionality can be activated/deactivated at some specific time.

Doorbell Battery Warning
  • 65
  • 0

Work in progress

This hack monitors the doorbell battery voltage. It makes a tick when it's time to recharge or replace the batteries.

Controlling Arduino State Machine via Web
  • 881
  • 15

Full instructions

This video shows how to change state of state machine on Arduino via web.

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog