Cov txheej txheem:

Wireless Encrypted Kev Sib Txuas Lus Arduino: 5 Kauj Ruam
Wireless Encrypted Kev Sib Txuas Lus Arduino: 5 Kauj Ruam

Video: Wireless Encrypted Kev Sib Txuas Lus Arduino: 5 Kauj Ruam

Video: Wireless Encrypted Kev Sib Txuas Lus Arduino: 5 Kauj Ruam
Video: Niam tais thab ntxhais thaub laus tsaus muag(qub dab neeg) 2/18/2022 2024, Hlis ntuj nqeg
Anonim
Wireless Encrypted Kev Sib Txuas Lus Arduino
Wireless Encrypted Kev Sib Txuas Lus Arduino

Nyob zoo sawv daws, Hauv kab lus thib ob no, kuv yuav piav qhia koj yuav siv lub nti Atecc608a li cas kom ruaj ntseg rau koj kev sib txuas lus wireless. Txog qhov no, Kuv yuav siv NRF24L01+ rau Wireless ntu thiab Arduino UNO.

Micro chip ATECC608A tau tsim los ntawm MicroChip thiab tau txais ntau yam cuab yeej ruaj ntseg. Piv txwv, cov nti no tuaj yeem khaws ECC Keys, AES Keys (rau AES 128) thiab SHA2 Hash.

Kab lus: NRF24L01 + Arduino UNO + ATECC608A

Thaum sib tham ntawm ob lub hom phiaj IoT, muaj ntau qhov kev tawm tsam tuaj yeem muaj: Tus txiv neej ntawm qhov muag me me, Luam cov ntaub ntawv thiab ntau ntxiv.. Yog li kuv lub tswv yim yooj yim heev:

  1. Kev siv cov ntaub ntawv encrypted ntawm ob lossis ntau dua IoT khoom.
  2. Cov khoom siv qis
  3. Ua haujlwm nrog Arduino UNO

Hauv kuv qhov xwm txheej, kuv siv

  • Atecc608a khaws kuv tus lej AES thiab encrypt/decrypt kuv cov ntaub ntawv.
  • Arduino Uno ua Microcontroller
  • NRF24L01 xa kuv cov ntaub ntawv

Koj yuav tsum ua raws cov theem rau qhov haujlwm no:

  1. Teeb lub nti ATECC608A
  2. Ua qhov Circuit Court (Master Node and Slave Node)
  3. Tshooj cai
  4. Mus Ntxiv!

Rau thawj kauj ruam "Teeb tsa lub nti ATECC608A", Kuv tau sau lwm tsab xov xwm uas piav qhia txhua kauj ruam hauv kev txiav txim. Qhov txuas yog nyob ntawm no:

Tam sim no pib!

Khoom siv

Rau qhov haujlwm no koj xav tau:

  • 2 Arduino UNO lossis Arduino NANO lossis Arduino Mega
  • Ib co xaim
  • 2 Atecc608a (txhua tus nqi qis dua 0.60 $)
  • 2 NRF24L01+
  • 2 capacitor (10 μF)
  • Cov qhob cij

Txuas rau kuv kab lus uas piav qhia txog teeb tsa lub nti ATECC608A -> Yuav teeb Atecc608a li cas

Kauj Ruam 1: 1. Teeb Atecc608a

1. Teeb Atecc608a
1. Teeb Atecc608a
1. Teeb Atecc608a
1. Teeb Atecc608a

Kuv yuav tsis qhia meej txhua kauj ruam ua raws los teeb tsa ATECC608A vim tias kuv tau sau kab lus tag nrho uas piav qhia txhua kauj ruam los ua nws. Txhawm rau teeb tsa nws, koj yuav tsum ua raws "Kauj Ruam 4" ntawm kab lus no hu ua "2. Kev teeb tsa ntawm Chip (Atecc608a)"

Qhov txuas yog: Yuav teeb tsa ATECC608A li cas

