HaaS600 IoT development board study notes (three)-use the amp tool to remotely update the js code

Abstract: In the previous article, we learned to use the amp tool to push js code to the HaaS600 development board. This article talks about how to remotely push to the device through the amp tool. After implementing this function, if the function of the device is updated, there is no need to go to the site for maintenance.

Experiment purpose: through the amp command line tool, remotely update (OTA) code to the HaaS600 development board

Experimental hardware: HaaS600 development board

Experimental software: win7 x64, amp-win, vscode, serial port assistant.

table of Contents

1. Bind the IoT card to the device

How to buy and activate an IoT card in Alibaba Cloud

2. Bind the IoT card to the device

3. Turn on the OTA function for your device

4. Set the token for your device

5. Use the amp tool to remotely update the js source code


1. Bind the IoT card to the device

The HaaS600 development board needs to be inserted into the gprs network. We can choose a mobile phone card or an Internet of Things card. The two cards have the same appearance. The difference is that the Internet of Things card is very cheap and only provides networking functions (some superimposed SMS functions are also available) ).

The Internet of Things card also needs real-name system and needs to be bound to the device to realize remote update.

For specific operations, please refer to the article:

How to buy and activate an IoT card in Alibaba Cloud

 

2. Bind the IoT card to the device

The IoT card has a unique identification code (ICCID), and the device also has a unique identification code (IMEI).

The full name of ICCID is Integrate circuit card identity, that is, the SIM card number (not the mobile phone number), which is equivalent to the ID card of the mobile phone number. ICCID is the unique identification number of the IC card, which consists of 20 digits in total, and its encoding format is: XXXXXX 0MFSS YYGXX XXXX. The first six operator codes: China Mobile's: 898600; 898602, China Unicom's: 898601, 898609, China Telecom 898603, 898606.

The ICCID of the IoT card I bought is shown below

The full name of IMEI is International Mobile Equipment Identity (International Mobile Equipment Identity). Commonly known as "mobile phone serial number", "mobile phone serial code", "mobile phone serial number", it is used to identify each independent mobile phone in the GSM mobile network, which is equivalent to the ID number of the mobile phone (not the mobile phone card). IMEI codes are applicable to mobile phones of GSM and WCDMA standards and Iridium satellite phones, while CDMA mobile phones use MEID codes, which are different from IMEI codes. Every GSM mobile phone sold through formal channels in the world has a unique IMEI code. The IMEI code is planned by the GSMA Association and authorized by various regional organizations to allocate it. In China, the Telecommunication Terminal Testing Technology Association (TAF) of the Ministry of Industry and Information Technology is responsible for the authentication of domestic mobile phones. Other distribution agencies include British BABT and American CTIA.

The IMEI of the HaaS600 development board that I bought is lasered on the core module EC100Y of the development board.

The binding operation is completed through Taobao on the mobile phone, and there are steps for real-name authentication. The mobile phone interface after binding is shown in the figure below. After binding, the IoT device can work normally.

 

3. Turn on the OTA function for your device

OTA (Over-the-Air Technology) literally means "over-the-air" technology. It is a technology for remotely managing SIM card data and applications through the air interface of mobile communication (GSM or CDMA). The air interface can adopt WAP, GPRS, CDMA1X and short message technology. The application of OTA technology enables mobile communications not only to provide voice and data services, but also to provide new service downloads.

If you want to implement the OTA function, you need Ali to activate this permission.

According to Ali's official help document, you can apply by email.

https://help.aliyun.com/document_detail/184019.html?spm=a2c4g.11186623.6.657.680d21ffWDxRVl

When sending mail, there is a fixed format, the key is the unique identification of the device, that is, the IMEI code. Alibaba Cloud feedback tokens by email.

 

4. Set the token for your device

What is a token?

It literally means a token, which can be understood as a code. The token I understand is a secret code that can be verified locally without being sent to the background.

In computer identity authentication, it means token (temporary), and in lexical analysis it means token. Generally used as an invitation and login system.

Definition of token. (Entry 1 of 2) 1a : a piece resembling a coin issued for use (as for fare on a busby a particular group on specified termsb : a piece resembling a coin issued as money by some person or body other than a de jure governmentc : a unit of a cryptocurrency Bitcoin tokens.

With the officially authorized token, we can access it remotely, but before remote access, we need to set this secret code inside the HaaS600 device.

The specific operations are as follows:

Connect HaaS600 development board and computer.

Open the serial assistant (choose by yourself, many kinds of assistants are fine), set the baud rate to 115200.

First get the current token, enter the following command string, pay attention to sending with "new line"

var kv = require('kv');

Can get the current token

Then use another command to set the token. After the setup is complete, the token will be fixed inside HaaS600. In other words, it has its own "secret code" to talk to the Alibaba Cloud IoT platform.

kv.setStorageSync('_amp_device_token', '9da64dd7e367ab8ec5e0c026xxxxxxxx');

5. Use the amp tool to remotely update the js source code

Assume that the program running inside the HaaS600 development board is to make the USER LED flash once per second. Our new source code will extend the LED to flash once every 2 seconds.

In theory, the serial cable is not needed at this time. Connecting the serial cable to the notebook is not to transmit the code to the device through the data cable, but to observe the HaaS600 information through the data cable.

First modify the source code with vscode,

Modified from 1000 milliseconds to 2000 milliseconds

Then open a new terminal in vscode, cd into the amp command line tool folder amp-win, and then display the networked devices. Found that a login is required.

Then use the command amp login XXXXXX to log in. Note that XXXXXXX is a string of strings, which is the token used to send emails for public beta application feedback, which is the "secret number".

It's equivalent to saying "Hey, hey, hey, hey, hey, hey, hey, hey," and the other person answers "river demon in Pagoda Town", your own person, success!

amp login 374bb6d4ef1f*******************

After logging in successfully, you can display online devices through the command amp device list. Note that the HaaS600 device should always be powered on. In the prompt message, the device number is actually the IMEI serial number on the HaaS600 module.

Next, use the amp tool to remotely update the js source code. Note that the following statement is amp put, not amp serialput app.

Moreover, when updating remotely, there is no need to toggle the mode button of the HaaS600 development board to the DL state.

amp put app 866327**********

 

The serial port information feedback at this time is as shown in the figure below: When the prompt "push app package SUCCESS" is prompted, the HaaS600 device automatically resets, and after about 3 seconds, the new program runs and is done.

 

Conclusion: The HaaS600 development board adopts gprs networking mode, which is very suitable if it is used in occasions without wifi signal coverage. The remote update of the amp command line provided by it is also very convenient and can be used as a project development prototype. After the product is finalized, you can directly purchase the customized EC100Y module and solder it to the bottom plate of your own design. There is no need to consider the issue of programming in the future.

Guess you like

Origin blog.csdn.net/youngwah292/article/details/112426986