Cov txheej txheem:

Yuav Ua Li Cas Nrog JSON hauv Node-RED: 13 Cov Kauj Ruam
Yuav Ua Li Cas Nrog JSON hauv Node-RED: 13 Cov Kauj Ruam

Video: Yuav Ua Li Cas Nrog JSON hauv Node-RED: 13 Cov Kauj Ruam

Video: Yuav Ua Li Cas Nrog JSON hauv Node-RED: 13 Cov Kauj Ruam
Video: La Yang Ft. Phuab Vaj - Yuav Ua Li Cas [Official MV] 2024, Kaum ib hlis
Anonim
Yuav Ua Li Cas Nrog JSON hauv Node-RED
Yuav Ua Li Cas Nrog JSON hauv Node-RED

Cov lus qhia no yuav qhia koj yuav ua li cas nrog JSON hauv node-RED. Kuv yuav qhia koj yuav ua li cas tswj kev sib txuas lub hwj chim nyob nrog kev xa cov ntaub ntawv json ntawm http tau txais thiab tshaj tawm. Thiab koj tuaj yeem siv qhov kev paub no tom qab los tswj hwm cov cuab yeej txhawb nqa JSON raws tu qauv.

Rau kev qhia lub hom phiaj kuv yuav siv NETIO 4 Txhua lub networked lub qhov (socket), tab sis tsis txhob txhawj, koj tsis tas yuav yuav dab tsi. NETIO muaj qhov ua tau zoo 4Txhua yam online demo koj tuaj yeem siv.

Khoom siv

NETIO 4 Txhua lub networked powersocket lossis 4All online demo:

Node-RED

Kauj Ruam 1: REST JSON Http (s) Protocol

REST JSON Http (s) raws tu qauv
REST JSON Http (s) raws tu qauv

Ib feem no yog qhov txuj ci me ntsis tab sis thov nrog kuv. Yog tias kuv tsis tau piav qhia ntu no ces koj yuav muaj teeb meem nkag siab qhov tseem ceeb hauv json cov ntaub ntawv peb yuav xa mus rau ntawm-RED.

Kev nqis tes ua siv rau txhua qhov tso tawm (lub qhov hluav taws xob):

Hauv txhua qhov kev cai M2M, NETIO lub qhov hluav taws xob qhov hluav taws xob siv tib qhov kev coj ua uas tuaj yeem siv rau tus kheej cov txiaj ntsig. Piv txwv li, Toggle lossis Short Off txiav txim tuaj yeem sau rau txhua qhov tso tawm.

Txawm li cas los xij, Kev hloov pauv tuaj yeem tsuas yog siv rau kev sau qhov muaj txiaj ntsig, nws tsis tuaj yeem siv los nyeem lub xeev qhov hluav taws xob tam sim no.

Nov yog cov haujlwm koj tuaj yeem thov rau txhua qhov tso tawm:

0 = Cov zis tso tawm (Tawm)

1 = Cov zis tau qhib rau (On)

2 = Cov zis tawm rau lub sijhawm luv (luv luv)

3 = Cov zis tau qhib rau lub sijhawm luv (luv luv)

4 = Cov zis hloov pauv los ntawm ib lub xeev mus rau lwm qhov (toggle)

5 = Lub xeev tso tawm tsis hloov (tsis hloov)

6 = Tsis quav ntsej

Piv txwv - JSON cov ntaub ntawv to toggle qhov tso tawm no. 1:

{

"Cov txiaj ntsig": [{

"ID": 1, "Kev ua": 4

}]

}

ID - tus lej no qhia tias qhov twg peb yuav siv

Kev nqis tes ua - ntu no, yog qhov kev nqis tes ua uas yuav ua (piv txwv li 1 (Qhib cov zis))

Kauj ruam 2: Txaus

Txaus
Txaus

Thiab tam sim no qhov tseem ceeb. Nov yog yuav ua li cas node-RED ib puag ncig zoo li.

