|
| 1 | +--- |
| 2 | +sidebar_position: 10 |
| 3 | +--- |
| 4 | + |
| 5 | +import DFU_1 from '/img/X2E/DFU_1.png'; |
| 6 | +import DFU_2 from '/img/X2E/DFU_2.png'; |
| 7 | +import DFU_3 from '/img/X2E/DFU_3.png'; |
| 8 | +import DFU_4 from '/img/X2E/DFU_4.png'; |
| 9 | +import at_ok from '/img/X2E/at_ok.png'; |
| 10 | +import pid_csv from '/img/X2E/pid_csv.png'; |
| 11 | +import pid_email from '/img/X2E/pid_email.png'; |
| 12 | +import temp_email from '/img/X2E/temp_email.png'; |
| 13 | +import x2e_connections from '/img/X2E/x2e_connections.png'; |
| 14 | +import x2e_provisioned from '/img/X2E/x2e_provisioned.png'; |
| 15 | +import x2e_reboot from '/img/X2E/x2e_reboot.png'; |
| 16 | + |
| 17 | +# Controlling a Physical Device via Moonchain |
| 18 | + |
| 19 | +This demonstration illustrates how to control a physical device using Moonchain, specifically through remotely toggling an LED on or off. It emphasizes the seamless integration of blockchain technology with real-world hardware, showcasing the potential for secure, decentralized control in various applications. |
| 20 | + |
| 21 | +### English |
| 22 | +<iframe |
| 23 | + width="800" height="450" src="https://www.youtube.com/embed/30CATOQeYKc" |
| 24 | + title="YouTube video player" frameborder="0" |
| 25 | + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" |
| 26 | + allowFullScreen> |
| 27 | +</iframe> |
| 28 | + |
| 29 | +### German |
| 30 | +<iframe |
| 31 | + width="800" height="450" src="https://www.youtube.com/embed/1uU0s5Zzf3I" |
| 32 | + title="YouTube video player" frameborder="0" |
| 33 | + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" |
| 34 | + allowFullScreen> |
| 35 | +</iframe> |
| 36 | + |
| 37 | +## Moonchain Info |
| 38 | +- Contract Proposals: [MEPs Repository](https://github.com/MXCzkEVM/MEPs) |
| 39 | +- Deployed Contrace Addresses: |
| 40 | + - MEP801: <code>0x070B3e2229a27CDd34126E96B2Ce65c63BD1A5CE</code> |
| 41 | + - MEP802: <code>0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6</code> |
| 42 | + - MEP803: <code>0xBFc77Ee5959699eC4171891b625D6EccdC9e00cD</code> |
| 43 | + |
| 44 | +:::info[NOTE] |
| 45 | +Commands in this document use the wallet address `0xa2d9E584F4cF0167d283dB6EB4922082269B6bB7` as an example. MXC tokens are required for gas fees and other transaction costs. |
| 46 | +::: |
| 47 | +- Private Key: <code>318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368</code> |
| 48 | + |
| 49 | +``` |
| 50 | +318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 |
| 51 | +``` |
| 52 | + |
| 53 | +### Change the X2E Firmware |
| 54 | +- Firmware Repository: [Moonchain-Control-X2E](https://github.com/MXCzkEVM/Moonchain-Control-X2E) |
| 55 | +- Download the Mobile App Tool (Nordic DFU): |
| 56 | + - [Google Play Store](https://play.google.com/store/apps/details?id=no.nordicsemi.android.dfu&hl=en&gl=US) |
| 57 | + - [Apple App Store](https://apps.apple.com/tt/app/nrf-device-firmware-update/id1624454660)(requires iOS 16 or higher) |
| 58 | +- Update Firmware: |
| 59 | + - Copy `demo_controls_dfu_ism2400.zip` to your mobile phone (Place it in the download folder for recognition). |
| 60 | + <img src={DFU_1} style={{width: 600}}/> |
| 61 | + - Open the DFU App, select the firmware binary file, and start scanning for BLE devices. |
| 62 | + <img src={DFU_2} style={{width: 600}}/> |
| 63 | + - Hold the X2E board's "USER" button for 5 seconds to initiate DFU mode. |
| 64 | + <img src={DFU_3} style={{width: 600}}/> |
| 65 | + - Select the X2E board on the app, tap "Start" to upgrade the firmware, and wait for completion. |
| 66 | + <img src={DFU_4} style={{width: 600}}/> |
| 67 | + |
| 68 | +### Connection of X2E |
| 69 | +To control an LED, follow these connection guidelines: |
| 70 | +<img src={x2e_connections} style={{width: 600}}/> |
| 71 | + |
| 72 | +### Purchase a Provision ID (PID) |
| 73 | +- Obtain a temporary email address to receive the PID. This prevents exposing your personal email on Moonchain. |
| 74 | +<img src={temp_email} style={{width: 600}}/> |
| 75 | +- Check Device Profile |
| 76 | + - Ensure it matches the firmware of your X2E board. Use the ISM2400 profile with index 3. |
| 77 | + ```bash |
| 78 | + cast call 0xBFc77Ee5959699eC4171891b625D6EccdC9e00cD "deviceProfileList(uint256) (uint256,string,address,string,bool,uint256)" 3 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 |
| 79 | + ``` |
| 80 | + - Response will be similar to one below |
| 81 | + ```bash |
| 82 | + 3 |
| 83 | + X2E Class C - ISM2400 |
| 84 | + 0xD9892d06C864a41A38915dDd48DF11A0DBfdCf89 |
| 85 | + https://api.github.com/repos/MatchX-GmbH/iso-device-profile/contents/matchx/x2e_class_c_ism2400.json |
| 86 | + true |
| 87 | + 100000000000000000` |
| 88 | + ``` |
| 89 | +
|
| 90 | +- Check PID Unit Price |
| 91 | +```bash |
| 92 | +cast call 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "pidUnitPrice() (uint256)" --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 |
| 93 | +``` |
| 94 | + - Response: `123450000000000000000 wei` (123.45 MXC). |
| 95 | +- Purchase PID |
| 96 | + - Replace the email with your own and use the following command to purchase a PID via MEP802. |
| 97 | + ```bash |
| 98 | + cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "producePid(string,uint256,uint256)" "[email protected]" 1 3 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 --value 123450000000000000000 |
| 99 | + ``` |
| 100 | + - After a few minutes, you will receive an email with a PID CSV file. |
| 101 | + <img src={pid_email} style={{width: 600}}/> |
| 102 | +- Extract PID and pidZkevmHash |
| 103 | + - Use the PID and pidZkevmHash from the CSV file to set up the X2E board. |
| 104 | + <img src={pid_csv} style={{width: 600}}/> |
| 105 | + |
| 106 | +### Setup the X2E Board |
| 107 | + |
| 108 | +- Connect the X2E board to your computer using a USB Type-C cable. |
| 109 | +- Launch a serial terminal program (e.g., minicom on Linux or PuTTY on Windows) with settings `115200 8N1`. |
| 110 | + - Use the following command: |
| 111 | + ```bash |
| 112 | + minicom -b 115200 -8 -D /dev/ttyACM0 -o |
| 113 | + ``` |
| 114 | +- Send "AT" command to verify connection. You should receive "OK". |
| 115 | + - Run the `AT` command |
| 116 | + <img src={at_ok} style={{width: 600}}/> |
| 117 | +- Change the PID of the X2E board: |
| 118 | + - Use the following command: |
| 119 | + ```bash |
| 120 | + AT+CQRCODE={"PID":"K2ILSDXUOO3O4EEIWZDDW6SL","B":"MatchX","M":"X2E","V":"1.3"} |
| 121 | + ``` |
| 122 | +- Clear all data and reboot |
| 123 | + - Run the command below: |
| 124 | + ```bash |
| 125 | + AT+IREBOOT=8 |
| 126 | + ``` |
| 127 | + <img src={x2e_reboot} style={{width: 600}}/> |
| 128 | + |
| 129 | +Wait for a while, the X2E board will finish the provisioning process with the new PID. After that, it will start to join the network and send data. After it joined, the status LED will lite steady and the Control pin (IO14) will go higher. If you are using the suggested connection, the target LED will be lit. |
| 130 | + |
| 131 | +If this doesn't happen after 6 minutes, please check the status of your NEO miner and make sure it is running. |
| 132 | +<img src={x2e_provisioned} style={{width: 600}}/> |
| 133 | + |
| 134 | +### Mint the Sensor NFT for the X2E Board |
| 135 | +- Check Minting Price |
| 136 | + ```bash |
| 137 | + cast call 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "priceInfoList(uint256) (uint256,uint,bool)" 0 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 |
| 138 | + ``` |
| 139 | + - Response `9876500000000000000 wei` (9.8765 MXC). |
| 140 | +- Mint the NFT |
| 141 | + - Replace `0xf6d4bd...` with the pidZkevmHash and use the following command: |
| 142 | + ```bash |
| 143 | + 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 |
| 144 | + ``` |
| 145 | +- Burn Sensor NFT to Repeat Process |
| 146 | +```bash |
| 147 | +cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "burnSensorNFT(uint256)" 0xf6d4bda9e25797a1423a41c485bfaa8e03930f0dbdf2d2b324d79fa71d8c9108 --rpc-url https://geneva-rpc.moonchain.com --private-key 318dee0c207c20f4767e342a52e876b816379334a53277773c783b0e9348d368 |
| 148 | +``` |
| 149 | +### Controlling via Moonchain |
| 150 | +You can control the pin output in three modes: always low, always high, or cycling (blinking). Replace `0xf6d4bd...` with the pidZkevmHash from earlier commands. |
| 151 | +- Set to Low (Turn off LED) |
| 152 | + ```bash |
| 153 | + cast send 0x28479D68cD3ef5661BDB7505EFD1712D5D0951F6 "enqueueDownlink(uint256,string,uint8,uint8)" 0xf6d4bda9e25797a1423a41c485bfaa8e03930f0dbdf2d2b324d79fa71d8c9108 "Qh |
| 154 | + ``` |
0 commit comments