Tsis tas li, koj yuav tsum tau teeb tsa tib qho kev teeb tsa rau Atecc608a, tus tswv sab thiab tus qhev sab, txwv tsis pub koj yuav tsis tuaj yeem thim koj cov ntaub ntawv

Ceeb toom:

Txhawm rau teeb tsa lub nti no, koj yuav tsum ua raws txhua kauj ruam ntawm tsab xov xwm saum toj no hauv kev txiav txim. Yog tias ib kauj ruam ploj lossis lub nti tsis xauv, koj yuav tsis muaj peev xwm ua txoj haujlwm no

Qhov seem:

Kauj ruam los ua raws qhov no:

  • Tsim tus qauv teeb tsa
  • Sau daim ntawv no rau tus nti
  • Xauv qhov Config Zone
  • Sau koj tus lej AES (128 Khoom) hauv qhov qhib
  • Xauv Cov Ntaub Ntawv Thaj Tsam

Kauj Ruam 2: 2. Tsim ntawm Circuit (Master thiab Slave)

2. Tsim ntawm Circuit (Master thiab Slave)
2. Tsim ntawm Circuit (Master thiab Slave)
2. Tsim ntawm Circuit (Master thiab Slave)
2. Tsim ntawm Circuit (Master thiab Slave)

Hauv txoj haujlwm no, koj yuav muaj Master Node thiab Slave Node.

Tus tswv node yuav luam tawm cov ntaub ntawv xa los ntawm qhev qhev ntawm qhov tseeb. Nws yuav thov cov ntaub ntawv los ntawm tus qhev ntawm txhua X lub sijhawm.

Tus qhev qhev yuav mloog "network" thiab thaum nws tau txais "Thov cov ntaub ntawv", nws yuav tsim nws, encrypt nws thiab xa nws mus rau tus tswv node.

Rau ob sab, tus tswv thiab tus qhev ntawm Circuit yog tib yam:

  • Ib qho arduino Nano
  • Ib qho ATECC608A
  • 1 NRF24L01

Kuv txuas lub Circuit Court rau cov kauj ruam no (cf daim duab saum toj no).

Rau ATECC608A rau Arduino UNO, qhov no yog soic 8 tus pin. Kuv ntxiv qhov "saib sab saum toj" saum toj no:

  • ARDUINO 3.3V -> PIN 8 (Atecc608a)
  • ARDUINO GND -> PIN 4 (Atecc608a)
  • ARDUINO A4 (SDL) -> PIN 5 (Atecc608a)
  • ARDUINO A5 (SCL) -> PIN 6 (Atecc608a)

Rau NRF24L01 rau Arduino:

  • ARDUINO 3.3V -> VCC (nrf24l01)
  • ARDUINO GND -> GND (nrf24l01)
  • ARDUINO 9 -> CE (nrf24l01)
  • ARDUINO 10 -> CSN (nrf24l01)
  • ARDUINO 11 -> MOSI (nrf24L01)
  • ARDUINO 12 -> MISO (nrf24l01)
  • ARDUINO 13 -> SCK (nrf24l01)
  • ARDUINO 3 -> IRQ (nrf24l01) -> tsuas yog rau qhev qau, tsis siv hauv Hom Master

Vim li cas siv tus pin IRQ ntawm NRF24L01

IRQ tus pin muaj txiaj ntsig zoo, tus pin no tso cai hais (LOW) thaum tau txais pob ntawv los ntawm NRF24L01, yog li peb tuaj yeem txuas qhov cuam tshuam rau tus pin no kom sawv ntawm tus qhev.

Kauj Ruam 3: 3. Txoj Cai (Qhev thiab Xib Hwb)

3. Txoj Cai (Qhev thiab Xib Hwb)
3. Txoj Cai (Qhev thiab Xib Hwb)

Qav Node

Kuv siv lub zog txuag rau tus qhev Node vim nws tsis xav mloog txhua lub sijhawm.

