Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Manufacturing Technology >> Productieproces

SMART temperatuurbewaking voor scholen

Componenten en benodigdheden

Pycom SiPy
× 1
Raspberry Pi 3 Model B
× 1
Arduino Nano R3
× 1
SparkFun Logic Level Converter - bidirectioneel
× 1
NFC RFID-RC522
× 1
Scherpe GP2Y0A41SK0F (4cm - 30cm) - Analoge afstandssensor
× 1
MLX90614-DCI I2C - Temperatuursensor
× 1
DFRobot I2C 16x2 Arduino LCD-displaymodule
× 1
LED (generiek)
× 1
Weerstand 330 ohm
× 2
Zoemer
× 1

Apps en online services

Arduino IDE
Visual Studio-code (Pymakr)
ThingSpeak-API
IFTTT
Putty
IDLE IDE

Over dit project

PROBLEEMVERKLARING

Vanwege het warme weer en de uitbraak van het SARS (Severe Acute Respiratory Syndrome (SARS)) in Azië in 2003, moeten de leerlingen van het basis- en voortgezet onderwijs elk kwartaal de temperatuur meten om het welzijn van de leerlingen te garanderen. Wanneer er een temperatuurmeting door de school is gepland, moeten de studenten hun eigen digitale thermometer meenemen voor deze oefening. Sommige studenten kunnen echter niet deelnemen aan de oefening vanwege redenen zoals een misplaatste of beschadigde thermometer en vergeten het apparaat mee te nemen. Vanwege persoonlijke hygiëne mogen studenten hun thermometer niet delen en hebben ze mogelijk niet genoeg geld om een ​​nieuw stuk te kopen. Daarom beïnvloedt het het slagingspercentage van de temperatuurmeting. Na de oefening voor het meten van de temperatuur, moet het personeel de temperatuurgegevens van alle studenten en de studenten in het bijzonder handmatig invoeren in de database. De taak is erg vervelend en tijdrovend, aangezien elke leraar een formulier moet invullen voor ongeveer 40 studenten.

Wat is de oplossing?

Het thema van ons project is Social Impact van SqwidNet, en op het gebied van goede gezondheid en welzijn in de Sustainable Development Goal (SDG). De reden hiervoor is dat ons systeem kan worden ingezet om automatisch de temperatuur van geldige gebruikers te meten, zodat hun temperatuur kan worden gecontroleerd en er een waarschuwing wordt verzonden wanneer deze een bepaald drempelniveau overschrijdt.

HOE HET WERKT:RaspberryPi &Arduino

De RaspberryPi bevat een Python-programma en de MySQL-database.

Bij het starten van het Python-programma wordt automatisch gecontroleerd of de database al is gemaakt, zo niet, dan wordt deze automatisch gemaakt. De tabellen binnenin worden ook gecontroleerd en indien nodig automatisch gemaakt. Dit vermindert het handmatige werk van leraren/administratief personeel in de school.

Vervolgens brengt het een queryverbinding tot stand om de database te controleren en wacht tot de Arduino relevante informatie via de seriële communicatiepoort verzendt.

Als een RFID-kaart op de Arduino tikt, wordt de kaartinformatie opgeslagen in de Arduino en via seriële communicatie naar de RaspberryPi gestuurd. Daarna bevestigt RaspberryPi met de database dat de kaart een geldige gebruiker is, en als dat zo is, stuurt het naar de Arduino om het te bevestigen en de Arduino geeft "Welkom, naam" weer op het LCD-scherm. Als het geen geldige gebruiker is, zegt het gewoon "Fout! Ongeldige gebruiker!".

Laten we zeggen dat we nu een geldige gebruiker hebben die net heeft getikt. Vervolgens zal de Arduino de gebruiker vragen om hun temperatuur op te nemen. Een afstandssensor zal dan detecteren of een gebruiker klaar is om zijn temperatuur op te nemen. Als dat zo is, zal het hun temperatuur opnemen en hun temperatuur weergeven op het LCD-scherm. Als het een geldige temperatuur is (28*C - 42*C), wordt deze informatie zowel naar de RaspberryPi (MySQL) als naar Sigfox (ThingSpeak) gestuurd voor gegevensopslag. De MySQL-database zou de gebruikers-ID, datum, tijdstempel en de temperatuur van elke opname opslaan.

Bij het ontvangen van de temperatuurgegevens van de Arduino, zou de RaspberryPi constant controleren of de temperatuur correct wordt geleverd voordat hij verder gaat met iets anders. Dit komt omdat, als het Python-programma slechts één keer controleert op de temperatuurgegevens, deze mogelijk nog niet door de Arduino zijn verzonden, omdat beide code op verschillende tijdstippen worden uitgevoerd. Dus om te synchroniseren, controleren we constant de temperatuurgegevens op de Python-code voordat we verder gaan met de rest van het programma.

OPMERKING: Zowel de Python-code van de RaspberryPi als de Arduino-code maken gebruik van een synchronisatiemethode genaamd Handshaking. Als de RaspberryPi niet klaar is om andere temperatuur-/gebruikersinformatie te ontvangen, zou de Arduino de gebruiker niet toestaan ​​op de kaart te tikken, vice versa .

Een eenvoudige manier waarop ik dat deed, is door constant een "READY"-signaal te sturen totdat de andere partij een "RECEIVE"-signaal terugstuurt, zodat ze weten dat ze allebei klaar zijn.

Arduino -

boolean readySignal =Serial.readString() =="READY";


if(readySignal)
{

getapt =true;

Serial.println("RECEIVED");

}

Python -

while(readySignal ==True):

ser.write(b'' + "READY")



ReceivedSignal =ser.readline().strip() =="RECEIVED"


if(receivedSignal ==True):

readySignal =False

Vergeet niet om elke keer dat u klaar bent met een zoekopdracht, uw queryverbinding te sluiten! Dit is om elk mogelijk geheugenlek te elimineren en het is over het algemeen een goede gewoonte.

HOE HET WERKT:Sigfox (SiPy)

Na ontvangst van de temperatuurgegevens van de Arduino, scheidt de SiPy de gebruikers-ID en de temperatuur in hele getallen en decimalen. Nadat dit is gedaan, worden alle gegevens via bytes naar de Sigfox-backend gestuurd (zodat deze zowel naar Ubidots als naar ThingSpeak kan worden verzonden) en zou het er ongeveer zo uit moeten zien als de volgende afbeelding.

Na ontvangst hiervan zal de Sigfox-backend deze gegevens opnieuw coderen om naar ThingSpeak te worden verzonden om te worden opgeslagen. Hieronder ziet u hoe u de backend codeert voor het verzenden van gegevens naar thingspeak.

In de Sigfox-backend onder apparaattype> Apparaatnaam> CALLBACKS moet u de aangepaste payload precies zo invoeren als deze is tenzij u de codering in de SiPy hebt gewijzigd, aangezien de aangepaste payload instelt wat als eerste wordt ontvangen als de gebruikers-ID, dus als u bijvoorbeeld eerst de temperatuur opstuurt, zal deze op de backend die temperatuur naar de gebruikers-ID converteren in plaats van temperatuur. In de body moet de schrijf-api-sleutel bovenaan komen te staan, terwijl de velden kunnen worden geplaatst met alle aangepaste gegevens die u in de aangepaste payload hebt gemaakt.

HOE HET WERKT:de cloud

Nadat de gegevens met succes naar ThingSpeak zijn verzonden, ontvangt het deze eerst in een privéweergavekanaal waar een MATLAB-analysescript de gegevens analyseert en de temperatuurgegevens combineert tot één waarde in plaats van de scheiding van een geheel getal en een decimale waarde.

De tabelcode is afkomstig uit een open source-project en aangepast aan onze behoeften. Het is erg handig omdat de tabel automatisch wordt bijgewerkt elke keer dat er nieuwe gegevens worden verzonden, perfect voor ons gebruik.

Tegelijkertijd controleert het of de temperatuur gevaarlijk is (koorts), als dat het geval is, wordt er een e-mail verzonden om het personeel/docenten op de hoogte te stellen.

Samenvattend, het eerste kanaal waarvan de temperatuurwaarde is gescheiden in een geheel getal en een decimaal getal, is een backend-kanaal, niet echt om te bekijken. Voor het tweede kanaal zijn de temperatuurwaarden gecombineerd en leuk gemaakt voor personeel/management/beheerders om te bekijken en heeft een Excel-achtige tabel voor eenvoudige gegevensanalyse.

1. Arduino Nano-verbindingen instellen

Voor de Arduino Nano zijn dit de verbindingen die we met onze modules hebben gemaakt.

Nano en Uno hebben dezelfde pinout.

RFID - RC522

SDA D10
SCK D13
MOSI D11
MISO D12
IRQ NIET VERBONDEN
GND GND
RST D9
3.3V 3.3V

Hoe RFID te testen

LCD

SDA A4
SCL A5
GND GND
5V 5V

Hoe I2C LCD te testen

Afstandssensor

5V 5V
GND GND
Ingang A0

Hoe de Sharp IR-afstandssensor te testen

Zoemer

GND GND
Uitgang D6

Zoemer testen

IR Temperatuursensor

SDA A4
SCL A5
GND GND
5V 5V

Hoe de IR-temperatuursensor te testen,

LED

Vlakke zijde (kathode) GND
Niet-platte zijde (anode) D7

Goed! Voor de Arduino-verbindingen zou je nu goed moeten zijn om te gaan.

2. RaspberryPi-configuratie

Er zijn hoofdzakelijk twee dingen die op uw Raspberry Pi 3-machine moeten worden geïnstalleerd,

1. Raspbian-bediening Systeem -

De installatie van het Raspbian-besturingssysteem wordt als redelijk eenvoudig beschouwd.

Een kort antwoord over hoe u dit moet doen, is door een afbeeldingsbestand op een SD-kaart te flashen (schrijven) en deze SD-kaart in de Raspberry Pi 3 te steken.

Als u echter op zoek bent naar een stapsgewijze zelfstudie met lang antwoord, kunt u dit als volgt doen -

Ten eerste moet je software downloaden waarmee je flash.img-bestanden op een opslagstation kunt zetten. U kunt de software genaamd balenaEtcher gebruiken.

Ga daarna naar de Raspberry Pi - Raspbian-pagina en kies er een die bij je past. Ik koos voor de "Raspbian Buster met Desktop en aanbevolen software" omdat, zoals de naam al zegt, deze wordt geleverd met aanbevolen software en dat bespaart je het extra gedoe van het downloaden van software.

Als je klaar bent met de bovengenoemde stappen start u gewoon de balenaEtcher-software. Deze stap is vrij duidelijk:selecteer de afbeelding (uw.img Raspbian-bestand), selecteer vervolgens uw SD-kaart en druk op flash. Nu moet je gewoon wachten. Als het klaar is, zou het u moeten vragen en kunt u nu de nieuw geflitste SD-kaart in uw Raspberry Pi plaatsen.

Sluit hierna uw Raspberry Pi-machine via HDMI aan op een monitor en voer uw eerste installatie uit. Ga ten slotte naar Voorkeuren -> Raspberry Pi-configuratie en je zou in dit menu moeten zijn -

Volg de opties, deze stap maakt interfaces zoals SSH, VNC mogelijk waarmee je verbinding kunt maken met ip-adressen via eth0 of wlan0 (je hebt dus geen HDMI-kabel meer nodig, je kunt het allemaal via SSH doen).

(optionele stap) - Ik open de terminal en bewerk het dhcpcd.conf-bestand (sudo nano /etc/dhcpcd.conf) en ik voeg deze opdrachtregels toe,

interface eth0
statisch ip_address=192.168.0.11/24

Met het bovenstaande kan ik verbinding maken met de Raspberry Pi via een Ethernet-kabel met het statische adres, 192.168.0.11, dus ik weet elke keer dat dat het adres van mijn Raspberry Pi is.

Dit is een optiestap, want als je eenmaal bent verbonden met wifi, krijg je een wlan0 ip-adres waarmee je verbinding kunt maken met de Raspberry Pi zonder een Ethernet-kabel en overal op de locatie, zolang je verbonden bent met hetzelfde Wifi. Om te zien wat uw wlan0 IP-ADRES is, beweegt u uw muis over het WiFI-symbool in de rechterbovenhoek en dit wordt aangegeven.

Leuk! Je bent klaar met de installatie van je eerste Raspberry Pi!

3. MySQL-database instellen

Ik zou deze stap een beetje moeilijk vinden, vooral het gedeelte waar je de MySQL-rootgebruiker moet instellen, volg deze zorgvuldig omdat het erg moeilijk is om eventuele fouten te corrigeren.

Eerst moet u ervoor zorgen dat uw systeem is geüpgraded en bijgewerkt naar de nieuwste firmware. U kunt er zeker van zijn door deze commando's in te voeren,

sudo apt update
sudo apt upgrade

Nadat dit is gebeurd, installeert u apache2.

sudo apt install apache2 

Met Apache2 kun je een webserver maken zodat je later toegang hebt tot de websites die je maakt.

Zodra apache2 is geïnstalleerd, moet je PHP installeren.

sudo apt install php php-mbstring 

Met PHP kun je je eigen PHP-websites maken en bekijken.

Laten we stoppen en kijken of alles wat je zojuist hebt geïnstalleerd werkt, typ gewoon het IP-adres van je Raspberry Pi in je webbrowser of "localhost" als je nog steeds verbonden bent via HDMI, en je zou een Apache-indexpagina moeten zien.

Nu moet u de database installeren. Hiervoor gebruik je MySQL en mariadb.

sudo apt install mariadb-server php-mysql 

BELANGRIJK - Zorg ervoor dat u wat hieronder staat zeer aandachtig leest.

Nu gaat u uw MySQL-rootgebruiker maken, zodat u deze kunt gebruiken om toegang te krijgen tot de database.

sudo mysql --user=root 

U komt nu in een MySQL-sessie waar u MySQL-codes kunt typen, typ deze regel voor regel, (u kunt het wachtwoord vervangen door uw eigen wachtwoord)

DROP GEBRUIKER 'root'@'localhost';
CREER GEBRUIKER 'root'@'localhost' GEDENTIFICEERD DOOR 'wachtwoord';
VERLENEN ALLE RECHTEN OP *.* AAN 'root' @'localhost' MET SUBSIDIEOPTIE;
VOORRECHTEN VERLOPEN;
exit;

U kunt nu uw MySQL-rootgebruiker testen door in te loggen;

mysql --user=root --password=yourmysqlpassword 

Als het allemaal werkt, kunt u nu PHPMyAdmin installeren, het beheerdersdashboard waarmee u de MySQL-database kunt openen (bekijken) en wijzigen.

sudo apt install phpmyadmin

(na installatie)
sudo phpenmod mysqli
sudo /etc/init.d/apache2 restart

Gefeliciteerd! U hebt nu toegang tot uw nieuw gemaakte database met behulp van http://your_raspberrypi_ip_address/phpmyadmin.

4. SiPy Expansion Board 2.0 Installatie- en softwarehandleiding

Eerst moet u de SiPy-module op het uitbreidingsbord plaatsen met de resetknop naar de USB-connector gericht en moet deze stevig op zijn plaats klikken met de pinnen niet langer zichtbaar.

Bron:Pycom-documentatie

Hierna moet u de firmware op de SiPy bijwerken, zodat u programma's kunt uploaden en uitvoeren en de Sigfox Device ID en PAC-nummer kunt krijgen die zullen worden gebruikt om te registreren voor de Sigfox-backend. Download de firmware-updater volgens het besturingssysteem (besturingssysteem) dat u gebruikt.

  • Vensters
  • macOS (10.11 of hoger)
  • Linux (vereist dialoogvenster en python-serieel pakket)

Nadat u de pycom-firmware-upgrade hebt gedownload en u de updater voor de eerste keer start, zullen de volgende afbeeldingen slechts één keer verschijnen dus zorg ervoor dat u de juiste Sigfox-regio, bord selecteert.

Volg de instructies op de firmware-update zorgvuldig, aangezien dit ertoe kan leiden dat uw Sigfox niet goed functioneert, aangezien het Sigfox-apparaat-ID en PAC-nummer allemaal "F" zijn (zoals hieronder) in plaats van een combinatie van cijfers en alfabetten.

b 'FFFFFFFF'
b 'FFFFFFFFFFFFFFFF'

Nadat de firmware is bijgewerkt, moet u Visual Studio Code downloaden en de extensie Pymkr en nodejs installeren voordat u kunt beginnen met het uploaden en uitvoeren van programma's op de SiPy.

Ten eerste moet u een nieuwe map maken om alle bestanden die u later naar de SiPy gaat uploaden op te slaan of om alle programma's die u gaat uitvoeren op te slaan. Druk op bestand in de linkerbovenhoek en druk op Map openen of Ctrl+K+O, selecteer vervolgens waar u deze map wilt plaatsen en klik met de rechtermuisknop om een ​​nieuwe map te maken. Maak daarna een nieuw bestand of Ctrl+N om een ​​nieuw bestand te openen. Nadat je een nieuw bestand hebt gemaakt, moet je het nieuwe bestand opslaan als een python en het opslaan als type wijzigen in een python-bestand, zodat de code later op de SiPy kan worden uitgevoerd en het kan worden opgeslagen in de nieuwe map die je hebt gemaakt.

Opmerking: Bestandsnaam kan van alles zijn zoals Test, Trial, enz. Maar als het uploaden naar de SiPy-bestandsnaam main moet worden genoemd .

Om uw code uit te voeren zonder deze naar de Sipy-module te uploaden, hoeft u alleen maar op de knop Uitvoeren onder aan het programma te drukken. De upload ernaast uploadt de huidige map naar de SiPy-module. Wees voorzichtig bij het gebruik van while 1-loops, want als deze eenmaal zijn geüpload naar de SiPy-module, is de enige manier om weer toegang te krijgen tot de SiPy-module door FTP naar de flash te gebruiken en het main.py-bestand van de SiPy te verwijderen Module.

Als je per ongeluk een oneindige while-lus hebt toegevoegd, hoef je je geen zorgen te maken, want je kunt nog steeds je programma uploaden of het vorige verwijderen via FTP. Download eerst de gratis versie van filezilla en installeer deze.

Na de installatie moet u de verbinding instellen. Open eerst filezilla en ga naar sitemanager die onder bestand staat of druk op Ctrl+S en druk op nieuwe site.

U kunt de site hernoemen naar SiPy of hoe u deze verbinding ook wilt noemen en de instellingen voor codering wijzigen in Alleen gewone FTP gebruiken (onveilig) en zet instellingen over naar passief en beperk het aantal actieve verbindingen tot 1

U kunt de host (adres), gebruiker en wachtwoord vinden via Visual Studio Code door op alle opdrachten te drukken en algemene instelling te selecteren. Dit toont u de standaardinstellingen voor de host (adres), gebruiker (gebruikersnaam) en wachtwoord. Dit kan worden gewijzigd door op de projectinstellingen . te drukken in alle commando's.

Vervolgens moet u de SiPy Module SSID weten die u kunt vinden door alle commando's te gebruiken en op get WiFI AP SSID te drukken. Elke SSID van de SiPy Module is uniek, maar het wachtwoord is overal hetzelfde en kan niet worden gewijzigd. Wachtwoord voor SiPy Module SSID is www.pycom.io

Opmerking: Desktopgebruikers hebben een wifi-adapter nodig

Nu kunt u filezilla gaan gebruiken om toegang te krijgen tot de SiPy Flash! Maak eerst verbinding met de SiPy SSID, ga dan naar filezilla site manager en maak verbinding met de nieuwe site die je hebt gemaakt en typ het wachtwoord in. Open nu de flash-map en verwijder ALLEEN main.py! Nadat u de main.py hebt verwijderd, start u de SiPy opnieuw en kunt u beginnen met het uitvoeren/uploaden van uw programma's.

Opmerking: Misschien wilt u de flash-map naar uw besturingssysteem (besturingssysteem) kopiëren voor het geval u alles verwijdert.

5. Registreren bij Sigfox Backend

Sluit na het installeren van Visual Studio Code het pycom-uitbreidingsbord aan op de computer en het zal automatisch de verbinding detecteren wanneer u Visual Studio Code opent. Kopieer de onderstaande code en plak deze in de terminal of in een bestand en voer het uit. Beide methoden zijn voldoende.

van netwerkimport Sigfox
import binascii

# initialiseer Sigfox voor RCZ* (je hebt mogelijk een andere RCZ-regio nodig)
sigfox =Sigfox(mode=Sigfox .SIGFOX, rcz=Sigfox.RCZ*)

# print Sigfox Device ID
print(binascii.hexlify(sigfox.id()))

# print Sigfox PAC-nummer
print(binascii.hexlify(sigfox.pac()))

Opmerking :Vervang * door uw RCZ-regionummer.

Terminalmethode om Sigfox Device ID en PAC-nummer te krijgen

Om de terminal in Visual Studio Code te openen, drukt u op Ctrl+~. Plak vervolgens de code erin en het zal eruit zien als de volgende afbeelding.

Bestandsmethode om Sigfox Device ID en PAC-nummer te krijgen

Zodra het nieuwe bestand is opgeslagen door op Ctrl+S te drukken of naar bestand te gaan en vervolgens op te slaan, de code in het bestand te plakken en het bestand op te slaan, kunt u het bestand uitvoeren door op de knop Uitvoeren te drukken onderaan het scherm en zou hetzelfde moeten krijgen als de afbeelding hieronder.

Nadat u uw Sigfox-apparaat-ID en PAC-nummer hebt ontvangen, moet u uw Sigfox registreren bij de Sigfox-backend voordat u kunt beginnen met verzenden. De eerste pagina die u ziet, is waar uw sigfox-bedrijf is gevestigd. U moet het land kiezen waarin dit Sigfox-apparaat zal worden gebruikt, aangezien elk van de Sigfox-zones anders is geconfigureerd.

Nadat u het juiste land hebt gekozen, heeft u op de volgende pagina uw Sigfox-apparaat-ID en PAC-nummer nodig die u aan het begin van dit hoofdstuk hebt gekregen. Plak ze in het juiste veld en de pagina zou eruit moeten zien als de afbeelding. Wat de rest betreft, vul dienovereenkomstig.

Na het invullen van de apparaatpagina, het aanmaken van een Sigfox-account of inloggen op een bestaand Sigfox-account, moet u de Sigfox registreren op uw account. Als u een nieuw Sigfox-account aanmaakt, stuurt Sigfox u een e-mail naar het geregistreerde e-mailadres om het wachtwoord in te stellen.

Nadat je je sigfox backend-account hebt ingesteld, kun je deze code uitvoeren om wat gegevens te verzenden om te zien of de backend ze kan ontvangen.

Opmerking**: Sluit eerst uw sigfox-antenne aan voordat u een sigfox-programma uitvoert.

van netwerkimport Sigfox
import socket

# initialiseer Sigfox voor RCZ* (je hebt mogelijk een andere RCZ-regio nodig)
sigfox =Sigfox(mode=Sigfox .SIGFOX, rcz=Sigfox.RCZ*)

# maak een Sigfox-socket
s =socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)

# maak de socket blocking
s.setblocking(True)

# configureer het als alleen uplink
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)

# stuur enkele bytes
s.send(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]))

Opmerking :Vervang * door uw RCZ-regionummer.

6. De cloud instellen

Eerst moet u de IFTTT instellen voor e-mailen, naar de IFTTT-website gaan en een account aanmaken. Na het instellen van het account en inloggen, ga je naar je profiel dat zich in de rechterbovenhoek van het scherm aan de linkerkant van de "Verkennen" bevindt en druk je op de Maken .

Click "This " and then search for Webhooks and press it. If you are unsure, the following pictures will help you with what to do.

After selecting Webhooks, press the Receive a web request box and enter an event name to fit your requirements (in this example fever is used), afterwards press Create trigger .

Press the word "That ", type email in the search box and press Email then press Send me an email box

Enter message information. You can pass data about the event that triggered your message by using ingredients. For example, including {{Event Name}} adds the event name to your text message. The Body section must include at least {{Value1}} and {{Value2}}. Click Create action to finish the new applet. Note:Value 1, value 2 and value 3 in body message are derived from MATLAB Analysis and can be modified according to your requirement

ThingSpeak is an IOT (Internet of Things) platform which can be easily setup, learned and is open source.

First, we create two channels; (SIGFOX) TEMPERATURE PRIVATE VIEWING &(SIGFOX) TEMPERATURE PUBLIC VIEWING.

For the (SIGFOX) TEMPERATURE PRIVATE VIEWING , its purpose is to obtain data from the Sigfox backend. Sigfox sends up using bytes, this is because, we have realised that Ubidots (a web service) do not really work well with decoding Strings, so to make it work and accessible with both ThingSpeak and Ubidots, we chose to use bytes as it contain numbers from 0-255.

Therefore, using bytes makes it so we have to send both the whole number and the decimal number of the temperature information separately. So, this channel is mainly for keeping these messy values, later transferring to another channel for viewing which is the (SIGFOX) TEMPERATURE PUBLIC VIEWING channel.

We use MATLAB Analysis to convert the two messy values (whole number &decimal number) into just one combined value and transfer it onto the other channel. At the same time, we also transfer the userID onto the (SIGFOX) TEMPERATURE PUBLIC VIEWING as it's used for viewing. The MATLAB script is triggered on data insertion using a ThingSpeak REACT which will be explained below.

To setup the react, first go to Apps and then select React which will open the reacts tab. Press New React to create a new react for the MATLAB Analysis to be triggered when new data arrives from the Sigfox backend. Set the condition type to string, test frequency to on data insertion, condition to field 3 (which should be your userid) of the (SIGFOX) TEMPERATURE PRIVATE VIEWING when its not equal to 0, action to MATLAB Analysis with the code for calculating the temperature and Options to Run Action only the first time condition is met.

The table code was taken from an open sourced project and modified to suit our needs. It's very useful as the table auto updates every time a new data is sent in, perfect for our usage.

Unfortunately, the MATLAB plugin for the table is only view-able in private view and not in the public view. As it's intended for administrative purposes only, we do not subject this as an issue, it's intended to be only viewed in private view.

To retrieve Webhooks information, Click on your profile logo near the top right corner of the screen on the left of the “Explore” tab. Select My Services, select Webhooks then click documentation near the top right of the web page, from there you can see your key and format for sending a request. Enter that event name. The event name for this project is fever

https://maker.ifttt.com/trigger/{event}/with/key/(example)

https://maker.ifttt.com/trigger/fever/with/key/(example)

The service can be tested to see if it works or not by pasting the URL(example of the URL are shown above) into your browser or pressing the test button upon creation of the webhooks and email applet

After all that is done, you should be able to receive an email like the following picture, after you have finished setting up the ThingSpeak React.

Contributions

Aden - RaspberryPi + Arduino + its modules + ThingSpeak (MATLAB+ Setup)

Reginald - Sigfox + ThingSpeak Data Collection + Schematics

Bo Sheng - IFTTT Setup

Code

  • [C] ARDUINO NANO
  • [PYTHON] RaspberryPi
  • [MicroPython] Sigfox (Pycom)
  • [ThingSpeak] MATLAB SCRIPT
[C] ARDUINO NANOArduino
This code is used for checking if there's a RFID card tap, if there is, there will be temperature taking and also handshaking between the Raspberry Pi to send data over like the card's ID, temperature and ready/standby signal and more.

It also uses LCD to show informative information.

If you're interested in knowing more, please read the section on "HOW IT WORKS:RaspberryPi &Arduino"
/*90% is coded from scratch by Aden,http://www.astero.methe other 10% consists of open sourced libraries(Credits found below) used, like the RFID &temperature module.*//* * Initial Author:ryand1011 (https://github.com/ryand1011) * * Reads data written by a program such as "rfid_write_personal_data.ino" * * See:https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data * * Uses MIFARE RFID card using RFID-RC522 reader * Uses MFRC522 - Library * ----------------------------------------------------------------------------------------- * MFRC522 Arduino Arduino Arduino Arduino Arduino * Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro * Signal Pin Pin Pin Pin Pin Pin * ----------------------------------------------------------------------------------------- * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST * SPI SS SDA(SS) 10 53 D10 10 10 * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15*//***************** This is a library example for the MLX90614 Temp Sensor Designed specifically to work with the MLX90614 sensors in the adafruit shop ----> https://www.adafruit.com/products/1748 ----> https://www.adafruit.com/products/1749 These sensors use I2C to communicate, 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ******************/ // INCLUDE NECESSARY HEADER FILES #include #include #include #include #include #include // DEFINITION OF PINS#define RST_PIN 9 // Configurable, see typical pin layout above#define SS_PIN 10 // Configurable, see typical pin layout above#define BUZZER_PIN 7 //Pin define for Buzzer#define LED_PIN 6 //Pin define for LED #define dist_sensePin A0MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.LiquidCrystal_I2C lcd(0x27,16,2); // Calls the LiquidCrystal class and creats an instance for the LCD.// set the LCD address to 0x27 with 16 chars and 2 line displayAdafruit_MLX90614 mlx =Adafruit_MLX90614(); // Calls the Adafruit MLX90614 instance.SoftwareSerial unoSerial(2, 3); // RX, TX // Calls the SoftwareSerial instance (for Pycom communication)// GLOBAL VARIABLESboolean tapped =true; boolean confirmation =false;String GetUID(){ String card_UID=""; String card_UID_no_space =""; for (byte i =0; i  200)) // Check if there is actually a valid user infront of the machine. If no, it'll keep looping what's under. { dist_senseValue =analogRead(dist_sensePin); // Keep checking until there's a person that comes in the distance sensor's range. lcd.setCursor(0,0); lcd.print("Please take"); lcd.setCursor(0,1); lcd.print("your temperature."); // Prompt the user to take their temperature by standing infront of the machine. } digitalWrite(BUZZER_PIN, 1); digitalWrite(LED_PIN, 1); lcd.wissen(); // Turns on the Buzzer and LED, at the same time, clear the LCD too. meas_temp =(float)mlx.readObjectTempC(); temp_Hbyte =floor(meas_temp); temp_Lbyte =(meas_temp - temp_Hbyte) * 100; sMeasTemp +=userID; sMeasTemp +=","; sMeasTemp +=temp_Hbyte; sMeasTemp +=","; sMeasTemp +=temp_Lbyte; // Collect the temperature data that is taken. Serial.println("TEMP"); Serial.println(meas_temp); // Transfer the temperature data through Serial Communication to the RaspberryPi. if((meas_temp>
=28) &&(meas_temp <=42)) // Check if it's a valid temperature. unoSerial.print(sMeasTemp); // If it is, send to the sigfox module for cloud storage. lcd.setCursor(0,0); lcd.print("Temperature:"); lcd.setCursor(0,1); lcd.print(" " + String(meas_temp)); // Shows the temperature of the user through the LCD screen. } else // If it's an invalid user, { lcd.setCursor(0,0); lcd.print("Error!"); lcd.setCursor(0,1); lcd.print("Invalid User."); // Tells the user that he's not a valid user and he is unable to proceed to the temperature taking phase. } rawData =Serial.readString(); commaPos =rawData.indexOf(','); userInitial =rawData.substring(0, commaPos); // Above reads the incoming rawData again and converts into a userInitial variable. if(userInitial =="0") // If the user initial sent back is 0, it means that it's an invalid temperature because the RaspberryPi is unable to process it. { lcd.clear(); lcd.setCursor(0,0); lcd.print("Error!"); lcd.setCursor(0,1); lcd.print("Invalid Temperature."); // Prompts the user it's an invalid temperature range. } Serial.println("STANDBY"); // Sends Serial that the Arduino is still processing data. vertraging (1000); // Delay for 1 second. mfrc522.PICC_HaltA(); mfrc522.PCD_StopCrypto1(); } }
[PYTHON] RaspberryPiPython
This code is mainly used for updating the MySQL database and also to handshake with the Arduino via Serial Communication. It plays a vital role with the Arduino in this project

If you're interested in knowing more, please read the section on "HOW IT WORKS:RaspberryPi &Arduino".
'''Coded from scratch by Aden; for the Hackster.io Sigfox competition.http://www.astero.me'''# IMPORTSimport mysql.connectorimport serialimport osimport time# METHODSdef queryConnection():cursor =conn.cursor(buffered=True) cursor.execute("USE `" + databaseName + "`") # Use the userInfo database, return cursor # DATABASE INFORMATIONhost ="localhost"user ="root"password ="password"databaseName ="smartTemp"conn =mysql.connector.connect(host=host, user=user,passwd=password)# Serial CommunicationcomPort ='ttyUSB0'baudRate =9600ser =serial.Serial('/dev/' + comPort, baudRate, timeout=0) # Set the timeout as 0 so if it doesn't read a serial, it skips.print("Confirming USB Serial Port now, please wait") connected =False# Below, is to ensure that the RaPi receives the correct COM port of the Arduino board.for x in range(2):time.sleep(2) ser.write("RAPI") # Basically, here, we're writing to the Arduino to confirm communication. if connected ==False:serialConfirmation =ser.readline().strip() =="ARDUINO" # Check if the RaPi is reading the correct COM port, whether it can read the Arduino's serial communications. print(serialConfirmation) if(serialConfirmation ==False):comPort ='ttyUSB1' connected =True else:comPort ='ttyUSB0' connected =True print(comPort) ser =serial.Serial('/dev/' + comPort, baudRate) # Re-initiates this variable again, this time without a Serial Communication timeout. Meaning, it'll try to communicate with the Arduino w/o a timeout. print("COM PORT confirmed, using " + comPort) # Print to let you know which PORT the Arduino is on.# File CreationcountFile =open("count.txt", "a++") # Creates a count file if it doesn't exist.# GLOBAL VARIABLEStapRFID =Falsecursor =queryConnection()if(os.stat("count.txt").st_size ==0):# Checks if the count.txt is empty. print("Count has not been set, setting to 1 now.") count =1else:for countNumber in countFile:count =int(countNumber) # Set the count to the last counted count. print("Count has been restored from previous session:" + str(count)) try:# Tries to create the database if it doesn't already exists. print("Creating " + databaseName + " database now..") cursor.execute("CREATE DATABASE " + databaseName) # Create a database. print("Database has been sucessfully created.") except(mysql.connector.errors.DatabaseError):# If the database already exists, it excepts here. print(databaseName + " database is already created.") # If that database is found, run this block of code instead.cursor.execute("CREATE TABLE IF NOT EXISTS `userInfo` (id int, cardID VARCHAR(9), userID VARCHAR(4), userInitial VARCHAR(8))") # Create a userInfo table if it doesn't exist.cursor.execute("CREATE TABLE IF NOT EXISTS `tempData` (id int, userID VARCHAR(4), dateMeas date, timeMeas time, tempMeasure decimal(5,2))") # Create a tempData table if it doesn't exist.while True:# Endless loop. cursor =queryConnection() # Re-establishes the query connection using the queryConnection() method. cardID =str(ser.readline().strip()) # Reads the serial line and converts it to a String, stripping any empty spaces. cursor.execute("SELECT * FROM userInfo WHERE cardID ='" + cardID + "'") # Select the userInfo table with the inputted cardID from the Arduino. items =cursor.fetchone() # Fetch one line of the table. if(items !=None):# If it's able to fetch (valid user) print(cardID) # Print out the cardID that it's currently fetching. userID =str(items[2]) # Gets the userID from the fetched line. userDetails =str(items[3] + ", " + items[2]) # Get the userDetails from the fetched line. # Get the currentDate ¤tTime. currentDate =str(time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()))[0:10] currentTime =str(time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()))[11:] print(items) # Print the whole item array that was fetched. (for debugging) ser.write(b'' + userDetails) # Serial communication to the Arudino. countFile.close() # Closes the count file. countFile =open("count.txt", 'w') # Makes it so it overwrites the count file with the new saved count below. tempSignal =False while(tempSignal ==False):# Keeps looping until it gets the temperature reading from the Arduino. print("Getting Temperature") tempSignal =ser.readline().strip() =="TEMP" # Read the Arudino incoming serial. tempData =float(ser.readline().strip()) # Read the Arduino incoming serial of the temperature data. print(tempData) # Prints the retrieved temperature data from the Arduino. if(tempData>=28 and tempData <=42):# Check if the temperature is of a valid range. cursor.execute("INSERT INTO `tempData`(`id`, `userID`, `dateMeas`, `timeMeas`, `tempMeasure`) VALUES (" + str(count) + ",'" + userID + "','" + currentDate + "','" + currentTime + "','" + str(tempData) + "')") # Write into the database the necessary information. conn.commit() # Commit the INSERT changes into the database. count =count + 1 # Ups the count. countFile.write(str(count)) # Update the count file with the new count. else:# If it's not a valid temperature. ser.write(b'' + "0, 0") # Serial Communication to the Arduino informing that it's invalid temperature. else:# If it's not a valid user. ser.write(b'' + ", 0") # Serial Communication to the Arduino informing that no valid cardID is found. print("Nothing found") readySignal =ser.readline().strip() =="STANDBY" # Waits for the Arduino to tell that it's ready to do it again, to read/validate data. while(readySignal ==True):# If the Arduino is ready, loop until we're able to tell him back that we're also ready for another session. ser.write(b'' + "READY") # Serial communication basically to say we're ready too. print("sending") receivedSignal =ser.readline().strip() =="RECEIVED" if(receivedSignal ==True):readySignal =False print("received") cursor.close() # Close the query connection to prevent memory leaks. conn.close() # Closes the connection to the MySQL.
[MicroPython] Sigfox (Pycom)Python
This code is mainly used to read the serial communication from the Arduino and upload the received values to the Sigfox backend

If you're interested in knowing more, please read the section on "HOW IT WORKS:Sigfox (Pycom)"
'''100% is coded by Reginald,'''from machine import UART # Tx and Rx (``P3`` and ``P4``)from network import Sigfox # Import the sigfox library from the pycom controllerimport binascii # Import the Binary to ASCII library for converting from Binary (1,0) to ASCII (readable characters)import socket # Import socket module to enable socket connection for Sigfoximport time # Import time that can be used for delaysimport pycom # Import pycom module that contains fucntions that controls the pycom deviceimport sys # Import sys module to enable exit from the pycom running programpycom.heartbeat(False)#init Sigfox for RCZ4 (Asia)sigfox =Sigfox(mode=Sigfox.SIGFOX,rcz=Sigfox.RCZ4)uart1 =UART(1, baudrate=9600) # To set the serial communcation parametersuart1.init(9600,bits=8,parity=None, stop=1, pins =('P3', 'P4'), timeout_chars=20) # To set the serial communcation parameterswhile True:try:recv=uart1.readline() # It always reads the serial communcation for any messages if recv !=None:'''If there is a message recieved from the serial communcation, it will procced to establish the sigfox connection and process the message for sending''' #print Sigfox DeviceID print(binascii.hexlify(sigfox.id())) # print Sigfox PAC number print(binascii.hexlify(sigfox.pac())) #create Sigfox socket sk1 =socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) #make thesocket blocking sk1.setblocking(False) #configure as uplink only sk1.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) dataList =recv.decode("utf-8") #decode the received message print("dataList :%s" %(dataList)) split_val =dataList.split(",") #split the listing based on commas # eg. if receive message is 8,35,60 -> userID =8, temperature =35.60 degree celsius userID =int(split_val[0]) # assign the 1st element in the listing to userID. temp_H =int(split_val[1]) # assign the 2nd element in the listing to the whole number of the temperature. temp_L =int(split_val[2]) # assign the 3rd element in the listing to the decimal numner of the temperature. print("userID :%d temp_H :%d temp_L :%d" % (userID, temp_H, temp_L)) bData =[userID,temp_H,temp_L] # create a list print(bData) meas_temp =temp_H + (temp_L*0.01) # merge temperature values print("measure temperature :%.2f" %(meas_temp)) sk1.send(bytes(bData)) #cast the data list to bytes and send to Sigfox backend. sk1.close() #close Sigfox socket connection. time.sleep(5) #delay for 5 seconds. except KeyboardInterrupt:sys.exit() 
[ThingSpeak] MATLAB SCRIPTMATLAB
This script focuses on combining the raw data that is sent up by the Sigfox to ThingSpeak and put them together into a presentable visual state, allowing users to properly visualize the information. It also works alongside with IFTTT by triggering a webhook URL when it reaches a fever temperature, alerting user(s) via Email.

If you're interested in learning more about this code, please read the section on "HOW IT WORKS:ThingSpeak".
%% Made from scratch by Aden; for the Hackster.io Sigfox Competition.%% http://www.astero.mereadChannelID =870479; %% Channel to read.webhookTrigger ='https://maker.ifttt.com/trigger/student_fever/with/key/h10MdSGwjSPtZQ43wH-AgoiKI0pwaljBNnGUEu4Yecn';readAPIKey ='QGHINBPNJQKULBH2'; %% Channel read API Key.writeChannelID =870482; %% Channel to write.writeAPIKey ='R6NJIM8NT5A42R9N'; %% Channel write API Key.wholeNumber =thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', 1); %% Read the value from field 1 and save it to a variable.decimalNumber =thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', 2)/100;%% Read the value from field 2 and save it to a variable.userID =thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', 3);%% Read the value from field 3 and save it to a variable.display(wholeNumber, 'BEFORE') %% Display value for debugging.analyzedData =wholeNumber + decimalNumber; %% Converting the two into one whole number instead of two separate values.display(analyzedData, 'AFTER')display(userID, 'USERID')%%thingSpeakWrite(writeChannelID, analyzedData, 'Fields', 1, 'WriteKey', writeAPIKey);thingSpeakWrite(writeChannelID,'Fields',[1,2],'Values',{analyzedData,userID},'WriteKey', writeAPIKey)if(analyzedData>=38) %% Check if fever temperature. webwrite(webhookTrigger,'value1',analyzedData,'value2',userID); %% If yes, trigger the webhook and send an email of the values.end

Schema's

How everything is connected together Connections for Distance Sensor for Arduino Connections for Temperature Sensor Connections for LED for Arduino Connections for RFID for Arduino Connections for LCD for Arduino Connections for Buzzer for Arduino

Productieproces

  1. Temperatuurbewaking op de Raspberry Pi
  2. Temperatuur bewaken met Raspberry Pi
  3. DIY:temperatuurbewaking en -regeling voor HomeBrew
  4. CO2-monitoring met K30-sensor
  5. Slimme jaloezieën
  6. Contactloze temperatuurbewakingspoort
  7. Arduino - Stuur temperatuur naar internet via serieel
  8. 8-bit IO-poortbibliotheek voor Arduino
  9. Smart Hand Glove
  10. Health Band - Een slimme assistent voor ouderen
  11. Smart Farming:een uitgebreide IoT-oplossing voor landbouwmonitoring