Cov txheej txheem:

EnergyChain: 4 Kauj Ruam
EnergyChain: 4 Kauj Ruam

Video: EnergyChain: 4 Kauj Ruam

Video: EnergyChain: 4 Kauj Ruam
Video: Warframe | We All Lift Together 2024, Kaum ib hlis
Anonim
Zog zog
Zog zog

/ * Ua haujlwm tseem tab tom ua haujlwm */

Lub Zog Hluav Taws Xob yog POC uas ua ke IOT thiab Blockchain.

Qhov peb tau tso cai rau tib neeg muag lub zog uas lawv tsim rau leej twg yam tsis muaj qib xav tau. Txhawm rau kom muaj kev nyab xeeb ntawm tus tsim khoom thiab tus neeg siv khoom, tus neeg siv khoom tuaj yeem txuas txhua yam nws xav tau ntawm nws thiab tau txais lub zog. Lub npov ntsuas tus nqi siv tam sim no thiab sau qhov sib npaug

Kauj ruam 1: Cov ntaub ntawv

Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv

Txhawm rau ua cov phiaj xwm no peb yuav siv:

- 1 Raspberry Pi Zero

- 1 qhov ntsuas tam sim no AS712 (20A)

- 1 ADC 16 ntsis I2C ADS1555

- 1 RFID sensor RC522

- 1 relay 5V

- 1AC/DC 5V/2A hloov pauv ECL10US05-E los ntawm Farnell

- 1 qhov hluav taws xob

Kauj ruam 2: Kev thaiv kab

Thaiv
Thaiv

Peb yuav tsum tau xaim txhua yam ua ke raws li nws tau qhia hauv daim duab, ceev faj rau tam sim no xa los ntawm Raspberry Pi.

Cov kab hais kom ua:

  • 3v3 Hwj chim - Txuas 5V Vcc/Tam Sim No Sensor Vcc/RFID Vcc/ADC Vcc
  • 5v Hwj chim - AC/DC hloov pauv 5v
  • Hauv av - Siv 5V GND/Tam Sim No Sensor GND/AC/DC hloov GND/RFID GND/ADC cov tswv yim thiab tso tawm GND
  • BCM 2 - ADC SDA
  • BCM 3 - ADC SCL
  • BCM 4 - ADC CLK
  • BCM 6 - RFID SDA
  • BCM 9 - RFID MISO
  • BCM 10 - MOSI RFID
  • BCM 11 - RFID SCK
  • BCM 17 - Tshaj Tawm 5V IN
  • BCM 24 - Pib RFID
  • BCM 25 - RFID RST

Kauj ruam 3: Code

Txoj cai no ua haujlwm raws li hauv qab no:

RFID sensor tos rau ib daim ntawv thiab sau nws hauv Terminal. Then lub ntsuas tam sim no ntsuas tus nqi AC tam sim no siv thiab tso tawm hauv lub davhlau ya nyob twg lub zog tam sim ntawd txhua 100 ntsuas. Ua tsaug rau qhov ntawd, peb tuaj yeem tau txais tus nqi kWh.

ntshuam ntsaws, json

ntshuam sys los ntawm xov ntshuam ntshuam Xov los ntawm pirc522 ntshuam RFID ntshuam RPi. GPIO li GPIO ## Ntshuam GPIO tsev qiv ntawv ntshuam teeb liab ntshuam lub sijhawm ntshuam Adafruit_ADS1x15 GPIO.setmode (GPIO. BOARD) GPIO.setup (11, GPIO. OUT) GPIO.output (11, Tseeb) rdr = RFID () siv = rdr.util () siv.debug = Tseeb TCP_IP = '172.31.29.215' TCP_PORT = 5000 BUFFER_SIZE = 1024 adc = Adafruit_ADS1x15. ADS1115 () def end_read (teeb liab, thav duab): thoob ntiaj teb khiav print ("\ nCtrl+C ntes, xaus nyeem.") khiav = Cuav rdr.cleanup () sys.exit () signal.signal (signal. SIGINT, end_read) def loopRead (s): DemandeTag = 1 DemandeMesure = 0 bol = Muaj tseeb thaum (bol): yog DemandeTag == 1: tag () DemandeTag = 0 DemandeMesure = 1 yog DemandeMesure == 1: Mesure2 () sim: data = s.recv (BUFFER_SIZE) yog tias tsis yog cov ntaub ntawv: tawg cov ntaub ntawv luam tawmJSON = json.loads (cov ntaub ntawv) yog "cov lus" hauv cov ntaub ntawv JSON: luam tawm cov ntaub ntawv JSON ['lus'] yog cov ntaub ntawv JSON ['xov'] == "tawm": luam tawm ('Tawm qhov xav tau') GPIO.output (11, GPIO. HIGH) DemandeTag = 0 DemandeMesure = 0 bol = False yog dataJSON ['message'] == "on": GPIO.output (11, GPIO. LOW) DemandeMesure = 1 DemandeTag = 1 yog dataJSON ['message'] == "off": GPIO.output (11, GPIO. HIGH) DemandeTag = 1 message = '' zam tshwj tsis yog e: txuas ntxiv s.close () def tag (): rdr.wait_for_tag () (yuam kev, cov ntaub ntawv) = rdr.request () time.sleep (0.25) (yuam kev, uid) = rdr.anticoll () ID = str (uid [0])+'. '+str (uid [1])+'. '+str (uid [2])+'. '+str (uid [3]) print ("Card nyeem UID:"+ID) GPIO.output (11, GPIO. LOW) def Mesure (): mesure_voltage = 0 Nbre_mesure = 100 i = 0 thaum kuv def Mesure2 (): mesure_voltage = 0 Nbre_mesure = 200 max_voltage = 0 min_voltage = 32768 mVparAmp = 100 Puissance = 0 i = 0 readValue = 0 thaum imax_voltage: max_voltage = readValue yog readValue def Mesure3 (): print (str (adc.read_adc (0, nce = 1))) yog _name_ == "_main_": s = socket.socket (socket. AF_INET, socket. SOCK_STREAM) #s.connect ((TCP_IP, TCP_PORT)) #s.setblocking (0) loopRead (s)

Kauj ruam 4: Lub thawv

Txhawm rau ua txhua yam khoom siv hluav taws xob ntau dua, peb tsim lub thawv uas yuav muaj txhua yam hauv. Txhawm rau ntsia hlau rau txhua yam peb yuav siv M3 ntsia hlau.

Pom zoo: