Cov txheej txheem:

Txuas Txuas Txuas Txuas: 5 Cov Kauj Ruam
Txuas Txuas Txuas Txuas: 5 Cov Kauj Ruam

Video: Txuas Txuas Txuas Txuas: 5 Cov Kauj Ruam

Video: Txuas Txuas Txuas Txuas: 5 Cov Kauj Ruam
Video: Kaus txuas xa moo 2/3/2019 2024, Hlis ntuj nqeg
Anonim
Txuas nrog Stopwatch
Txuas nrog Stopwatch
Txuas nrog Stopwatch
Txuas nrog Stopwatch
Txuas nrog Stopwatch
Txuas nrog Stopwatch

Nyob zoo! Hauv qhov kev qhia no koj yuav pom yuav ua li cas txuas ib qho khoom siv Arduino sib xws, nruab nrog WiFi, rau REST APIs! Qhov no siv GitKraken Glo Board webapp los tsim cov laug cam, kab thiab daim npav los npaj khoom!

Qee qhov kev paub ntawm yuav ua li cas pej xeem API ua haujlwm xav tau. Txoj haujlwm no yog siv los siv GitKraken Glo's API txhawm rau taug qab lub sijhawm koj siv rau kev ua haujlwm ntawm koj Cov npe ua.

Piv txwv li, koj yuav tsum tau ua cov haujlwm no:

- Haus kas fes

Koj nias pib thaum koj pib, thaum koj ua tiav, koj nias Ua tiav, thiab voilà, lub sijhawm koj siv tau txais kev tawm tswv yim.

Kauj ruam 1: Tsim

Tsim
Tsim
Tsim
Tsim

Txhawm rau tsim, koj tuaj yeem xav txog dab tsi. Lub moos me me yuav zoo heev, tab sis kuv tsis tau ua dab tsi me me tso ib ncig.

Yog li cardboard thiab arcade laub khawm yog txoj hauv kev mus!

Pawg thawj coj kuv siv yog ESP8266 WeMos D1 Mini. Qhov no pheej yig dua li Arduino, thiab muaj WiFi onboard!

Lub vijtsam yog Nokia 5110 LCD.

n

Daim ntawv teev npe ntawm AliExpress:

  • Nokia 5110 NPE
  • 2 Arcade Nyees khawm
  • ESP8266
  • Jumper xov hlau
  • Lub thawv ntawv

Tab sis koj tuaj yeem pom nws nyob qhov twg lossis ntawm lwm lub vev xaib zoo li Amazon lossis eBay.

Cov nqi tag nrho: 5 € 86

Pins kev sib txuas:

ESP8266 WeMos D1 Mini, Nokia 5110 LCD

  • D2 (GPIO4) ↔ 0 RST
  • D1 (GPIO5) ↔ 1 CE
  • D6 (GPIO12) ↔ 2 DC
  • D7 (GPIO13) ↔ 3 DIN
  • D5 (GPIO14) ↔ 4 CLK
  • 3V3 ↔ 5 VCC
  • D0 (GPIO16) ↔ 6 BL
  • G (GND) ↔ 7 GND

ESP8266 WeMos D1 Mini -Arcade Nyees khawm

D3 (GPI18) ↔ Left Button

D4 (GPI17), Txoj Cai Khawm

Khawm lwm tus pin txuas nrog hauv av (GND).

Kauj ruam 2: Code

Code
Code
Code
Code
Code
Code

Tsuas yog muab tus lej rau kuv

Koj tuaj yeem pom tag nrho cov cai ntawm no:

github.com/antoinech/glo-stopwatch

Txhawm rau nws ua haujlwm rau koj, koj yuav tsum tau hloov cov kev hloov pauv no:

// Muab koj daim ntawv pov thawj WiFi tso rau ntawm no charst* ssid = "--your-ssid--"; const char* password = "--your-password--"; // Muab Koj Tus Kheej Tus Kheej (Token Access token) (https://support.gitkraken.com/developers/pats/) const char *bearer = "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

Koj tseem yuav xav tau 2 lub tsev qiv ntawv Adafruit:

github.com/adafruit/Adafruit-GFX-Library

github.com/adafruit/Adafruit-PCD8544-Nokia…

Thiab qhov txaus ntshai Arduino Json:

arduinojson.org/

Cov lus piav qhia

Hauv qhov chaws koj yuav pom:

  • yuav ua li cas txuas rau HTTPS qhov kawg
  • yuav ua li cas POST lossis GET thov
  • yuav ua li cas serialize JSON cov lus teb kom tau txais cov khoom thiab cov pawg
  • yuav ua li cas tso saib cov ntawv thiab duab hauv Nokia 5110 LCD

Yog tias koj xav kawm paub ntau ntxiv txog qhov API no:

support.gitkraken.com/developers/overview/

Cov kev thov no tuaj yeem ua haujlwm nrog ib qho API nyob deb uas siv POST thiab GET thov:)

Kauj Ruam 3: Txuas mus rau HTTPS Lub Vev Xaib

Tus lej pseudo no piav qhia koj yuav ua li cas txuas rau HTTPS lub vev xaib. Nws thawj kauj ruam yog tib yam li nrog a

WiFiClient tus thov kev pab

tab sis nrog cov kauj ruam pov thawj. Koj yuav tsum mus rau API qhov kawg koj xav txheeb xyuas, thiab txheeb xyuas daim ntawv pov thawj SHA1 ntiv tes. Luam muab tshuaj txhuam nws ua ib txoj hlua hauv koj tus lej thiab hu rau tus neeg siv khoom.verify (ntiv tes, hosturl).

WiFiClientSecure tus neeg siv khoom;

// Txuas rau WiFi WiFi.mode (WIFI_STA); WiFi.begin (ssid, password); thaum (WiFi.status ()! = WL_CONNECTED) {ncua (500); Serial.print ("."); } yog (! client.connect (tus tswv, httpsPort)) {Serial.println ("txuas tsis tau"); rov qab; } yog (client.verify (ntiv tes, tus tswv)) {Serial.println ("daim ntawv pov thawj sib xws"); } lwm {Serial.println ("daim ntawv pov thawj tsis phim"); }

Kauj Ruam 4: Ua POST / GET Thov

NCO NTSOOV

Nov yog cov syntax los ua POST thov:

Txoj hlua PostData = "{"; PostData += "\" text / ": \" kuv cov lus / ""; PostData += "}"; Serial.print (PostData); client.print (String ("POST") + url + "HTTP/1.1 / r / n" + "Host:" + host + "\ r / n" + "Authorization:" + bearer + "\ r / n" + "User-Agent: BuildFailureDetectorESP8266 / r / n" + "cache-control: no-cache / r / n" + "Content-Type: application/json / r / n" + "Content-Length:" + PostData. ntev () + "\ r / n" + "\ r / n" + PostData + "\ n"); Serial.println ("thov xa");

PostData yog cov ntaub ntawv koj xa ua JSON, hauv qhov no:

{

"text": "Kuv cov lus"}

Qhov hloov pauv url yog qhov kawg ntawm qhov url, tus tswv, lub vev xaib url, tus neeg nqa khoom yog API nkag mus token.

TAU

Nov yog pseudo-code rau GET thov:

client.print (String ("GET") + url + "HTTP/1.1 / r / n" + "Host:" + host + "\ r / n" + "Authorization:" + bearer + "\ r / n" + "User-Agent: BuildFailureDetectorESP8266 / r / n" + "Kev sib txuas: khaws-ciaj sia / r / n / r / n"); Serial.println ("thov xa"); thaum (client.connected ()) {Txoj kab = client.readStringUntil ('\ n'); yog (kab == "\ r") {Serial.println ("headers tau txais"); tawg; }} Txoj hlua kab = client.readStringUntil ('\ n');

Qhov tshwm sim ntawm cov lus txib no yuav muab khaws cia rau hauv kab sib txawv.

Kauj Ruam 5: JSON & NOKIA LCD

Txhawm rau ua tiav txoj haujlwm zoo sib xws, koj yuav tsum tso saib cov duab, cov ntawv thiab cov cim rau Nokia 5110 LCD. Koj tuaj yeem saib ntawm No Hauv Qhov Tutorial Tutorial los ntawm lastminuteengineers.

Txhawm rau tswj JSON hauv Arduino C ++, siv ArduinoJson lub vev xaib uas yuav qhia koj txhua yam txog nws!

Tsis txhob ua siab deb tshaj tawm cov lus nug yog tias koj muaj, lossis tshaj tawm qhov koj tau ua nrog qhov chaws no / qhia.

Pom zoo: