工業製造
産業用モノのインターネット | 工業材料 | 機器のメンテナンスと修理 | 産業プログラミング |
home  MfgRobots >> 工業製造 >  >> Manufacturing Technology >> 製造プロセス

学校向けのSMART温度監視

コンポーネントと消耗品

>
Pycom SiPy
× 1
Raspberry Pi3モデルB
× 1
Arduino Nano R3
× 1
SparkFunロジックレベルコンバーター-双方向
× 1
NFC RFID-RC522
× 1
シャープGP2Y0A41SK0F(4cm-30cm)-アナログ距離センサー
× 1
MLX90614-DCII2C-温度センサー
× 1
DFRobot I2C 16x2 ArduinoLCDディスプレイモジュール
× 1
LED(汎用)
× 1
抵抗330オーム
× 2
ブザー
× 1

アプリとオンラインサービス

>
Arduino IDE
Visual Studio Code(Pymakr)
ThingSpeak API
IFTTT
パテ
IDLE IDE

このプロジェクトについて

<図>

問題の説明

アジアでは、2003年の暑さと重症急性呼吸器症候群(SARS)の発生により、小中学生は四半期ごとに体温測定を行い、生徒の健康を確保する必要があります。学校が温度測定の練習を予定している場合は、生徒はこの練習のために自分のデジタル体温計を持参する必要があります。ただし、体温計の置き忘れや破損などにより、運動中に参加できない生徒もいます。個人の衛生状態により、生徒は体温計を共有することができず、新しいものを購入するのに十分なお金がない可能性があります。したがって、それは体温運動の成功率に影響を与えます。温度測定の演習後、スタッフはすべての学生の温度データとデータベースに固有の学生を手動でキー入力する必要があります。各フォームの教師は約40人の生徒のエントリを実行する必要があるため、このタスクは非常に面倒で時間がかかります。

解決策は何ですか?

<図> <図>

私たちのプロジェクトのテーマは、SqwidNetによる社会的影響であり、持続可能な開発目標(SDG)の健康と福祉の分野です。その理由は、有効なユーザーの温度を自動的に測定するようにシステムを展開できるため、ユーザーの温度を監視し、特定のしきい値レベルを超えるとアラートが送信されるためです。

仕組み:RaspberryPiとArduino

RaspberryPiはPythonプログラムとMySQLデータベースを保持しています。

Pythonプログラムを起動すると、データベースがすでに作成されているかどうかが自動的にチェックされ、作成されていない場合は自動的に作成されます。内部のテーブルもチェックされ、必要に応じて自動的に作成されます。これにより、学校の教師/管理スタッフの手作業が軽減されます。

次に、データベースをチェックするためのクエリ接続を確立し、Arduinoがシリアル通信ポートを介して関連情報を送信するのを待ちます。

ArduinoをRFIDカードでタップすると、カード情報がArduinoに保存され、シリアル通信を介してRaspberryPiに送信されます。その後、RaspberryPiは、そのカードが有効なユーザーであることをデータベースで確認し、有効なユーザーである場合は、Arduinoに送信して確認し、ArduinoはLCD画面に「ようこそ、名前」を出力します。有効なユーザーでない場合は、「エラー!無効なユーザー!」とだけ表示されます。

<図>

今、タップしたばかりの有効なユーザーがいるとしましょう。次に、Arduinoはユーザーに体温を測定するように促します。距離センサーは、ユーザーが自分の体温を測定する準備ができているかどうかを感知します。もしそうなら、それは彼らの温度を取り、LCDスクリーンに彼らの温度を出力します。有効な温度(28 * C〜42 * C)の場合、この情報はデータ保存のためにRaspberryPi(MySQL)とSigfox(ThingSpeak)の両方に送信されます。 MySQLデータベースには、ユーザーID、日付、タイムスタンプ、および各撮影の温度が保存されます。

Arduinoから温度データを受信するとき、RaspberryPiは、他の処理に進む前に、温度が適切に配信されているかどうかを常にチェックします。これは、Pythonプログラムが温度データを1回だけチェックする場合、両方のコードが異なるタイミングで実行されるため、Arduinoによってまだ送信されていない可能性があるためです。そのため、同期するために、プログラムの残りの部分に進む前に、Pythonコードの温度データを常にチェックしています。

<図> <図> <図> <図>

