Hacker Public Radio

HPR4311: LoRaWAN and the Things Stack


Listen Later

This show has been flagged as Clean by the host.

I have set up some LoRaWAN temperature and humidity sensors, and

am using the Things Stack to collect the data.


This gets processed via a web-hook and rendered as a graph.


The LoRaWAN Alliance -

https://lora-alliance.org


Mastering LoRaWAN -

https://www.amazon.com/Mastering-LoRaWAN-Comprehensive-Communication-Connectivity-ebook/dp/B0CTRH6MV6


The Things Industries - https://thethingsindustries.com


server.py
import json
import sqlite3
import logging
from http.server import BaseHTTPRequestHandler, HTTPServer
rooms = {
'eui-24e12*********07': 'living-room',
'eui-24e12*********54': 'hall',
'eui-24e12*********42': 'downstairs-office',
'eui-24e12*********35': 'kitchen',
'eui-24e12*********29': 'conservatory',
'eui-24e12*********87': 'landing',
'eui-24e12*********45': 'main-bedroom',
'eui-24e12*********89': 'upstairs-office',
'eui-24e12*********38': 'spare-bedroom',
'eui-24e12*********37': 'playroom'
};
# Configure logging
logging.basicConfig(filename="server_log.txt", level=logging.INFO, format="%(asctime)s - %(message)s")
# Define the web server handler
class MyServerHandler(BaseHTTPRequestHandler):
# Handle POST requests
def do_POST(self):
length = int(self.headers.get('Content-Length'))
data = self.rfile.read(length).decode('utf-8')
try:
# Validate and parse JSON data
json_data = json.loads(data)
logging.info(f"Received valid JSON data: {json_data}")
# Write the data to database
id = json_data["end_device_ids"]["device_id"]
room = rooms.get(id)
readat = json_data["uplink_message"]["rx_metadata"][0]["time"]
temp = json_data["uplink_message"]["decoded_payload"]["temperature"]
hum = json_data["uplink_message"]["decoded_payload"]["humidity"]
conn = sqlite3.connect('data.db')
sql = """CREATE TABLE IF NOT EXISTS data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
room TEXT,
readat DATETIME,
temp DECIMAL(4,1),
hum DECIMAL(4,1)
);"""
conn.execute(sql)
sql = "INSERT INTO data (room, readat, temp, hum) VALUES (?, ?, ?, ?)"
conn.execute(sql, (room, readat, temp, hum))
conn.commit()
conn.close()
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("Data received and logged!", "utf-8"))
except json.JSONDecodeError:
logging.error("Invalid JSON data received.")
self.send_response(400) # Bad Request
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("Invalid JSON format.", "utf-8"))
except PermissionError:
logging.error("File write permission denied.")
self.send_response(500) # Internal Server Error
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("Server error: Unable to write data to file.", "utf-8"))
# Start the server
server_address = ('0.0.0.0', 12345) # Customize host and port if needed
httpd = HTTPServer(server_address, MyServerHandler)
print("Server started on http://localhost:12345")
httpd.serve_forever()

process.php

Temperature Chart



Humidity Chart



Provide feedback on this episode.

...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

289 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

373 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

653 Listeners

Curious Cases by BBC Radio 4

Curious Cases

826 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

423 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,039 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

181 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,809 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

138 Listeners

What the Hack? by DeleteMe

What the Hack?

221 Listeners