Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 602aacd

Browse files
authored
Merge pull request #55 from MajorDomDePIN/main
Adding missing Part in Interact_with_IoT-Device.md
2 parents 2ca8f37 + 4fa21f1 commit 602aacd

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

docs/Tutorials/Interact_with_IoT-Device.md

+154
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,157 @@ Find a temporary email service provider to get the email address for receiving t
6565

6666
Check the device profile (from MEP803) that we will be using. It needs to match the firmware of the X2E board. We will be using an existing ISM2400 profile, with the index set to 3.
6767

68+
69+
```
70+
cast call 0xBFc77Ee5959699eC4171891b625D6EccdC9e00cD "deviceProfileList(uint256) (uint256,string,address,string,bool,uint256)" 3 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368
71+
```
72+
73+
The response will be similar to the following.
74+
75+
```
76+
3
77+
X2E Class C - ISM2400
78+
0xD9892d06C864a41A38915dDd48DF11A0DBfdCf89
79+
https://api.github.com/repos/MatchX-GmbH/iso-device-profile/contents/matchx/x2e_class_c_ism2400.json
80+
true
81+
100000000000000000
82+
```
83+
84+
85+
86+
Check the unit price of a PID from MEP802.
87+
88+
```
89+
cast call 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "pidUnitPrice() (uint256)" --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368
90+
```
91+
92+
The response will be `123450000000000000000` wei, means 123.45 MXC.
93+
94+
95+
96+
Please replace the email address with your own and send the following command to purchase one PID via MEP802.
97+
98+
```
99+
cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "producePid(string,uint256,uint256)" "[email protected]" 1 3 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 --value 123450000000000000000
100+
```
101+
102+
Wait for few minutes after the transaction done, you will receive a email and attached with the PID csv file.
103+
104+
![pid_email](assets/pid_email.png)
105+
106+
Please read the PID `K2ILSDXUOO3O4EEIWZDDW6SL` from the attached file and use it to set up the X2E board. You will also need the pidZkevmHash (5th column) when interacting with Moonchain.
107+
108+
![pid_csv](assets/pid_csv.png)
109+
110+
111+
112+
113+
114+
## Setup the X2E board.
115+
116+
Connect the X2E board to your computer using a USB Type-C cable. Next, launch a serial terminal program like `minicom` on Linux or `PuTTY` on Windows, and establish a connection with the X2E board. Use the serial settings `115200 8N1`.
117+
118+
```
119+
minicom -b 115200 -8 -D /dev/ttyACM0 -o
120+
```
121+
122+
Then send a "AT" command to test the connection. If the connection is correct, the X2E will reply a "OK".
123+
124+
![AT_OK](assets/at_ok.png)
125+
126+
Send the following command at the serial terminal program to change the PID of the X2E board. *Replace the PID to the one got from previous steps.* You will get a OK if success.
127+
128+
```
129+
AT+CQRCODE={"PID":"K2ILSDXUOO3O4EEIWZDDW6SL","B":"MatchX","M":"X2E","V":"1.3"}
130+
```
131+
132+
Clear all data and reboot.
133+
134+
```
135+
AT+IREBOOT=8
136+
```
137+
138+
![x2e_reboot](assets/x2e_reboot.png)
139+
140+
Wait for a while, the X2E board will finish the provisioning process with the new PID. Then it will start to join the network and sending data. After Joined, the status LED will lit steady and the Control pin (IO14) will goes high. If you are using the suggest connection, the target LED will lit.
141+
142+
If this doesn't happen after 6 minutes, please check the status of your NEO miner and make sure it is running.
143+
144+
![x2e_provisioned](assets/x2e_provisioned.png)
145+
146+
After that, your X2E board is connected and able to accept data from the Moonchain.
147+
148+
149+
150+
## Mint the sensor NFT for the X2E board
151+
152+
Check the price for minting a sensor NFT.
153+
154+
```
155+
cast call 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "priceInfoList(uint256) (uint256,uint,bool)" 0 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368
156+
```
157+
158+
The response will similar as below. The first line is the price. 9876500000000000000 equal to 9.8765 MXC.
159+
160+
```
161+
9876500000000000000
162+
0
163+
true
164+
```
165+
166+
167+
168+
Mint the NFT by replacing `0xf6d4bd...` with the pidZkevmHash you received earlier.
169+
170+
```
171+
cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "mintSensorNFT(uint256,uint256,string)" 0xf6d4bda9e25797a1423a41c485bfaa8e03930f0dbdf2d2b324d79fa71d8c9108 0 "https://global.matchx.io/iso/x2e/x2e_ref_sensor.jpeg" --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 --value 9876500000000000000
172+
```
173+
174+
After Sensor NFT minted, you are ready to send data to the X2E board via Moonchain.
175+
176+
177+
178+
To repeat the minting process, you must first burn the Sensor NFT.
179+
180+
```
181+
cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "burnSensorNFT(uint256)" 0xf6d4bda9e25797a1423a41c485bfaa8e03930f0dbdf2d2b324d79fa71d8c9108 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368
182+
```
183+
184+
185+
186+
187+
188+
## Controlling via Moonchain
189+
190+
The controlled pin output has three modes: the first mode sets the output to always low, the second mode sets it to always high, and the third mode toggles the pin, causing the LED to blink.
191+
192+
Please replace `0xf6d4bd...` with the pidZkevmHash you received earlier in the example commands below.
193+
194+
The controlled pin should be changed within 2 minutes after the transaction is completed.
195+
196+
197+
198+
Set controlled to low (Turn off LED):
199+
200+
```
201+
cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "enqueueDownlink(uint256,string,uint8,uint8)" 0xf6d4bda9e25797a1423a41c485bfaa8e03930f0dbdf2d2b324d79fa71d8c9108 "QhMA" 1 0 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368
202+
```
203+
204+
Set controlled to high (Turn on LED):
205+
206+
```
207+
cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "enqueueDownlink(uint256,string,uint8,uint8)" 0xf6d4bda9e25797a1423a41c485bfaa8e03930f0dbdf2d2b324d79fa71d8c9108 "QhMB" 1 0 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368
208+
```
209+
210+
Set controlled to cycling (Blinking the LED):
211+
212+
```
213+
cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "enqueueDownlink(uint256,string,uint8,uint8)" 0xf6d4bda9e25797a1423a41c485bfaa8e03930f0dbdf2d2b324d79fa71d8c9108 "QhMC" 1 0 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368
214+
```
215+
216+
217+
218+
219+
220+
221+

0 commit comments

Comments
 (0)