Peb tau ntshuam URL API ntws (Txoj haujlwm koj pom.

  1. NETIO AN30 (JSON REST API) ntws
  2. Dashboard (Graphical interface uas koj tuaj yeem ua haujlwm koj li haujlwm)

Kauj ruam 3: Dashboard

Dashboard
Dashboard

Nov yog li cas dashboard hauv node-RED rau cov lus qhia no zoo li. Koj tuaj yeem hloov kho nws yog tias koj xav kom haum koj tus saj.

Lub dashboard rau txoj haujlwm no tau muab faib ua 4 ntu:

  1. Cov xwm txheej ntawm lub cuab yeej - qhia cov ntaub ntawv ntawm lub cuab yeej xws li tus qauv, mac chaw nyob lossis lub khoos phis tawj version.
  2. (POST) Tswj Cov Zis 1 - Muaj 5 lub nyees khawm uas tswj kev tso tawm 1. Txhua lub khawm ua haujlwm sib txawv
  3. (Tau Txais) O1 - O4 Lub Xeev Tso Tawm - Qhov no qhia txog lub xeev tam sim no ntawm txhua qhov tso tawm los ntawm koj lub cuab yeej.
  4. Kev Tswj Ntaus Ntawv - Hauv ntu no koj tuaj yeem pom txhua hom kab teeb thiab ntsuas ntsuas uas tau qhia qhov ntsuas tam sim no los ntawm NETIO 4Aall ntaus ntawv

Kauj ruam 4: Ntshuam Flow (project, Script, Etc)

Ntshuam Flow (project, Script, Etc)
Ntshuam Flow (project, Script, Etc)

Hauv cov ntawv qhia zaub mov (kaum sab xis saum toj) xaiv Ntshuam thiab tom qab ntawd los ntawm Clipboard.

Tom qab ntawd, theej cov ntawv hauv qab no mus rau qhov chaw qhia thiab nyem Ntshuam.

Txhim kho cov uas ploj lawm

Cov nodes raug thauj mus rau qhov kev xaiv uas tau xaiv. Nws muaj peev xwm hais tias cov lus yuam kev tau tshwm nrog cov npe ntawm cov node uas tau raug xa tawm tab sis tseem tsis tau teeb tsa hauv Node-RED tseem tsis tau. Hauv qhov no, cov pob uas ploj lawm yuav tsum tau teeb tsa.

Yog tias muaj cov nodes ploj lawm, xaiv Manage palette hauv cov ntawv qhia zaub mov, nyem Nruab thiab nrhiav thiab teeb tsa cov node koj ploj lawm.

Ntshuam ntawv:

[{"id": "56b9510c.98c6f", "type": "tab", "label": "NETIO AN30 (REST JSON)", "xiam oob qhab": tsis tseeb, "info": ""}, {"id ":" 6a66b637.da1558 "," type ":" http request "," z ":" 56b9510c.98c6f "," name ":" HTTP Request (POST) "," method ":" POST "," ret ": "txt", "url": "https://netio-4All.netio-products.com:8080/netio.json", "tls": "", "x": 430, "y": 100, "xov hlau":

Kauj Ruam 5: Yuav Ua Li Cas Txhua Qhov Ua Haujlwm Ua Ke

Yuav Ua Li Cas Txhua Tus Ua Haujlwm Ua Ke
Yuav Ua Li Cas Txhua Tus Ua Haujlwm Ua Ke

Cov dej ntws tau muab faib ua ob ntu: POST thiab GET.

POST: Sau rau O1

  • Tsib lub khawm tsim hauv Dashboard hauv Flow tau tshwm rau hauv Dashboard.
  • Tom qab nyem qhov Output 1 = ON khawm hauv Dashboard, qhov kev them nyiaj tau teeb tsa rau hauv netio.json cov ntaub ntawv uas qhia meej txog qhov tso tawm thiab kev nqis tes ua (txhais rau txhua lub khawm).
  • HTTP Thov (POST) thaiv xa cov ntawv netio.json raws li kev thov mus rau IP chaw nyob.
  • Cov lus teb server (xwm txheej) raug xa rov qab raws li qhov tso tawm.
  • Msg.payload thaiv qhia qhov tshwm sim los ntawm HTTP Thov (POST).

Tau Txais: Nyeem los ntawm O1 - O4

  • The 1 Second Repeat block activates, with a period of one second, HTTP Request (GET) block, which in turn sent netio.json as a GET request and return a complete JSON file with the socket status as received from server.
  • JSON Parse block hloov pauv JSON cov ntaub ntawv los ntawm HTTP Thov (GET) thaiv mus rau JSON Object kom nws muaj peev xwm los tswj cov khoom hauv JSON cov ntaub ntawv.
  • Lub luag haujlwm muaj nuj nqis siv tus kheej ib feem ntawm JSON cov khoom thiab hloov pauv lawv mus rau hauv cov khoom ntawm cov khoom msg rau siv tom qab.
  • Daim Ntawv Tam Sim No thaiv teeb tsa msg.payload rau msg. TotalCurrent cov cuab yeej ntawm cov khoom msg, vim tias tom ntej Daim Ntawv Qhia Tam Sim No (Ntaus Ntawv) thaiv tsuas tuaj yeem tso saib qhov msg.payload tus nqi.
  • Ntau cov nodes tso tawm tom qab ntawd ua raws kom pom cov khoom xaiv ntawm cov khoom msg, raws li coj los ntawm JSON cov khoom, hauv Dashboard.

Qhov khoom xav tau thiab msg.payload

Rau kev piav qhia yooj yim thiab luv, saib ntawm no:

www.steves-internet-guide.com/node-red-mess…

Kauj Ruam 6: HTTP POST thiab Tau Txais

HTTP POST thiab Tau Txais
HTTP POST thiab Tau Txais
HTTP POST thiab Tau Txais
HTTP POST thiab Tau Txais

Thov HTTP (POST)

Lub node no xa cov ntawv netio.json ua HTTP Thov (POST) txhawm rau tswj hwm NETIO 4Txhua yam khoom siv.

Thov HTTP (Tau Txais)

Lub node no xa HTTP Thov (GET) thiab xa cov xwm txheej teb.

Cov ntsiab lus ua ntej ua tiav cov ntsiab lus rau NETIO 4 Txhua qhov kev qhia online, uas koj tuaj yeem sim qhov kev sib txuas yam tsis muaj NETIO ntaus ntawv ntawm koj lub rooj.

netio-4all.netio-products.com

Nws muaj peev xwm teeb tsa koj tus kheej tus IP chaw nyob hauv cov node no; Txawm li cas los xij, tus IP yuav tsum tau hloov pauv ob qho tib si HTTP Thov cov nodes, POST ntxiv rau GET.

Kauj Ruam 7: Khawm Nodes

Khawm Nodes
Khawm Nodes
Khawm Nodes
Khawm Nodes

Nyem rau lub pob node tsim cov lus uas muaj cov ntawv netio.json (Daim duab raug) uas yog tom qab ntawd xa ntawm http tshaj tawm ntawm lub node rau netio ntse lub qhov (socket).

Kauj Ruam 8: Muaj nuj nqi

Muaj nuj nqi ntawm
Muaj nuj nqi ntawm
Muaj nuj nqi ntawm
Muaj nuj nqi ntawm

Txoj haujlwm muaj nuj nqi yog qhov tshwj xeeb ntawm qhov uas ua rau sau tau qhov kev cai JavaScript ua haujlwm.

Hauv cov lus qhia no, kev ua haujlwm xaiv qhov muaj txiaj ntsig los ntawm kev cais tawm JSON cov ntaub ntawv (tam sim no yog JSON yam khoom) thiab muab lawv rau cov khoom ntawm yam khoom.

Txoj cai tau muab faib ua plaub ntu:

  1. Muab cov txiaj ntsig los ntawm JSON cov khoom rau cov khoom ntiag tug ntawm cov khoom msg
  2. Kev ua yuam kev thaum lub networked lub qhov (socket) lub zog tsis txhawb nqa kev ntsuas thoob ntiaj teb

    Yog tias lub zog txuas hluav taws xob sib txuas tsis txhawb qhov ntsuas ntawm qhov tseem ceeb hauv ntiaj teb, Node-RED yuav tso tawm qhov yuam kev vim tias txoj haujlwm no yuav tsis pom cov khoom ntiag tug, piv txwv li. msg.payload. GlobalMeasure. Voltage, vim nws yuav tsis muaj nyob hauv JSON yam khoom. Hauv qhov no, cov cuab yeej ntawm cov khoom msg, xws li msg. Voltage, tau teeb tsa 0 thiab qhov yuam kev raug ntes.

  3. Muab lub xeev cov txiaj ntsig tso tawm
  4. Teeb cov xim ntawm qhov tso tawm lub xeev qhov txiaj ntsig raws li lub xeev tso tawm

Kauj Ruam 9: JSON Node thiab Txhaj Tshuaj

JSON Node thiab Txhaj Tshuaj
JSON Node thiab Txhaj Tshuaj
JSON Node thiab Txhaj Tshuaj
JSON Node thiab Txhaj Tshuaj

JSON ntawm

JSON node parses JSON file thiab hloov nws mus rau hauv JSON object.

Raws li cov lus teb los ntawm server rau GET thov, HTTP Thov rau ntawm qhov rov qab JSON cov ntaub ntawv uas muaj qhov xwm txheej tam sim no ntawm NETIO 4x ntaus ntawv, tab sis tsuas yog cov ntawv yooj yim xwb, yog li txhawm rau ua haujlwm nrog cov ntaub ntawv, JSON cov ntaub ntawv xav tau yuav tsum tau parsed rau hauv JSON kwv.

Txhaj tshuaj

Txhua qhov thib ob, qhov ntawm no ua kom HTTP Thov ntawm qhov uas xa GET thov.

Raws li qhov tshwm sim, cov txiaj ntsig hauv Dashboard tau hloov kho nrog lub sijhawm ntawm ib pliag

Kauj ruam 10: Text Node thiab Debug Node

Text Node thiab Debug Node
Text Node thiab Debug Node
Text Node thiab Debug Node
Text Node thiab Debug Node

Text ntawm

Qhia tawm cov ntawv sau hauv Dashboard. Hauv qhov kev qhia no, cov ntawv nyeem pom tam sim no, qhov hluav taws xob, qauv, firmware version lossis JSON version.

Daim ntawv lo tau tshwm rau hauv Dashboard, thiab Lub Npe yog lub npe ntawm lub npe tso tawm kom pom hauv qhov ntws hauv Node-RED.

Debug ntawm

Qhia cov lus.payload.

Kauj Ruam 11: Daim Duab Node

Daim phiaj Node
Daim phiaj Node
Daim phiaj Node
Daim phiaj Node

Lub node no npaj cov phiaj xwm tam sim no hauv Dashboard raws li tus nqi thauj khoom.

Qhov ntawm no tsuas tuaj yeem npaj cov phiaj xwm raws li tus nqi thauj khoom.

Vim li no, txoj haujlwm muaj nuj nqi tau siv los teeb tsa msg.payload rau tus nqi uas xav tau los ua kom pom.

msg.payload = msg. TotalCurrent;

Kauj Ruam 12: Gauge Node thiab Txuas Nodes

Gauge Node thiab Link Nodes
Gauge Node thiab Link Nodes
Gauge Node thiab Link Nodes
Gauge Node thiab Link Nodes

Ntsuas qhov

Lub node no ntxiv cov ntsuas ntsuas rau Dashboard.

Hauv cov lus qhia no, txhua qhov ntsuas pom ib qho khoom ntawm cov khoom siv: voltage [V], kho [A], zaus [Hz] thiab tag nrho Qhov Tseeb Muaj Zog Muaj Tseeb (TPF).

Txuas cov nodes

Txuas hauv thiab txuas tawm cov node ua haujlwm zoo li lub qhov. Msg.payload tuaj txog rau hauv qhov txuas hauv qhov thiab tawm ntawm qhov txuas tawm ntawm qhov.

Kuv siv nws los ua kom cov dej ntws meej dua thiab nyeem tau yooj yim dua.

Kauj Ruam 13: Ua Tsaug Rau Qhov Nyeem Kuv Cov Lus Qhia

Kuv vam tias koj txaus siab rau kuv cov lus qhia thiab vam tias yuav kawm paub yam tshiab.

Cov lus qhia no tsuas yog luv dua ntawm cov lus qhia sib txawv uas kuv tau ua

Phau ntawv qhia thawj yog ntev dua thiab ntau yam qhia ntxaws thiab feem ntau ua tau zoo dua. Yog tias koj tsis nkag siab qee yam lossis xav tias kuv plam lossis tsis piav qhia txaus ib yam, ces koj tuaj yeem pom nws nyob ntawd.

Kuv cog lus tias koj yuav tsis poob siab

Thawj:

Tsis tas li muaj cov lus qhia zoo ib yam txog ntau yam kev siv ofnode-RED, yog li yog koj xav paub xav tshawb fawb ntxiv:

Ua haujlwm nrog REST URL API hauv node-RED

www.netio-products.com/en/application-notes/an29-node-red-example-of-url-api-communication-with-netio-4x

Ua haujlwm nrog REST XML hauv node-RED

www.netio-products.com/en/application-notes/an31-node-red-example-of-rest-xml-communication-with-netio-4x

Ua haujlwm nrog TCP/Modbus hauv node-RED

Yuav los sai sai:)

Pom zoo: