Wiznet makers

chalei

Published October 20, 2024 © GNU General Public License, version 3 or later (GPL3+)

0 UCC

0 VAR

4 Contests

0 Followers

0 Following

TinyML based room occupation watcher

A watcher device to monitor the room occupation

COMPONENTS Hardware components

WIZnet - W55RP20-EVB-Pico

x 1

Software Apps and online services

micropython - MicroPython

x 1


thonny.org - Thonny

x 1


PROJECT DESCRIPTION

At the campus where I work, there are many meeting rooms that is use by the staff. Sometime so many meeting could happen in one single day and it could take quite a distance to go to the meeting room and disappointed because there are no one told us that the room is occupied already.

In this project I will make a smart  room watcher that has the ability to sense if there are people in the room.

 

HARDWARE

To make this project, Besides the W55RP20-evb-pico ionic I'll be using the newly released Sensecap Watcher for its easy AI or TinyML configuration. and connect it to Ionic board like the picture below

For TX Pin I Use Pin 0 or GP0 and for  the RX Pin I use Pin 1 or GP1 on the  Ionic board.

SOFTWARE

The project will use the micropython firmware that I already familiar with and you can grab the Micropython firmware for the ionic  board here. And to  install to the board just use the same way like the micropython firmware for the Raspberry pi Pico (there are a bunch of tutorial for this).

Before I use it  with the sensecap watcher I want to try its ethernet capability. So I test the example from the wiznet github to get some http data.  And it worked flawlessly. The ethernet indicator LED's all  turned on. it means that the module is succesfully connected to the network.

After making sure the ethernet connection is running well, I want to make a simple web server that functioned to display the occupation status. After doing a quick google search I  found Microdot library that seems easy to use and familiar because it has almost the same structure with Flask framework. 

As a first test, I want to try to turned the onboard LED on the Ionic board using a simple web page. Since the original source code is meant for esp32 board, I have to make a few adjustment on the "network".

import machine
from microdot import Microdot, redirect, send_file
from machine import Pin,WIZNET_PIO_SPI
import network
import time

#W5x00 chip init
def w5x00_init():
   spi = WIZNET_PIO_SPI(baudrate=31_250_000, mosi=Pin(23),miso=Pin(22),sck=Pin(21)) #W55RP20 PIO_SPI
   nic = network.WIZNET5K(spi,Pin(20),Pin(25)) #spi,cs,reset pin
   nic.active(True)
   
#None DHCP
   nic.ifconfig(('192.168.0.180','255.255.255.0','192.168.0.1','8.8.8.8'))
   
#DHCP
   #nic.ifconfig('dhcp')
   print('IP address :', nic.ifconfig())
   
   while not nic.isconnected():
       time.sleep(1)
       print(nic.regs())

w5x00_init()
app = Microdot()


@app.route('/', methods=['GET', 'POST'])
def index(request):
   form_cookie = None
   message_cookie = None
   if request.method == 'POST':
       form_cookie = '{pin},{pull}'.format(pin=request.form['pin'],
                                           pull=request.form['pull'])
       if 'read' in request.form:
           pull = None
           if request.form['pull'] == 'pullup':
               pull = machine.Pin.PULL_UP
           elif request.form['pull'] == 'pulldown':
               pull = machine.Pin.PULL_DOWN
           pin = machine.Pin(int(request.form['pin']), machine.Pin.IN, pull)
           message_cookie = 'Input pin {pin} is {state}.'.format(
               pin=request.form['pin'],
               state='high' if pin.value() else 'low')
       else:
           pin = machine.Pin(int(request.form['pin']), machine.Pin.OUT)
           value = 0 if 'set-low' in request.form else 1
           pin.value(value)
           message_cookie = 'Output pin {pin} is now {state}.'.format(
               pin=request.form['pin'],
               state='high' if value else 'low')
       response = redirect('/')
   else:
       if 'message' not in request.cookies:
           message_cookie = 'Select a pin and an operation below.'
       response = send_file('gpio.html')
   if form_cookie:
       response.set_cookie('form', form_cookie)
   if message_cookie:
       response.set_cookie('message', message_cookie)
   return response


app.run(debug=True)
 

I thought that the adjustment will not  work instantly and I have to make few other configuration to make this work. But to my surprise my 1st adjustment for the code worked directly. This is the result.

For the Sensecap Watcher you just need to configure it through the sensecraft app on your mobile phone using this tutorial.

CONFIGURATION 

If you want to  run this system, First you need to download the code from my github repository 

https://github.com/chalei/ionic-room-occupation

The code is based on donskytech tutorial . I made a few changes on the uart and networking part in order to run this project.

ionic-room-occupation/

├── lib/                 # Contains libraries
├── static/              # Contains static resources (stylesheets, etc.)
├── templates/           # HTML templates for the web interface

├── gpio.py              # Manages GPIO interactions
├── occupy.py           # Controls LEDs via the web interface
└── watcher_read.py      # Handles data from the SenseCap Watcher

Open the "occupy.py" file and configure the IP address based on your network configuration.

Before running the file we need to ask the sensecap watcher to send a uart data when it see a person.

type "If  you see a person send uart data" on the chat box of the sensecraft app.

then on the configuration page make sure you tick the UART Output option and turned off the "include base 64" toggle button.

 

now you can check the sensecap watcher to check your configuration is working properly or not.

Now back to the Ionic board, Open the "occupy.py"  file on Thonny IDE,  make sure you already configure the IP address that work  in your network.

Run the file and open the IP address with the port 5000 (ipaddress:5000) on your browser then you will see web page like this

When a person or more is detected the toggle status will change to the right.

More clearer demo of the system you can check the video below

Huge Thanks To  Donsky for the microdot tutorial

 

Documents
  • Ionic Room Occpupation

Comments Write

Similar projects you might like

Identify a visitor's name using FaceRecognition and Alexa voice control. Control a door-locker using Alexa voice control with Chat-GPT3.

[AIoT] Smart Door Access with Alexa+GPT3+FaceRecognition

innovation4x
  • 1850

  • 0

Voice controlled home automation is an IoT-based project in order to control home appliances through voice commands.

[AIoT] Voice controlled Home Automation (Web-Based)

innovation4x
  • 1623

  • 0

"micropython-magic" is an extension that allows you to write and run MicroPython code in the Jupyter notebook environment.

micropython-magic

Benjamin
  • 1664

  • 0

This is a demonstration of two Wiznet W5500s running a micropython script that sets one unit as a server, and the other as a client, with a small data packet go

Pico Pi Wiznet W5500 Two-way comms via Ethernet with Micropython

scarlet
  • 1727

  • 0

일부 제조업체는 LLM Steak Classifier AIOT Bot 으로 알려진 Pi 기반 AI 고기 요리 모니터를 만든 개발자 Simon처럼 맛볼 수 있는 Raspberry Pi 프로젝트 를 만드는 방법을 확실히 알고 있습니다. 이 프로젝트는 실제 센서와 함께 ChatGPT를 사용하

Raspberry Pi 프로젝트가 잘 완료되었습니다. AI를 사용하여 고기를 완벽하게 요리합니다.

simons
  • 1098

  • 0

This post delves into WIZnet’s W5300 Indirect Mode with an 8-bit Data Bus.

WIZnet’s W5300 Indirect Address Mode with 8-bit Data Bus

Benjamin
  • 1664

  • 0

Use Hamming code to improve UDP accuracy

UDP Hamming code

momososo
  • 832

  • 0

Using MicroPython and WIZnet W5500 EVB-Pico, this project enables stable Ethernet communication for Raspberry Pi Pico, including DHCP, ping, and TCP socket test

🚀 Micropython with WIZnet W5500 EVB: Reliable Ethernet Communication for Raspberry Pi Pico

matthew
  • 150

  • 0