วันพุธที่ 14 กุมภาพันธ์ พ.ศ. 2561

Raspberry pi Node.JS Webserver + WebSocket Control LED


Raspberry pi NodeJS Webserver + WebSocket Control LED

This article show how to use raspberry pi to be NodeJS webserver and control LED via websocket.

What is WebSocket?

WebSocket enables bidirectional communication in real time over the web.
WebSocket can be run together with a normal HTTP server. You can click a button in a web browser, and enable a GPIO on your Raspberry Pi which turns on a light in your house. All in real time, and with communication going both ways!

System Diagram



Wiring Diagram

Hardware
Raspberry Pi Board
LED
Push Button Switch
Resistor 100 - 470 Ohm ( for LED )
Resistor 1K - 50K Ohm ( for Pull-up switch )



This is my raspberry pi development board.






Software and Library

Check Node Version

$ node -v 

If you don't have node. Install Node first

curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -

sudo apt-get install nodejs

Then install npm

Install From Source
curl https://www.npmjs.com/install.sh | sudo sh

or install linux package
sudo apt-get install npm


check npm version

$ npm -v  

Install the onoff Module

To interface with the GPIO on the Raspberry Pi using Node.js, we will use a Module called "onoff".
Install the onoff module using npm:

$ npm install onoff


Install socket.io for Node.js

To download and install newest version of socket.io, use the following command:

$ npm install socket.io --save



Source Code


webserver.js

Public/index.html


Demo

Run Node.js Webserver 

$ node webserver.js


Open on Web Browser on your Raspberry pi IP address and port 8080


Control on Checkbox on Web Browser or Push Button Switch on Raspberry pi Board.
End the program with Ctrl+c.



Reference

https://www.w3schools.com/nodejs/nodejs_raspberrypi.asp


My Website

email : info@softpowergroup.net  ,amphancm@gmail.com  Tel .+6681-6452400

Android and Arduino IoT

วันอาทิตย์ที่ 4 กุมภาพันธ์ พ.ศ. 2561

Raspberry pi connect RFID Reader ( SL500 USB )


Raspberry pi connect RFID Reader ( SL500 USB )

We 'd like to use RFID card with Raspberry pi board for eMoney or RFID cash card  Application in canteen of school.

RFID Reader


We want to use USB RFID Reader. we choose RFID reader model SL500 USB.
For Thailand Shop http://arduinoandroid.lnwshop.com/product/4/rfid-nfc-reader-writer 

RFID Card


Famous RFID tag is NXP Mifare MF-1.


Overview


NXP® has developed the MIFARE® MF1ICS50 to be used in a contactless smart card according to ISO/IEC 14443 Type A.
The MIFARE MF1ICS50 IC is used in applications like public transport ticketing where major cities have adopted MIFARE as their e-ticketing solution of choice.
1.1 Key applications
  • Public transportation
  • Access control
  • Event ticketing
  • Gaming & identity
1.2 Anticollision
An intelligent anticollision function allows to operate more than one card in the field simultaneously. The anticollision algorithm selects each card individually and ensures that the execution of a transaction with a selected card is performed correctly without data corruption resulting from other cards in the field.
1.3 Simple integration and user convenience
The MF1ICS50 is designed for simple integration and user convenience. Which could allow complete ticketing transactions to be handled in less than 100 ms. Thus, the MF1ICS50 card user is not forced to stop at the reader leading to a high throughput at gates and reduced boarding times onto busses. The MIFARE card may also remain in the wallet during the transaction, even if there are coins in it.
1.4 Security
  • Mutual three pass authentication (ISO/IEC DIS 9798-2)
  • Individual set of two keys per sector (per application) to support multi-application with key hierarchy
  • Unique serial number for each device

  • 1 Kbyte, organized in 16 sectors with 4 blocks of 16 bytes each (one block consists of 16 byte)
  • User definable access conditions for each memory block
  • Data retention of 10 years.

Library and Demo

Read Block 0 ( Manufacturer Block )


         b0 88 3f 7b 7c                  88 04                          44 85 00 b4 2e f0 bb 6a a8

Source code on Github

https://github.com/amphancm/RaspberryPi_rfid_sl500

CODE
SL500 Python Library - rfid_sl500.py
Example Code
Read Block0 16 Bytes data - read_block0.py
Read loop - loop.py

Reference

SL500 C language

python