Nws ua haujlwm li cas: tus qhev node mloog thiab tos kom tau txais "Wake UP packet". Cov pob ntawv no yog xa los ntawm Master node kom nug cov ntaub ntawv los ntawm tus qhev.

Hauv kuv qhov xwm txheej kuv siv qhov array ntawm ob int:

// Tsa pob ntawv

const koj wake_packet [2] = {20, 02};

Yog tias kuv lub pob tau txais pob ntawv,

  1. nws sawv, nyeem cov pob ntawv no, yog tias pob ntawv yog "Wake UP",
  2. nws tsim cov ntaub ntawv,
  3. encrypt cov ntaub ntawv,
  4. xa cov ntaub ntawv mus rau tus tswv, tos ACK pob ntawv,
  5. tsaug zog.

Txog AES Kev Nkag Siab, Kuv siv tus yuam sij hauv tus lej 9.

Nov yog kuv tus lej rau Slave node

#suav nrog "Arduino.h" #suav nrog "avr/sleep.h" #suav nrog "avr/wdt.h"

#suav nrog "SPI.h"

#suav nrog "nRF24L01.h" #suav nrog "RF24.h"

#suav nrog "Wire.h"

// ATECC608A lub tsev qiv ntawv

#include "ATECCX08A_Arduino/cryptoauthlib.h" #suav nrog "AES BASIC/aes_basic.h"

#define ID_NODE 255

#define AES_KEY (uint8_t) 9

ATCAIfaceCfg cfg;

ATCA_STATUS xwm txheej;

RF24 xov tooj cua (9, 10);

const uint64_t masteraddresse = 0x1111111111;

const uint64_t slaveaddresse = 0x1111111100;

/**

* / Cov lus luv luv Ua tiav thaum qhov cuam tshuam tau teeb tsa (IRQ QIB) * * */ tsis muaj dab tsi wakeUpIRQ () {thaum (xov tooj cua.available ()) {int cov ntaub ntawv [32]; xov tooj cua.read (& cov ntaub ntawv, 32); yog (data [0] == 20 && data [1] == 02) {ntab temp = 17.6; ntab hum = 16.4;

uint8_t cov ntaub ntawv [16];

uint8_t cypherdata [16];

// Tsim txoj hlua txhawm rau teeb tsa tag nrho kuv tus nqi

// Txhua tus nqi sib cais los ntawm "|" thiab "$" txhais tias qhov kawg ntawm cov ntaub ntawv // CEEB TOOM: Yuav tsum muaj tsawg dua 11 txoj hlua ntev tmp_str_data = hlua (ID_NODE) + "|" + Txoj hlua (temp, 1) + "|" + Txoj hlua (hum, 1) + "$"; // qhov loj ntawm 11 Serial.println ("tmp_str_data:" + tmp_str_data);

tmp_str_data.getBytes (cov ntaub ntawv, qhov loj ntawm (cov ntaub ntawv));

// Nkag mus rau cov ntaub ntawv

ATCA_STATUS xwm txheej = aes_basic_encrypt (& cfg, cov ntaub ntawv, qhov loj ntawm (cov ntaub ntawv), cypherdata, AES_KEY); yog (xwm txheej == ATCA_SUCCESS) {ntev Rand = random ((ntev) 10000, (ntev) 99999));

// tsim kom muaj UUID raws li peb tus lej thawj = ID node

Txoj hlua uuid = Txoj hlua (ID_NODE) + Txoj hlua (rand); // Qhov loj ntawm 8

uint8_t tmp_uuid [8];

uint8_t data_to_send [32];

uuid.getBytes (tmp_uuid, sizeof (tmp_uuid) + 1);

memcpy (data_to_send, tmp_uuid, sizeof (tmp_uuid));

memcpy (data_to_send + sizeof (tmp_uuid), cypherdata, sizeof (cypherdata)); // Tsis txhob mloog xov tooj cua.stopListening ();

kub rslt;

// Xa Cov Ntaub Ntawv rslt = radio.write (& data_to_send, sizeof (data_to_send)); // Pib Mloog xov tooj cua.startListening (); yog (rslt) {// Xaus thiab pw hom Serial.println (F ("Ua Tiav")); }

void teeb tsa ()

{Serial.begin (9600);

// Pib lub constuctor rau lub tsev qiv ntawv

cfg.iface_type = ATCA_I2C_IFACE; // Hom kev sib txuas lus -> I2C hom cfg.devtype = ATECC608A; // Hom nti cfg.atcai2c.slave_address = 0XC0; // I2C addresse (default value) cfg.atcai2c.bus = 1; cfg.atcai2c.baud = 100000; cfg.wake_delay = 1500; // Ncua ntawm sawv (1500 ms) cfg.rx_retries = 20;

xov tooj cua.begin ();

xov tooj cua.setDataRate (RF24_250KBPS); xov tooj cua.maskIRQ (1, 1, 0); xov tooj cua.enableAckPayload (); xov tooj cua.setRetries (5, 5);

xov tooj cua.openWritingPipe (masteraddresse);

xov tooj cua.openReadingPipe (1, slaveaddresse); // Txuas cuam tshuam rau tus pin 3 // Hloov 1 los ntawm O yog tias koj xav kom cuam tshuam rau tus pin 2 // FALLING MODE = Pin ntawm LOW attachInterrupt (1, wakeUpIRQ, FALLING); }

void lub voj ()

{// Tsis xav tau}

Tswv Node

Tus tswv node sawv txhua txhua 8 thib ob los nug cov ntaub ntawv los ntawm qhev Node

Nws ua haujlwm li cas: Tus tswv node xa pob "WakeUP" mus rau tus qhev thiab tom qab tos cov lus teb ntawm tus qhev nrog cov ntaub ntawv.

Hauv kuv qhov xwm txheej kuv siv qhov array ntawm ob int:

// Tsa pob ntawv

const koj wake_packet [2] = {20, 02};

Yog tias tus qhev node xa ACK pob ntawv tom qab tus tswv xa WakeUp pob ntawv:

  1. Tswv teeb tsa hauv Mloog hom thiab tos kev sib txuas lus
  2. Yog kev sib txuas lus
  3. Luam tawm thawj 8 byte, nyiag peb peb thawj byte ntawm 8 bytes, yog tias qhov no yog tus lej ID
  4. Tshem tawm 16 byte ntawm cypher
  5. Decrypt cov ntaub ntawv
  6. Luam cov ntaub ntawv hauv Serial
  7. Pw tsaug zog hom

Txog AES Kev Nkag Siab, Kuv siv tus yuam sij hauv tus lej 9.

Nov yog kuv tus lej rau Master node

#suav nrog "Arduino.h"

#include "avr/sleep.h" #include "avr/wdt.h" #include "SPI.h" #include "nRF24L01.h" #include "RF24.h" #include "Wire.h" // ATECC608A lub tsev qiv ntawv #include "ATECCX08A_Arduino/cryptoauthlib.h" #include "AES BASIC/aes_basic.h" #define ID_NODE 255 #define AES_KEY (uint8_t) 9 ATCAIfaceCfg cfg; ATCA_STATUS xwm txheej; RF24 xov tooj cua (9, 10); const uint64_t masteraddresse = 0x1111111111; const uint64_t slaveaddresse = 0x1111111100; // Wake UP packet const int wake_packet [2] = {20, 02}; // watchdog cuam tshuam ISR (WDT_vect) {wdt_disable (); // lov tes taw watchdog} void sleepmode () {// disable ADC ADCSRA = 0; // tshem ntau yam "rov pib dua" tus chij MCUSR = 0; // tso cai hloov pauv, rov pib dua WDTCSR = ntsis (WDCE) | ntsis (WDE); // teeb tsa hom cuam tshuam thiab ncua sijhawm WDTCSR = ntsis (WDIE) | ntsis (WDP3) | ntsis (WDP0); // teeb WDIE, thiab 8 vib nas this ncua wdt_reset (); // rov pib lub watchdog set_sleep_mode (SLEEP_MODE_PWR_DOWN); noInterrupts (); // ncua sijhawm ua ntu zus raws li sleep_enable (); // tua tawm xim av ‐ tawm ua haujlwm hauv software MCUCR = ntsis (BODS) | ntsis (BODSE); MCUCR = ntsis (BODS); cuam tshuam (); // lav kev qhia tom ntej ua tiav sleep_cpu (); // thim kev pw tsaug zog raws li kev ceeb toom sleep_disable (); } void teeb () {Serial.begin (9600); // Init constuctor rau lub tsev qiv ntawv cfg.iface_type = ATCA_I2C_IFACE; // Hom kev sib txuas lus -> I2C hom cfg.devtype = ATECC608A; // Hom nti cfg.atcai2c.slave_address = 0XC0; // I2C addresse (default value) cfg.atcai2c.bus = 1; cfg.atcai2c.baud = 100000; cfg.wake_delay = 1500; // Ncua ntawm sawv (1500 ms) cfg.rx_retries = 20; xov tooj cua.begin (); xov tooj cua.setDataRate (RF24_250KBPS); xov tooj cua.maskIRQ (1, 1, 0); xov tooj cua.enableAckPayload (); xov tooj cua.setRetries (5, 5); xov tooj cua.openWritingPipe (slaveaddresse); xov tooj cua.openReadingPipe (1, masteraddresse); } tsis muaj dab tsi voj () {bool rslt; // Xa Cov Ntaub Ntawv rslt = radio.write (& wake_packet, sizeof (wake_packet)); yog (rslt) {// Pib Mloog xov tooj cua.startListening (); thaum (xov tooj cua.available ()) {uint8_t teb [32]; xov tooj cua.read (& teb, sizeof (teb)); uint8_t node_id [3]; uint8_t cypher [16]; memcpy (node_id, teb, 3); memcpy (cypher, teb + 3, 16); yog ((int) node_id == ID_NODE) {uint8_t tso zis [16]; ATCA_STATUS xwm txheej = aes_basic_decrypt (& cfg, cypher, 16, tso tawm, AES_KEY); yog (xwm txheej == ATCA_SUCCESS) {Serial.println ("Cov Ntaub Ntawv Rov Qab:"); rau (size_t i = 0; i <16; i ++) {Serial.print ((char) tso tawm )); }}}}}} lwm {Serial.println ("Ack tsis tau txais rau Wakup Pob"); } // Pw tsaug zog hom 8 thib ob sleepmode (); }

Yog tias koj muaj lus nug, Kuv nyob ntawm no los teb nws

Kauj Ruam 4: 4. Mus Ntxiv

Qhov piv txwv no yooj yim yog li koj tuaj yeem txhim kho txoj haujlwm no

Kev txhim kho:

  • AES 128 yog qhov yooj yim thiab koj tuaj yeem siv lwm txoj hauv kev ntawm AES ua AES CBC kom muaj kev nyab xeeb dua.
  • Hloov cov wireless wireless (NRF24L01 txwv los ntawm kev them nyiaj ntawm 23 Bytes)

Yog tias koj pom kev txhim kho los ua, piav qhia nws ntawm thaj chaw sib tham

Kauj Ruam 5: Xaus

Kuv vam tias tsab xov xwm no yuav muaj txiaj ntsig zoo rau koj. Thov txim yog tias kuv ua yuam kev hauv kuv cov ntawv tab sis lus Askiv tsis yog kuv hom lus thiab kuv hais tau zoo dua li kuv sau.

Ua tsaug rau kev nyeem txhua yam.

Txaus siab rau nws.

Pom zoo: