Pratyush Mallick
Published © MIT

Forest Guardian

A low-power solar-run device that detects illegal logging of wood at the edge using acoustic data.

IntermediateFull instructions providedOver 4 days1,993

Things used in this project

Hardware components

QuickFeather Dev Kit with UART Cable + SensiML
QuickLogic Corp. QuickFeather Dev Kit with UART Cable + SensiML
×1
MikroE SOLAR ENERGY CLICK
×1
XBee S2C
×1
Power Profiler Kit
Nordic Semiconductor Power Profiler Kit
×1
SparkFun XBee Explorer Regulated
SparkFun XBee Explorer Regulated
×1
Rechargeable Battery, Lithium Ion
Rechargeable Battery, Lithium Ion
×1
Product Enclosure
×1

Software apps and online services

SensiML DataCapture & Analytics Studio
nRF Connect SDK
Nordic Semiconductor nRF Connect SDK

Hand tools and fabrication machines

Drill, Screwdriver
Drill, Screwdriver
Soldering iron (generic)
Soldering iron (generic)
Solder Flux, Soldering
Solder Flux, Soldering
Prototyping Board

Story

Read more

Schematics

Circuit Diagram

Quickfeather to Peripheral Connections

Code

Gateway Script

Python
The script here fetches the data from the XBee coordinator over Uart and then sends the data to the thingspeak server.
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 29 22:52:08 2021

@author: Pratyush 
"""

import serial
import time
import thingspeak

channel_id =   # PUT CHANNEL ID HERE
write_key_my = ""  # PUT YOUR WRITE KEY HERE

serialPort = serial.Serial(
    port="COM19", baudrate=115200, bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE
)
serialString = ""  # Used to hold data coming over UART
channel = thingspeak.Channel(id=channel_id, api_key=write_key_my )
while 1:
    # Wait until there is data waiting in the serial buffer
    if serialPort.in_waiting > 0:

        # Read data out of the buffer until a carraige return / new line is found
        serialString = serialPort.readline()

        # Print the contents of the serial data
        try:
            val = serialString.decode("Ascii")
            
            # Stripping out recognition results according to the 
            # device state
            if(val.startswith('Result')):
                recog_class = (val.split(":")[1]).strip()
                
            elif(val.startswith('Infer')): 
                response_state =  "1"
                
            elif(val.startswith('Sleep')):
                response_state = "2"
            
            # Using thingspeak APIs to update the channel
            response = channel.update({1: recog_class,2: response_state })
            print(response)
            print(val)

        except:
            pass

Sms Alert Script

MATLAB
The script is designed to display a custom image on the widget screen and trigger an SMS alert according to the value of the channel field.
import matlab.net.*
import matlab.net.http.*

%% Channel Info %%
channelID = % Channel ID here 
channelReadKey = '' % Not needed for public channel
sensorText = ''
field = 1 % Field to annotate

trigger = uint16(0)
%% Fetch Data %%
lastValue = thingSpeakRead(channelID, 'ReadKey', channelReadKey)';
channelData = webread(strcat('https://api.thingspeak.com/channels/', ...
                                num2str(channelID), ...
                                '/feeds.json?metadata=true&api_key=', ...
                                channelReadKey));
%% Extract & Prepare Data %%
metadata = jsondecode(channelData.channel.metadata);
fieldData = metadata.('field' + string(field));
% Read the sensor image from the URL provided in the metadata
img = websave('field-img.jpg', fieldData.image);

if lastValue(1) == 1
    sensorText = "Axe Detected"
elseif lastValue(1) == 2
    sensorText = "Chainsaw Detected"
elseif lastValue(1) == 3
    sensorText = "Normal"
    trigger = trigger + 1
end

%% Display Data %%
% Create an empty figure
figure('Color', 'white', 'Menu', 'none');
axis off
% Place the sensor name and data
text(0, 1, sensorText, 'FontSize', 25, 'VerticalAlignment', 'top');

% Create new axes to assist in placing the image
% Positioning is [bottomLeftX bottomLeftY width height]
axes('pos', [0 0 1 1]);
axis off
% Place the image
imshow(img);

if trigger < 4 & trigger > 0
    r = 'pi_key=< Twilio API KEY here >'
    uri ='https://api.thingspeak.com/apps/thinghttp/send_request?api_key=< Twilio API KEY here >'
    response = webwrite(uri,r)
elseif trigger == 10
    trigger = 0
end

%title(sprintf('Last updated at: %s',datetime('now')))

Forest Guardian Source Code

Contains all the source code for the project.

Credits

Pratyush Mallick

Pratyush Mallick

3 projects • 10 followers
I love tinkering, taking things apart, and making them work. Happy Hacking

Comments