Cov txheej txheem:

Koj Daim Ntawv Them Nqi Zog Zog: 4 Kauj Ruam
Koj Daim Ntawv Them Nqi Zog Zog: 4 Kauj Ruam

Video: Koj Daim Ntawv Them Nqi Zog Zog: 4 Kauj Ruam

Video: Koj Daim Ntawv Them Nqi Zog Zog: 4 Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Hlis ntuj nqeg
Anonim
Koj Daim Ntawv Them Nqi Zog
Koj Daim Ntawv Them Nqi Zog

HAIS TIAS YUAV UA LI CAS

Yog tias koj xav ua kom koj lub tsev ntse dua, tej zaum koj yuav xav pib los ntawm koj cov nqi txhua hli (piv txwv li lub zog, roj, thiab lwm yam …). Raws li qee tus hais, Zoo rau Ntiaj Teb, Lub Hnab thiab Cov Kab Hauv Qab. Cov cuab yeej qhib tau yog peb txoj hauv kev kom mus txog qhov muaj kev ruaj ntseg hauv ib puag ncig hauv tsev! Lub tswv yim no coj peb los tsim cov kev daws teeb meem yooj yim thiab nyab xeeb, yooj yim rau sib koom ua ke nrog txhua lub tsev siv tshuab software txij li nws nthuav tawm cov ntaub ntawv hla MQTT (hauv peb qhov xwm txheej peb yuav qhia koj yuav ua li cas muab nws tso rau hauv Tsev Pabcuam).

Txheej txheem cej luam

Txhawm rau ntsuas kev siv hluav taws xob, peb tau xaiv siv Finder Energy Meter, txij li nws tau tsim los rau DIN kev siv tsheb nqaj hlau thiab haum zoo kawg nkaus hauv lub txee loj ntawm peb lub tsev. Qhov txias tshaj plaws ntawm cov khoom no yog tias nws muaj RS485 Modbus interface, cov txheej txheem kev lag luam kev sib txuas lus uas ua rau tham nrog Arduino yooj yim heev. Qhov tseeb, Arduino tau tshaj tawm daim ntawv pov thawj raug cai, MKR485 thiab ob lub tsev qiv ntawv los txiav txim siab cov txheej txheem. Raws li lub hauv paus tseem ceeb, peb tau xaiv Arduino MKR WiFi 1010, vim nws koom nrog MKR daim ntawv foos thiab muaj WiFi txuas.

Teeb Teeb Ceeb Toom! Txheeb xyuas koj lub tebchaws cov cai hais txog kev cuam tshuam nrog koj lub tshuab hluav taws xob hauv tsev thiab ceev faj heev vim tias nws tuaj yeem ua rau tuag taus! Yog tias koj tsis paub-yuav ua li cas, hu xov tooj rau hluav taws xob. Thawj kauj ruam yog teeb tsa lub ntsuas hauv koj lub txee hluav taws xob. Txhawm rau kom ntseeg tau tias koj tab tom ua haujlwm nyob hauv ib puag ncig nyab xeeb, tua lub zog los ntawm lub dav hlau hluav taws xob ua ntej ntawm koj lub kaw lus thiab ntsuas ob zaug nrog lub ntsuas cua uas tsis muaj qhov hluav taws xob nruab nrab ntawm lub dav hlau. Tom qab ntawd muab lub ntsuas hluav taws xob tso rau hauv koj lub txee thiab txuas cov xov tooj nyob thiab nruab nrab los ntawm lub tshuab hluav taws xob tseem ceeb mus rau qhov ntsuas ntawm lub ntsuas, nco ntsoov siv lub rooj sib tham xim (xiav rau nruab nrab thiab xim av/dub/txho rau nyob hauv EU). Cov zis yuav tsum txuas nrog rau lwm qhov system.

Kev sib txuas hluav taws xob loj. Cov xov hlau saum toj no yog cov tswv yim, cov xov dhau los yog cov zis.

Kauj Ruam 1: Qhov Yuav Tsum Tau

Qhov Yuav Tsum Tau
Qhov Yuav Tsum Tau

Kauj Ruam 2: Xav Tau Software

Software Xav Tau
Software Xav Tau

Software

Pib koj lub computer thiab qhib koj li IDE. Koj tuaj yeem siv Arduino IDE lossis Arduino Tsim Editor. Txoj cai tau ntsib cov kev thov hauv qab no: Modbus kev sib txuas lus, Kev tswj hwm WiFiMQTT raws tu qauv Modbus yog thiab qhib qhov txheej txheem rau cov khoom lag luam thiab cov tshuab. Txhawm rau Arduino tham Modbus, peb yuav siv Arduino Modbus lub tsev qiv ntawv. Lub tsev qiv ntawv no ntim txhua tus neeg nqa khoom thiab ua rau sib txuas ib qho khoom siv Modbus nrawm heev. Txij li thaum peb tab tom nyeem cov ntawv sau npe, ua raws cov ntaub ntawv ntawm lub ntsuas, peb tuaj yeem pom txhua cov ntaub ntawv peb xav tau xws li cov lej muaj nuj nqi, chaw nyob ntawm tus lej sau npe thiab qhov loj ntawm cov npe hauv cov lus. Tab sis kom ua kom pom tseeb, cia peb piav qhia seb Modbus ua haujlwm li cas: Cov ntawv Modbus ua raws cov qauv yooj yim: 01 03 04 00 16 00 02 25 C7 0x01is Tus Ntaus Chaw Nyob 0x03 yog Txoj Cai Txoj Cai uas qhia rau lub cuab yeej yog tias peb xav nyeem lossis sau cov ntaub ntawv *, hauv qhov no, nyeem tuav cov npe 0x04 rau Byte Count00 16 - Peb xa 4 bytes ntawm chaw nyob sau npe (00 16) uas qhia rau lub cuab yeej dab tsi peb xav nyeem 00 02- tom qab ntawd qhov loj ntawm sau npe (00 02) hauv cov lus (txhua lo lus yog 2 bytes ntev) 4 bytes kawg yog CRC code. Txoj cai no tau tsim los ntawm kev ua lej ua ntej dhau bytes, qhov no ua kom ntseeg tau tias cov lus tau txais raug.

Kev Pabcuam Hauv Tsev Ntxiv Kev ntsuas lub tsev rau Tus Pabcuam Tsev yog qhov yooj yim heev. Piv txwv tias koj muaj MQTT tus broker teeb tsa (Ntawm no yog phau ntawv qhia), txhua yam koj yuav tsum tau ua yog ntxiv cov ntsiab lus tshiab hauv cov ntawv teeb tsa.yaml. sensor: - platform: mqtt name: "Main Voltage" state_topic: "energy/main/voltage" unit_of_measurement: "V" Ntawm no koj yuav tsum tso lub npe ntawm kev ntsuas, MQTT lub ncauj lus los nyeem thiab ntsuas ntsuas ntawm qhov ntau. Txuag cov ntaub ntawv, txheeb xyuas qhov teeb tsa thiab rov ua haujlwm Lub Tsev Pabcuam, tam sim no qhov ntsuas yuav tshwm ntawm nplooj ntawv tseem ceeb.

Vaj Huam Sib Luag Pab Tsev siv qhia pom kev nyeem tam sim no

Tus Pabcuam Hauv Tsev yuav saib xyuas kev tsim cov duab kab thiab siv cov txheej txheem uas tshwm sim los ntawm koj qhov kev nyeem. Cov ntawv qhia no tau ua tiav, tam sim no nws yog rau koj ntxiv cov yam ntxwv thiab kho nws rau koj tus kheej lub hom phiaj!

Kauj ruam 3: Sib sau ua ke

Sib sau ua ke
Sib sau ua ke
Sib sau ua ke
Sib sau ua ke

Ua tiav? Nws yog lub sijhawm los ntsaws rau hauv kev sib txuas RS485! Peb yuav siv cov hlua sib txuas ua ke nrog hauv av, feem ntau yog siv rau kab xov tooj. Nrog cov kab no, koj tuaj yeem xa mus deb deb (1.2 km). Txawm li cas los xij, peb tsuas yog siv kab ntev txaus los tawm ntawm lub txee thiab tso Arduino rau hauv qhov chaw nkag tau yooj yim.

Finder RS485 kev txuas

RS485 interface npe nws cov davhlau ya nyob twg A, B thiab COM. Cov txheej txheem de-facto feem ntau yog siv TX+/RX+ lossis D+ ua lwm txoj hauv kev rau B (siab rau MARK piv txwv li tsis ua haujlwm), TX-/RX- lossis D- ua lwm txoj rau A (qis rau MARK piv txwv li tsis ua haujlwm) Txij li thaum MKR ntaub thaiv npog kuj tseem muaj ob lub Duplex, koj yuav pom ob lwm lub davhlau ya nyob twg, Y thiab Z. Ntawm no peb yuav ntsaws rau lwm qhov kawg ntawm kab ntawv txij li peb paub los ntawm cov ntawv teev tseg uas ib nrab-duplex kev sib txuas lus tsuas yog tshwm sim ntawm Y thiab Z cov dav hlau. Lub davhlau ya nyob twg COM yuav tsum txuas nrog ISOGND. Txij li thaum peb siv qhov kev sib txuas ib nrab-duplex thiab txij li cov cabling yog cov phooj ywg-rau-tus phooj ywg, peb yuav tsum teeb tsa cov hloov pauv ntawm MKR485 daim ntaub thaiv kom phim peb cov teeb tsa: peb teeb tsa HALF (2 rau tua) thiab txiav tawm ntawm YZ (3 rau YOG); thawj tus tsis muaj teeb meem. Qhov kev txiav tawm yog qhov tsis kam txuas ob lub xov tooj cua, rau kev cuam tshuam kev cuam tshuam.

Qhov no yog nws. Tam sim no koj tuaj yeem kaw lub txee thiab tsom mus rau software sab!

Kauj ruam 4: Code

Code
Code

#suav nrog

#include #include #include // koj li ntaub ntawv pov thawj wifi const char ssid = "**********"; const char pass = "**********";

WiFiClient nqa; MQTTClient tus neeg siv khoom; unsigned ntev tus nqi = 60000; // default refresh npaum li cas hauv ms unsigned ntev lastMillis = 0;

// txuas qhov tsis muaj nuj nqi txuas () {Serial.print ("xyuas wifi …"); thaum (WiFi.status ()! = WL_CONNECTED) {Serial.print ("."); ncua (1000); } Serial.print ("\ n txuas …"); thaum (! ncua (1000); } Serial.println ("\ sib txuas!"); client.subscribe ("lub zog/lub ntsiab/rov ua dua tshiab"); // lub ncauj lus los teeb tsa tus nqi tshiab nyob deb} // mqtt tau txais kev hu rov qab tsis muaj dab tsi messageReceived (Txoj hlua & ntsiab lus, Txoj hlua & them nyiaj) {Serial.println ("khoom:" + ncauj lus + " -" + payload); yog (lub ncauj lus == "lub zog/lub ntsiab/rov ua dua tshiab") {// kev hloov kho tus nqi tus nqi = payload.toInt ()*1000; Serial.println ("tus nqi tshiab"+Txoj hlua (tus nqi)); }}

teeb tsa tsis muaj dab tsi () {Serial.begin (115200); WiFi.begin (ssid, dhau); thaum (! Serial); client.begin ("broker_ip", nqa); // CHANGE TO MATCH YOU SETUP client.onMessage (messageReceived); // pib Modbus RTU tus neeg siv yog (! ModbusRTUClient.begin (9600)) {Serial.println ("Ua tsis tiav los pib Modbus RTU Client!"); thaum (1); }}

lub voj void () {client.loop (); yog (! client.connected ()) {// tshawb xyuas lub network txuas txuas (); } // tshaj tawm cov lus tom qab hloov kho tshiab (tsis txwv qhov niaj hnub ua) yog (millis () - lastMillis> tus nqi) {lastMillis = millis (); // ua txhua qhov nyeem tau hu ua ntab volt = readVoltage (); ncua (100); ntab amp = readCurrent (); ncua (100); ob npaug watt = readPower (); ncua (100); ntab hz = readFreq (); ncua (100); ob npaug wh = readEnergy (); // tshaj tawm cov txiaj ntsig hauv cov ncauj lus ntsig txog tus neeg siv khoom.publish ("lub zog/lub ntsiab/qhov hluav taws xob", Txoj hlua (volt, 3)); client.publish ("lub zog/lub ntsiab/tam sim no", Txoj hlua (amp, 3)); client.publish ("lub zog/lub zog/lub zog", Txoj hlua (watt, 3)); client.publish ("lub zog/lub ntsiab/zaus", Txoj hlua (hz, 3)); client.publish ("lub zog/lub zog/lub zog", Txoj hlua (wh, 3)); Serial.print (String (volt, 3)+"V"+String (amp, 3)+"A"+String (watt, 3)+"W"); Serial.println (String (hz, 3)+"Hz"+String (wh, 3)+"kWh"); ncua (100); }}

/ * Cov haujlwm los nyeem Finder Energy Meter sau npe * * Txheeb xyuas modbus cov txheej txheem phau ntawv kom nkag siab cov cai * https://gfinder.findernet.com/public/attachments/7E/EN/PRT_Modbus_7E_64_68_78_86EN.pdf */float readVoltage () {float lwd = 0; yog (! Serial.println (ModbusRTUClient.lastError ()); // tus neeg ua haujlwm yuam kev} lwm {uint16_t word1 = ModbusRTUClient.read (); // nyeem cov ntaub ntawv los ntawm qhov tsis uint16_t word2 = ModbusRTUClient.read (); uint32_t millivolt = word1 << 16 | lus 2; // ntsis lej volt = millivolt/1000.0; } rov qab volt; } float readCurrent () {ntab ampere = 0; yog (! Serial.println (ModbusRTUClient.lastError ()); } lwm {uint16_t lo lus 1 = ModbusRTUClient.read (); uint16_t word2 = ModbusRTUClient.read (); int32_t milliamp = word1 << 16 | lus 2; ampere = milliamp/1000.0; } rov ampere; }

ob npaug readPower () {ob chav watt = 0; yog (! Serial.println (ModbusRTUClient.lastError ()); } lwm {uint16_t lo lus 1 = ModbusRTUClient.read (); uint16_t word2 = ModbusRTUClient.read (); uint16_t lo lus 3 = ModbusRTUClient.read (); uint64_t milliwatt; yog (lo lus 1 >> 7 == 0) {milliwatt = word1

Pom zoo: