ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
Label: DTU luat --- ## Abstract 1. Introduce an open-source DeviceBit GPRS DTU project 2. Connect one illuminance equipment to DeviceBit by this open-source project for demonstration. For DeviceBit DTU content, please refer to the following link [What is DeviceBit DTU][1] ## Hardware Air200 produced by AirM2M is selected as the open-source module (lua version). There are 3 reasons for selecting it: 1. The air200 module uses the recent popular mode which integrate open script interfaces for secondary development on low-cost hardware (similar to the nodemcu for esp8266). For a simple application, MCU can be directly saved (such as this case of this tutorial). 2. There are many materials for open-source software and hardware and so it is very convenient for learning. The functions of development board functions are very rich (integrated USB debugging, and even can be directly used for solar battery power). 3. The price advantage is too obvious. The price for an air200 in mass productio is less than 15 RMB. With the external power supply, card holder, PCB and so on, the cost for each in mass production will not exceed 20 RMB. The following are two official development boards of AirM2M. On the left is S3, providing only a SIM card holder, which is suitable for direct application products. On the right is S1, providing the power and USB download interfaces, which is more suitable for debugging the code. The two development boards can be purchased directly on TB. ![air2000 两种开发板][2] ![GPRS-DTU-01 正面][3] ![GPRS-DTU-01 反面][4] Related hardware schematic: [GPRS-DTU-01 schematic][5] > Without this bottom board, testing can be carried out. Just buy a S3 module, a ttl-485 module, make a 5V power supply plug by yourself, and connect these things together with DuPont lines. The pin for 5V on S3 can be connectd with Vin, and the pin for Vbat can can be used to supply power to the ttl-485 module (Not recomment this for long-time usage). ## Code [Based on luat DeviceBit GPRS DTU Code][6] The code is modified based on the demo code provided by luat team. Just add the following two functions (by @瘦网虫). 1. Send register packet to DeviceBit modbus server after tcp link is established. 2. Send regieter packet content to module by fixed serial port command. Thanks for the demo code provided by the luat team. ## Download the luat code to hardware Download the luat code to the S3 module, which need to use luaDB download tool, belonging to the luat development. Your can find the answer in the [openluat forum][7], or ask their technical support group for help. Based on the above, a GPRS DTU which can be connected to DeviceBit is done. We will explain the use of this DTU with the following case. ---------- ## To test with a modbus RTU illuminance device See the following picture: ![光照度传感器与DTU][8] ## Web settings on DeviceBit Add a new devie, as the picture shown below. Find your userkey and device ID. ![建立设备,注意06这个网关号][9] For how to find userkey and device ID, please refer to [Using DTU to connect JSY-149 single-phase meter to DeviceBit][10] ## Start the luat hardware & set up userkey_gateNO. Start the hardware and send the following string through UART 1 (Note: It is uart1 is not host UART) setvar:regcode=userkey_gateNO&^! As the following picture shown, It will return save OK if it is correct. ![向DTU 设置usrkey 网关号][11] ## Restart the luat hardware, waiting for the led light on S3 get into the quick flash phase. This means that the network has been successful connected. Don't forget to insert the SIM card in advance, otherwise it will never succeed. Go to the Modbus console an the position shown by the arrow point below. ![modbus 控制台][12] ## Send the test command in the Modbus console Under normal circumstances, you will receive the returned values, indicating that the test is successful. ![modbus 命令测试][13] ## References [DeviceBit DTU Tutorial 1: Overview][14] [Using DTU to connect JSY-149 single-phase meter to DeviceBit][15] [1]: http://www.jianshu.com/p/c1e1097d7e5f [2]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-6.jpg [3]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-9.jpg [4]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-10.jpg [5]: http://leweidoc.oss-cn-hangzhou.aliyuncs.com/doc/GPRS-DTU-01.PDF [6]: https://github.com/lewei50/DTU/tree/master/luat [7]: http://bbs.openluat.com/forum.php [8]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-7.jpg [9]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-1.jpg [10]: https://www.kancloud.cn/xjme/devicebitusermanual/396861 [11]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-2.jpg [12]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-3.jpg [13]: http://doc-resources.lewei50.com/lewei50/img/DTU-lewei50-20170525-5.jpg [14]: https://www.kancloud.cn/xjme/devicebitusermanual/395843 [15]: https://www.kancloud.cn/xjme/devicebitusermanual/396861