注: RaspberryPiのPythonコードとArduinoコードはどちらも、ハンドシェイクと呼ばれる同期方法を利用しています。 RaspberryPiが別の温度/ユーザー情報を受信する準備ができていない場合、Arduinoはユーザーがカードをタップすることを許可しません。その逆

私が行った簡単な方法は、相手が「RECEIVE」信号を送り返すまで常に「READY」信号を送信して、両方の準備ができていることを知らせることです。

Arduino-

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


if(readySignal)
{

タップ=true;

Serial.println( "RECEIVED");

}

Python-

  while(readySignal ==True):

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



receiveSignal =ser.readline()。strip()=="RECEIVED"


if(receivedSignal ==True):

readySignal =False
>

クエリが完了するたびに、クエリ接続を閉じることを忘れないでください。これは、メモリリークの可能性を排除するためであり、全体としては良い習慣です。

仕組み:Sigfox(SiPy)

Arduinoから温度データを受信した後、SiPyはuserIDと温度を整数と小数点以下の桁数に分離します。これを行った後、すべてのデータはバイトを介してSigfoxバックエンドに送信され(UbidotsとThingSpeakに送信できるように)、次の図のようになります。

<図>

これを受信した後、Sigfoxバックエンドはこのデータを再コード化してThingSpeakに送信して保存します。以下に、thingspeakにデータを送信するためのバックエンドをコーディングする方法を示します。

Sigfoxバックエンドのデバイスタイプ>デバイス名>コールバックで、カスタムペイロードをそのまま入力する必要があります カスタムペイロードが最初に受信したものをユーザーIDとして設定するため、SiPyのコーディングを変更しない限り、たとえば、最初に温度を送信すると、バックエンドでその温度が温度ではなくユーザーIDに変換されます。本文では、書き込みAPIキーを上に配置する必要がありますが、フィールドは、カスタムペイロードで作成した任意のカスタムデータとともに配置できます。

<図>

仕組み:クラウド

データがThingSpeakに正常に送信された後、最初にプライベート表示チャネルでデータを受信します。ここで、MATLAB分析スクリプトがデータを分析し、整数値と10進数値を分離するのではなく、温度データを1つの値に結合します。

<図>

<図>

テーブルコードはオープンソースプロジェクトから取得され、ニーズに合わせて変更されました。新しいデータが送信されるたびにテーブルが自動更新されるので非常に便利で、私たちの使用法に最適です。

同時に、温度が危険なレベル(発熱)にあるかどうかをチェックします。危険なレベル(発熱)にある場合は、スタッフ/教師に通知するメールが送信されます。

<図>

要約すると、温度値が整数と10進数で区切られている最初のチャネルはバックエンドチャネルであり、実際には表示用ではありません。 2番目のチャネルでは、温度値が組み合わされ、スタッフ/管理者/管理者が表示しやすくなり、データ分析を容易にするためのExcelのようなテーブルがあります。

1. ArduinoNano接続のセットアップ

Arduino Nanoの場合、モジュールとの接続は次のとおりです。

ナノとウノのピン配置は同じです。

<図> <図>
  RFID-RC522 

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

RFIDのテスト方法

<図>
  LCD 

SDA A4
SCL A5
GND GND
5V 5V

I2CLCDのテスト方法

<図>
 距離センサー

5V 5V
GND GND
入力A0

シャープIR距離センサーのテスト方法

<図>
 ブザー

GND GND
出力D6

ブザーをテストする方法

<図>
  IR温度センサー

SDA A4
SCL A5
GND GND
5V 5V

IR温度センサーのテスト方法

<図>
  LED 

Flat Side(cathode)GND
Non-flat Side(Anode)D7

いいね! Arduino接続については、今すぐ行ってください。

2.RaspberryPiのセットアップ

Raspberry Pi3マシンにインストールする必要があるのは主に2つです。

1。 Raspbian Operating システム -

Raspbianオペレーティングシステムのインストールはかなり簡単だと考えられています。

その方法についての簡単な答えは、画像ファイルをSDカードにフラッシュ(書き込み)し、このSDカードをRaspberry Pi3に挿入することです。

ただし、ステップバイステップの長い回答のチュートリアルを探している場合は、次の方法で実行できます-

まず、flash.imgファイルをストレージドライブにフラッシュできるソフトウェアをダウンロードする必要があります。 balenaEtcherというソフトウェアを使用できます。

その後、Raspberry Pi-Raspbianページに移動し、ニーズに合ったものを選択します。 「デスクトップと推奨ソフトウェアを備えたRaspbianBuster」を選択したのは、その名前が示すように、推奨ソフトウェアが付属しているため、ソフトウェアをダウンロードする手間が省けるからです。

完了したら 前述の手順で、balenaEtcherソフトウェアを起動するだけです。この手順は非常に自明です。画像(your.img Raspbianファイル)を選択し、SDカードを選択して、フラッシュを押します。今、あなたはただ待つ必要があります。完了すると、プロンプトが表示され、新しくフラッシュされたSDカードをRaspberryPiに挿入できるようになります。

<図>

これに続いて、HDMI経由でRaspberry Piマシンをモニターに接続し、初期設定を行います。最後に、環境設定-> RaspberryPi構成に移動します。 そして、あなたはこのメニューにいるはずです-

<図>

オプションに従ってください。この手順により、SSH、VNCなどのインターフェースが有効になり、eth0またはwlan0を介してIPアドレスに接続できるようになります(HDMIケーブルは不要になり、SSHを介してすべて実行できます)。

(オプションの手順)-ターミナルを開いてdhcpcd.confファイル(sudo nano /etc/dhcpcd.conf)を編集し、これらのコマンドラインを追加します

  interface eth0 
static ip_address =192.168.0.11 / 24

上記の方法で、静的アドレス192.168.0.11のイーサネットケーブルを介してRaspberry Piに接続できるので、それが私のRaspberryPiのアドレスであることが毎回わかります。

これはオプションの手順です。WiFiに接続すると、wlan0 ipアドレスを取得して、イーサネットケーブルなしで、同じ場所に接続している限り、その場所のどこにでもRaspberryPiに接続できるようになります。 Wi-Fi。 wlan0のIPアドレスを確認するには、右上にあるWi-Fi記号の上にマウスを置くだけで表示されます。

<図>

いいね! これで、RaspberryPiの初期設定は完了です。

3.MySQLデータベースのセットアップ

この手順は少し難しいと思います。特に、MySQLのrootユーザーを設定する必要がある部分では、エラーを修正するのが非常に難しいため、注意深く実行してください。

まず、システムがアップグレードされ、最新のファームウェアに更新されていることを確認する必要があります。これらのコマンドを入力して確認できます

  sudo apt update 
sudo apt upgrade

これが完了したら、apache2をインストールします。

  sudo apt install apache2  

Apache2を使用すると、Webサーバーを作成できるため、後で作成するWebサイトにアクセスできます。

apache2をインストールしたら、PHPをインストールする必要があります。

  sudo apt install php php-mbstring  

PHPを使用すると、独自のPHPWebサイトを作成して表示できます。

インストールしたばかりのすべてが機能しているかどうかを確認してみましょう。WebブラウザにRaspberryPiのIPを入力するか、HDMI経由で接続している場合は「localhost」と入力すると、Apacheインデックスページが表示されます。

<図>

次に、データベースをインストールする必要があります。このためには、MySQLとmariadbを使用します。

  sudo apt install mariadb-server php-mysql  

重要 -以下をよくお読みください。

次に、MySQL rootユーザーを作成して、それを使用してデータベースにアクセスできるようにします。

  sudo mysql --user =root  

ここで、MySQLコードを入力し、これらを1行ずつ入力できるMySQLセッションに入ります(パスワードを独自のパスワードに置き換えることができます)

  DROP USER'root '@' localhost '; 
CREATE USER'root' @ 'localhost' IDENTIFIED BY'password ';
GRANT ALL PRIVILEGES ON *。* TO'root' @ 'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

ログインしてMySQLrootユーザーをテストできるようになりました;

  mysql --user =root --password =yourmysqlpassword  

すべてが機能する場合は、MySQLデータベースにアクセス(表示)および変更するための管理者コントロールパネルであるPHPMyAdminをインストールできます。

  sudo apt install phpmyadmin 

(インストール後)
sudo phpenmod mysqli
sudo /etc/init.d/apache2 restart

おめでとうございます! これで、http:// your_raspberrypi_ip_address / phpmyadminを使用して新しく作成したデータベースにアクセスできます。

<図>

4.SiPy拡張ボード2.0セットアップおよびソフトウェアガイド

まず、リセットボタンをUSBコネクタに向けて、SiPyモジュールを拡張ボードに挿入する必要があります。ピンが見えなくなった状態でしっかりとカチッとはまります。

<図> <図>

出典:Pycomドキュメント

その後、SiPyのファームウェアを更新して、プログラムをアップロードして実行したり、Sigfoxバックエンドの登録に使用されるSigfoxデバイスIDとPAC番号を取得したりできるようにする必要があります。使用しているOS(オペレーティングシステム)に応じてファームウェアアップデータをダウンロードしてください。

  • ウィンドウズ
  • macOS(10.11以降)
  • Linux( ダイアログが必要) および python-serial パッケージ)

pycomファームウェアアップグレードをダウンロードした後、アップデーターを初めて起動すると、次の画像は1回だけ表示されます したがって、正しいSigfoxリージョン、ボードを選択していることを確認してください。

<図>

ファームウェアアップデートの指示に注意深く従ってください。SigfoxデバイスIDとPAC番号がすべて「F」(以下のように)であり、数字とアルファベットが混在しているように、Sigfoxが正しく機能しなくなる可能性があります。

  b'FFFFFFFF '
b'FFFFFFFFFFFFFFFF'

ファームウェアが更新されたら、SiPyでプログラムのアップロードと実行を開始する前に、Visual Studio Codeをダウンロードし、拡張機能Pymkrとnodejsをインストールする必要があります。

<図>

まず、後でSiPyにアップロードするすべてのファイルを保存するため、または実行するすべてのプログラムを保存するために、新しいフォルダーを作成する必要があります。左上隅にあるファイルを押し、フォルダを開くまたはCtrl + K + Oを押します 次に、このフォルダを配置する場所を選択し、右クリックして新しいフォルダを作成します。その後、新しいファイルまたはCtrl + N を作成します 新しいファイルを開きます。新しいファイルを作成したら、新しいファイルをpythonとして保存し、[名前を付けて保存]の種類をpythonファイルに変更して、後でSiPyでコードを実行し、作成した新しいフォルダーに保存できるようにする必要があります。

<図> <図>

注: ファイル名は、テスト、トライアルなどのいずれかになります。ただし、SiPyファイル名にアップロードする場合は、メインを呼び出す必要があります。 。

Sipy Moduleにコードをアップロードせずにコードを実行するには、プログラムの下部にある実行ボタンを押すだけです。その横にあるアップロードは、現在のフォルダーをSiPyモジュールにアップロードします。 while 1ループを使用する場合は注意してください。これらがSiPyモジュールにアップロードされると、SiPyモジュールに再度アクセスする唯一の方法は、フラッシュにFTPで転送し、メイン.pyファイルをSiPyから削除することです モジュール。

<図>

誤って無限のwhileループを追加した場合でも、FTPを介してプログラムをアップロードしたり、前のプログラムを削除したりできるため、心配する必要はありません。まず、filezillaの無料バージョンをダウンロードしてインストールします。

<図>

インストール後、接続を設定する必要があります。まず、filezillaを開き、ファイルの下にあるサイトマネージャーに移動するか、Ctrl + Sを押して新しいサイトを押します。

<図>

サイトの名前をSiPyまたはこの接続と呼びたいものに変更し、暗号化の設定をプレーンFTPのみを使用する(安全でない)に変更できます。 設定をパッシブに転送し、アクティブな接続の数を1に制限します

<図> <図>

すべてのコマンドを押してグローバル設定を選択することで、Visual Studio Codeからホスト(アドレス)、ユーザー、およびパスワードを見つけることができます。 これにより、ホスト(アドレス)、ユーザー(ユーザー名)、およびパスワードのデフォルト設定が表示されます。これは、プロジェクト設定を押すことで変更できます すべてのコマンドで。

<図> <図> <図>

次に、すべてのコマンドを使用して[Wi-Fi APSSIDの取得]を押して見つけることができるSiPyモジュールSSIDを知る必要があります。 各SiPyモジュールのSSIDは一意ですが、パスワードは全体を通して同じであり、変更することはできません。 SiPy ModuleSSIDのパスワードはwww.pycom.ioです

<図> <図>

注: デスクトップユーザーはWiFiアダプターを入手する必要があります

これで、filezillaを使用してSiPyFlashにアクセスできるようになりました。最初にSiPySSIDに接続し、次にfilezillaサイトマネージャーに移動して、作成した新しいサイトに接続し、パスワードを入力します。次に、フラッシュフォルダを開き、 main.pyのみを削除します! main.pyを削除した後、SiPyを再起動すると、プログラムの実行/アップロードを開始できます。

<図> <図>

注: すべてを削除する場合に備えて、フラッシュフォルダをOS(オペレーティングシステム)にコピーすることをお勧めします。

5.Sigfoxバックエンドへの登録

Visual Studio Codeをインストールした後、pycom拡張ボードをコンピューターに接続すると、Visual StudioCodeを開いたときに接続が自動的に検出されます。以下のコードをコピーして、ターミナルまたはファイルに貼り付けて実行します。 どちらの方法でもかまいません。

  from network import Sigfox 
import binascii

#initalise Sigfox for RCZ *(別のRCZリージョンが必要な場合があります)
sigfox =Sigfox(mode =Sigfox .SIGFOX、rcz =Sigfox.RCZ *)

#printSigfoxデバイスID
print(binascii.hexlify(sigfox.id()))

#print SigfoxPAC番号
print(binascii.hexlify(sigfox.pac()))

:*をRCZリージョン番号に置き換えます。

SigfoxデバイスIDとPAC番号を取得するための端末方法

Visual Studio Codeでターミナルを起動するには、Ctrl +〜を押します。次に、コードを中に貼り付けると、次の図のように表示されます。

<図>

SigfoxデバイスIDとPAC番号を取得するためのファイルメソッド

Ctrl + Sを押すか、ファイルに移動して保存し、コードをファイルに貼り付けてファイルを保存することで新しいファイルを保存したら、実行ボタンを押してファイルを実行できます。 画面の下部にあり、下の画像と同じになるはずです。

<図>

SigfoxデバイスIDとPAC番号を取得したら、送信を開始する前に、SigfoxをSigfoxバックエンドに登録する必要があります。最初に表示されるページは、sigfoxの会社が拠点を置いている場所です。各Sigfoxゾーンは異なる構成になっているため、このSigfoxデバイスを使用する国を選択する必要があります。

<図>

正しい国を選択したら、次のページで、この章の冒頭で取得したSigfoxデバイスIDとPAC番号が必要になります。それらを正しいフィールドに貼り付けると、ページは画像のように見えるはずです。残りはそれに応じて埋めます。

<図>

デバイスページに入力した後、Sigfoxアカウントを作成するか、既存のSigfoxアカウントにログインしたら、Sigfoxをアカウントに登録する必要があります。新しいSigfoxアカウントを作成する場合、Sigfoxは登録された電子メールにパスワードを設定するための電子メールを送信します。

<図>

sigfoxバックエンドアカウントを設定したら、このコードを実行してデータを送信し、バックエンドがそれらを受信できるかどうかを確認できます。

注**: sigfoxプログラムを実行する前に、まずsigfoxアンテナを接続してください。

  from network import Sigfox 
import socket

#initalise Sigfox for RCZ *(別のRCZリージョンが必要な場合があります)
sigfox =Sigfox(mode =Sigfox .SIGFOX、rcz =Sigfox.RCZ *)

#Sigfoxソケットを作成
s =socket.socket(socket.AF_SIGFOX、socket.SOCK_RAW)

#ソケットをブロックする
s.setblocking(True)

#アップリンクのみとして構成する
s.setsockopt(socket.SOL_SIGFOX、socket.SO_RX、False)

#いくつかのバイトを送信
s.send(bytes([1、2、3、4、5、6、7、8、9、10、11、12]))

:*をRCZリージョン番号に置き換えます。

6.クラウドのセットアップ

まず、メール用にIFTTTを設定し、IFTTT Webサイトにアクセスして、アカウントを作成する必要があります。アカウントを設定してログインしたら、[探索]の左側にある画面の右上隅の近くにあるプロフィールに移動し、[作成] を押します。 。

<図> <図>

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

コード

  • [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.clear(); // 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. delay(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

回路図

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

製造プロセス

  1. ラズベリーパイの温度監視
  2. ラズベリーパイで温度を監視する
  3. DIY:HomeBrewの温度監視と規制
  4. K30センサーによるCO2モニタリング
  5. スマートブラインド
  6. 無接触温度監視ゲート
  7. Arduino-シリアル経由でWebに温度を送信
  8. Arduino用の8ビットIOポートライブラリ
  9. スマートハンドグローブ
  10. ヘルスバンド-高齢者向けのスマートアシスタント
  11. スマートファーミング:農業モニタリングのための包括的なIoTソリューション