当前位置:网站首页>Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda

Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda

2022-07-07 22:06:00 51CTO

One 、 Project introduction

​ The energy crisis is becoming more and more serious , It is imperative to develop new energy . Photovoltaic power generation is a good choice , However, photoelectric conversion efficiency has always been a major problem perplexing the development of the industry . The project passed MPPT Full name “ Maximum power point tracking ”(Maximum Power Point Tracking) Real time detection of the generation voltage of the solar panel , And track the maximum voltage and current value (VI), Make the system output power at maximum power . Use 300W The photovoltaic solar panel is 4 strand 12V Lithium iron phosphate battery for charging . The basic functions have been realized , Equipment code in the project 、 Application side code 、 Schematic diagrams, etc. will be all open source ,PCB The circuit is still under debugging .
#DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_Hi3861
The system is divided into three parts :
Video presentation address : https://ost.51cto.com/show/14366
Application end :

OpenHarmony Application end : Use moisturizing DAYU200 Development board , be based on ArkUI/eTS Development framework , Realize the application end of photovoltaic power generation controller , It can monitor the status of photovoltaic controller equipment in real time . And synchronize the device data to Huawei cloud IotDA, It can realize the state detection and control of Wan equipment .

#DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_Hi3861_02

HarmonyOS Application end : Use HarmonyOS Atomized service capability , Application installation free . Support NFC Touch the distribution network (NAN+SoftAP), The distribution network successfully pulls up the device control page . The equipment control module is the same as OpenHarmony Application end . At the same time, provide service cards , Important device information can be added to the desktop , Easy to view anytime, anywhere .

Device end :

The equipment end is a solar charging and discharging controller , The input terminal is connected to the solar photovoltaic panel , The output terminal is connected to energy storage equipment such as lithium battery . The main control chip adopts Hi3861, The core algorithm adopts MPPT“ Maximum power point tracking ”(Maximum Power Point Tracking), It can significantly improve the power generation efficiency of solar photovoltaic panels . Schematic diagram is as follows :

#DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_DAYU200_03

Cloud :

Cloud access   Hua Wei Yun IotDA, Responsible for equipment data collection , Issue commands to the device .

#DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_DAYU200_04

Two 、 Project directory

project gitee Address : https://gitee.com/liangzili/oh-solar-control

├─1.OpenHarmony_Firmware				//  Device code 
├─2.OpenHarmony_APP				 		// dayu200  Application side code 
├─3.HarmonyOS_APP				 		//  Hongmeng mobile phone   Application side code 
├─4.Schematic_PCB						//  Schematic diagram 
└─HuaweiYunCloud						//  Huawei cloud model file 

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

3、 ... and 、 Device code

Functions realized by the device :

1.NFC One key distribution network

  1. Obtain the input and output current and voltage of the device .

    #DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_Hi3861_05

    #DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_Hi3861_06

    #DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_Hi3861_07

    In the schematic diagram , At the solar input , The lithium battery is terminated with a voltage dividing resistor . Separate access to ADS1115 Of AIN0 and AIN3 Interface .1.OpenHarmony_Firmware\OH_SolarControl\ADS1X15 Migrated under the folder ADS1X15 Arduino End drive code to OpenHarmony. Current detection uses ACS712 modular , Access ADS1115 Of AIN1 and AIN2 Interface ,ADS1115 adopt I2C Module and Hi3861 Communications . The main access codes are as follows :

    #include "ADS1X15.h"
    
    hi_gpio_init();                                                     //GPIO Module initialization 
    
    //  Port multiplexing I2C
    hi_io_set_func(HI_IO_NAME_GPIO_13, HI_IO_FUNC_GPIO_13_I2C0_SDA);
    hi_io_set_func(HI_IO_NAME_GPIO_14, HI_IO_FUNC_GPIO_14_I2C0_SCL);
    
    // ADS1X15 initialization 
    ADS1X15_begin();
    
    //  Collect voltage :
    int SamplingCount = 4;  // Number of samples 
    for(int i = 0; i<SamplingCount; i++){                            //  Average sampling count of voltage sensor  ( recommend : 3)
        //TODO: increase ADS1115 testing 
        operatingData->involtage = operatingData->involtage + ADS1X15_computeVolts(ADS1X15_readADC_SingleEnded(3));   //
        operatingData->outvoltage = operatingData->outvoltage + ADS1X15_computeVolts(ADS1X15_readADC_SingleEnded(1));   //
        operatingData->incurrent = operatingData->incurrent + ADS1X15_computeVolts(ADS1X15_readADC_SingleEnded(2));   // 
        operatingData->outcurrent = operatingData->outcurrent + ADS1X15_computeVolts(ADS1X15_readADC_SingleEnded(0));   // 
    }
    operatingData->involtage  = operatingData->involtage/SamplingCount*40.2857;   // Partial pressure coefficient  
    operatingData->outvoltage  = operatingData->outvoltage/SamplingCount*25;  // Partial pressure coefficient  
    //  Collect current :
    operatingData->incurrent  = operatingData->incurrent/SamplingCount;  //
    operatingData->incurrent  = (operatingData->incurrent-2.45)/0.066; // ACS712 Power supply :4.96V, When there is no current , Voltage is VCC/2. sensitivity 0.066A/V
    operatingData->outcurrent  = operatingData->outcurrent/SamplingCount;  //
    operatingData->outcurrent  = (operatingData->outcurrent-2.45)/0.066; // ( Detect the current v -  Current sensor midpoint 2.525v)*-1 /  Current sensor sensitivity 0.066A/V =  Get the current current input value . Output power ( Battery or charging voltage )
    
           
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
    • 11.
    • 12.
    • 13.
    • 14.
    • 15.
    • 16.
    • 17.
    • 18.
    • 19.
    • 20.
    • 21.
    • 22.
    • 23.
    • 24.
    • 25.
    • 26.
    • 27.
  2. Temperature control

    When the system temperature is too high , Automatically shut down the system . Use NTC100K The temperature sensor , because Hi3861 System resources are relatively limited , Therefore, the temperature value is calculated by using the binary look-up table method , The key codes are as follows :

    /** * @brief AD Value corresponds to temperature value table ( Ascending table ) * NTC Temperature sensor R25=100K, Partial resistance 51K,NTC Reference voltage 3.3V,ADC The resolution of the 12 position ,ADC Reference voltage 4*1.8 *  The calculation method refers to  NTC Calculation table .excel */
    const uint16_t NTC100K[100] = {
        0x220, 0x232, 0x243, 0x255, 0x268, 0x27A, 0x28D, 0x29F, 0x2B2, 0x2C5, // 20~39 ℃
        0x2D8, 0x2EB, 0x2FE, 0x311, 0x324, 0x338, 0x34B, 0x35E, 0x371, 0x384, // 30~39 ℃
        0x397, 0x3AA, 0x3BD, 0x3D0, 0x3E2, 0x3F4, 0x407, 0x419, 0x42B, 0x43C, // 40~49 ℃
        0x44E, 0x45F, 0x470, 0x481, 0x492, 0x4A2, 0x4B2, 0x4C2, 0x4D2, 0x4E1, // 50~59 ℃
        0x4F0, 0x4FF, 0x50E, 0x51C, 0x52A, 0x538, 0x546, 0x553, 0x560, 0x56C, // 60~69 ℃
        0x579, 0x585, 0x591, 0x59D, 0x5A8, 0x5B3, 0x5BE, 0x5C8, 0x5D3, 0x5DD, // 70~79 ℃
        0x5E7, 0x5F0, 0x5FA, 0x603, 0x60C, 0x614, 0x61D, 0x625, 0x62D, 0x635, // 80~89 ℃
        0x63C, 0x644, 0x64B, 0x652, 0x659, 0x65F, 0x666, 0x66C, 0x672, 0x678, // 90~99 ℃
        0x67E, 0x684, 0x689, 0x68E, 0x694, 0x699, 0x69D, 0x6A2, 0x6A7, 0x6AB, // 100~109 ℃
        0x6B0, 0x6B4, 0x6B8, 0x6BC, 0x6C0, 0x6C4, 0x6C8, 0x6CB, 0x6CF, 0x6D2, // 110~119 ℃
    };
    
    
    //  Collect the temperature :  Use Hi3861 Self contained ADC Get thermistor 
    hi_adc_channel_index channel3 = HI_ADC_CHANNEL_3;       // ADC Channel number 
    hi_u16 *data;                                           //  Read data storage address 
    hi_adc_equ_model_sel equ_model = HI_ADC_EQU_MODEL_8;    //  Average algorithm mode : Use 8 Sub average algorithm mode 
    hi_adc_cur_bais cur_bais = HI_ADC_CUR_BAIS_DEFAULT;     //  Analog power control : Use the default recognition mode , Modifiable 1.8V/3.3V
    hi_u16 delay_cnt = 0;                                   //  Count of delay time from configuring sampling to starting sampling , One count is 334ns, Its value should be in 0~0xFF0 Between 
    hi_adc_read(channel3, &data, equ_model, cur_bais, delay_cnt);       //  From a ADC The channel reads a data 
    hi_float voltage = hi_adc_convert_to_voltage(data);                 //  take ADC The read codeword is converted into voltage ,(data * 1.8 * 4 / 4096)
    
    voltage = 3.3*51/voltage-51;                                        //  The actual voltage , Power supply 3.3V, Partial resistance 51KΩ
    // operatingData->temp = 1/((ln(voltage/100)/3950)+1/298.15)-273.15; //  Use the formula to calculate the temperature value , I won't support it ln function 
    operatingData->temp = AdcConvertTemp(NTC100K,100,20,data);      //  Use the dichotomous look-up table method to calculate the temperature value 
    
    if (operatingData->temp > 60 )                                  //  The temperature exceeds 100℃≈6.6f,80℃≈12.38f
    {
        systemState.overTemperture = true;
        systemState.errCount++;
    }else
    {
        systemState.overTemperture = false;
    }
    
           
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
    • 11.
    • 12.
    • 13.
    • 14.
    • 15.
    • 16.
    • 17.
    • 18.
    • 19.
    • 20.
    • 21.
    • 22.
    • 23.
    • 24.
    • 25.
    • 26.
    • 27.
    • 28.
    • 29.
    • 30.
    • 31.
    • 32.
    • 33.
    • 34.
    • 35.
    • 36.
    • 37.
    • 38.
    • 39.
    • 40.
  3. OLED Show

    Display the real-time operation status of the system , The relevant code is contained in 1.OpenHarmony_Firmware\OH_SolarControl\ssd1306 Under the folder

    InitGpio();
    ssd1306_Init();
    ssd1306_Fill(Black);
    ScreenPrint(0, 0,"Hello");
    
    void ScreenPrint(int x,int y,char* message){
        ssd1306_SetCursor(x, y);
        ssd1306_DrawString(message, Font_7x10, White);
        ssd1306_UpdateScreen();
    }
    
           
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
  4. mqtt Access to Huawei cloud

Four 、OpenHarmony Application side code

  1. Interface implementation

    Page using ets Compiling , The main codes are as follows :

          DeviceInfo()                        //  Equipment information 
          Devicestate(this.DeviceStateData)   //  Equipment status 
    
          //  Current and voltage 
          Flex({ justifyContent: FlexAlign.SpaceBetween,alignItems:ItemAlign.Center }){
            Column() {
              Text(this.InVoltage+' V').fontSize(30)
              Text(' Input voltage ').fontSize(30)
            }
            .width('33%')
    
            Column() {
              Text(this.OutVoltage+' V').fontSize(30)
              Text(' Output voltage ').fontSize(30)
            }
            .width('34%')
    
            Column() {
              Text(this.InCurrent+' A').fontSize(30)
              Text(' Input current ').fontSize(30)
            }
            .width('33%')
    
          }.align(Alignment.Center).borderRadius(15).backgroundColor(0xE5E5E5).width('90%').height(180).margin({top:10})
    
           
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
    • 11.
    • 12.
    • 13.
    • 14.
    • 15.
    • 16.
    • 17.
    • 18.
    • 19.
    • 20.
    • 21.
    • 22.
    • 23.
    • 24.
  2. Http visit

    Connecting Huawei cloud IotDA Need to use get、post Request cloud data , Send request configuration code :

    export class HttpRequestOptions {
        method: string
        extraData: Object
        header: Object
        readTimeout: number
        connectTimeout: number
    
        constructor() {
            this.method = 'POST'
            this.header = {
                'Content-Type': 'application/json'
            }
            this.readTimeout = 5000
            this.connectTimeout = 5000
        }
    
        setMethod(method: string) {
            this.method = method
            Logger.info(TAG, `setMethod method is ${this.method}`)
        }
    
        setExtraData(extraData: Object) {
            this.extraData = extraData
            Logger.info(TAG, `setExtraData extraData is ${JSON.stringify(this.extraData)}`)
        }
    
        setHeader(header: Object) {
            this.header = header
            Logger.info(TAG, `setHeader header is ${JSON.stringify(this.header)}`)
        }
    }
    
    /***********************  Network data request  *********************************/
    async request(uri: string, op: Object) {
        let httpRequest = http.createHttp()
        Logger.info(TAG, `createHttp uri = ${uri}`)
        try {
            let result = await httpRequest.request(uri, op)
            Logger.info(TAG, `HttpResponse's result is ${JSON.stringify(result.result)}`)
            Logger.info(TAG, `responseCode is ${result.responseCode} header is ${JSON.stringify(result.header)} cookies is ${JSON.stringify(result.cookies)}}`)
            return result
        } catch (err) {
            Logger.info(TAG, `This err is ${JSON.stringify(err)}`)
            httpRequest.destroy()
            return err
        }
    }
    
           
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
    • 11.
    • 12.
    • 13.
    • 14.
    • 15.
    • 16.
    • 17.
    • 18.
    • 19.
    • 20.
    • 21.
    • 22.
    • 23.
    • 24.
    • 25.
    • 26.
    • 27.
    • 28.
    • 29.
    • 30.
    • 31.
    • 32.
    • 33.
    • 34.
    • 35.
    • 36.
    • 37.
    • 38.
    • 39.
    • 40.
    • 41.
    • 42.
    • 43.
    • 44.
    • 45.
    • 46.
    • 47.
    • 48.
  3. Hua Wei Yun API Interface

    obtain IAM user Token Interface , This interface can be used through user name and password ma To obtain IAM user Token.

        async getIAMUserToken(){
            let PostHeader = {
                'Content-Type': 'application/json'
            }
            let PostBody = {
                "auth": {
                    "identity": {
                        "methods": [
                            "password"
                        ],
                        "password": {
                            "user": {
                                "name": this.IAMUserName,
                                "password": this.IAMPassword,
                                "domain": {
                                    "name": this.IAMDoaminId
                                }
                            }
                        }
                    },
                    "scope": {
                        "project": {
                            "name": this.region
                        }
                    }
                }
            }
            let requestData = await this.request('https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens', { // Initiate a network data request ,url/ Request header 
                method: 'POST',
                extraData: PostBody,  //  Request body 
                header: PostHeader,
                readTimeout: 5000,
                connectTimeout: 5000,
            })
            Logger.info(TAG, `getIAMUserToken header is ${JSON.stringify(requestData.header)}`)// Response head .Object type 
            Logger.info(TAG, `getIAMUserToken result is ${JSON.stringify(requestData.result)}`)// The corresponding body .string type 
            return requestData.header['X-Subject-Token']
    
           
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
    • 11.
    • 12.
    • 13.
    • 14.
    • 15.
    • 16.
    • 17.
    • 18.
    • 19.
    • 20.
    • 21.
    • 22.
    • 23.
    • 24.
    • 25.
    • 26.
    • 27.
    • 28.
    • 29.
    • 30.
    • 31.
    • 32.
    • 33.
    • 34.
    • 35.
    • 36.
    • 37.

    Query device shadow data interface , Query the device shadow information of the specified device by calling this interface , The relevant code is as follows

        async showDeviceShadow(){
            let PostHeader = {
                'Content-Type': 'application/json',
                'X-Auth-Token': this.X_Auth_Token
            }
            let PostBody = {}
            let requestData = await this.request('https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/'+this.project_id+'/devices/'+this.device_id+'/shadow', { // Initiate a network data request ,url/ Request header 
                method: 'GET',
                extraData: PostBody,  //  Request body 
                header: PostHeader,
                readTimeout: 5000,
                connectTimeout: 5000,
            })
            Logger.info(TAG, `showDeviceShadow header is ${JSON.stringify(requestData.header)}`)// Response head .Object type 
            Logger.info(TAG, `showDeviceShadow result is ${JSON.stringify(requestData.result)}`)// The corresponding body .string type 
            return JSON.parse(requestData.result).shadow[0].reported.properties
        }
    
           
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
    • 11.
    • 12.
    • 13.
    • 14.
    • 15.
    • 16.
    • 17.

5、 ... and 、HarmonyOS Application side code

HarmonyOS The application side can be used directly DevEco Studio Self contained OneHop Templates , Need to install  DevEco Studio 3.0.0.800 Beta2 for HarmonyOS

#DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_DAYU200_08

I have written this part in my previous article , I won't go into that here , Original link   Touch to achieve - Open source basic software community -51CTO.COM

The application side code is divided into two modules ,entry and control,entry The module is responsible for the equipment distribution network ,control The module is responsible for equipment data acquisition and equipment control .

entry Distribution network module

By default, the distribution network in the template uses NAN Distribution network mode , The success rate of distribution network is relatively poor , Can increase SoftAP Distribution network mode , Two modes of distribution network , Increase the success rate of equipment distribution . The first change getWifiInfo() function .

    getWifiInfo() {
        getApp(this).NetConfig.getWifiList((result) => {						//  obtain wifi list 
            if (result.code == 0 && result.data && result.data.length > 0) {	//  If the list is obtained successfully 
                this.wifiApInfo = result.data[0]
                for (let i = 0;i < result.data.length; i++) {
                    if (result.data[i].hasDefaultPassword) {
                        this.wifiApInfo = result.data[i];
                        break;
                    }
                }
                if (Object.keys(this.wifiApInfo).length == 0) {
                    this.desc = " There is no connected wifi"
                    return;
                }
                if (this.isNAN) {
                    this.discoverDeviceByNAN()
                } else {
                    this.startSoftAp()
                }
            } else {															//  Otherwise, failed to get the list 
                this.isFail = true
            }
        });
    },

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

discoverDevice() The function is decomposed into NAN、SoftAP Two ways

/************************ NAN Distribution network  *********************************/
discoverDeviceByNAN() {
        this.desc = " Start discovering devices "
        let scanInfo = {
            duration: 5,
            lockTime: 60,
            sessionId: getApp(this).ConfigParams.sessionId
        };
        // Step1 discover the device through the NaN broadcast service.
        getApp(this).NetConfig.discoveryByNAN(scanInfo, (result) => {
            if (result.code == 0) {
                this.desc = "NAN Device discovery succeeded "
                getApp(this).ConfigParams.deviceInfo = result.data;
                this.registerDisconnectCallback(getApp(this).ConfigParams.deviceInfo.sessionId);
                let connectInfo = {
                    targetDeviceId: getApp(this).ConfigParams.deviceInfo.productId,
                    type: 0,
                    pin: '11111111',
                    password: getApp(this).ConfigParams.deviceInfo.sn,
                    sessionId: getApp(this).ConfigParams.deviceInfo.sessionId
                };
                console.info("netconfig connectInfo" + JSON.stringify(connectInfo))
                this.connectDevice(connectInfo);
            } else {
                this.desc = "NAN Device discovery failed "
                this.startSoftAp()
            }
        });
    },
/************************ SoftAP Distribution network  *********************************/
    startSoftAp() {
        this.isNAN = false
        this.desc = "softAP Distribution network "
        this.disconnectDevice()
        getApp(this).ConfigParams.deviceInfo.sessionId = ''
        this.discoverDeviceBySoftAp()
    },
    discoverDeviceBySoftAp() {
        if (!this.targetDeviceId) {
            this.desc = "apName It's empty : " + this.targetDeviceId  //TODO
            return;
        }
        getApp(this).NetConfig.discoveryBySoftAp((result) => {
            console.info("NetConfig# discoveryBySoftAp" + JSON.stringify(result))
            if (result.code == 0) {
                this.desc = "softAP Find success "
                getApp(this).ConfigParams.deviceInfo = result.data;
                getApp(this).ConfigParams.deviceInfo.sessionId = ''
                let connectInfo = {
                    targetDeviceId: "teamX-Lamp01",
                    // targetDeviceId: this.targetDeviceId, //  equipment ap Hotspot name , from NFC in tag=5 Get the value of 
                    type: 1,
                    pin: '11111111',
                    password: '',
                    sessionId: ''
                };
                this.connectDevice(connectInfo);
            } else {
                this.isFail = true
            }
        })
    },

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.

There are also two ways to connect devices :

    connectDevice(connectInfo) {
        if (this.isNAN) {
            this.desc = " In connection device (NAN)"
        } else {
            this.desc = " In connection device (SoftAp)"
        }
        console.info("Netconfig connectDevice argument" + JSON.stringify(connectInfo))
        // Step2 connect the device.
        getApp(this).NetConfig.connectDevice(connectInfo, (result) => {
            if (result.code === 0) {
                this.desc = " Device connected successfully "
                this.configDevice();
            } else {
                console.error("netconfig connectDevice fail" + JSON.stringify(result))
                if (this.isNAN) {
                    this.desc = " Failed to connect device (NAN)"
                    this.startSoftAp()
                } else {
                    this.desc = " Failed to connect device (softAp)"
                    this.isFail = true
                    this.disconnectDevice();
                }
            }
        });
    },

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

The distribution network function needs to be modified in the same way , Other distribution modes are basically unchanged .

    async configDevice() {
        this.desc = " Start the distribution network "
        let netConfigInfo = {
            ssid: this.wifiApInfo.ssid,
            ssidPassword: '',
            isDefaultPassword: true,
            channel: this.wifiApInfo.channel,
            sessionId: getApp(this).ConfigParams.deviceInfo.sessionId,
            type: this.isNAN ? 0 : 1,
            wifiApId: this.wifiApInfo.wifiApId,
            vendorData: '',
            timeout: 30,
            paramValid: true
        };
        console.info("netconfig configDevice" + JSON.stringify(netConfigInfo))
        // Step4 config the device net.
        getApp(this).NetConfig.configDeviceNet('deviceInfo', 'accountInfo', netConfigInfo, (result) => {
            if (result.code == 0) {
                this.desc = " Distribution network success "
                // Step5 config the device net success, go to the control.
                this.goToControl();
            } else if (this.isNAN) {
                this.startSoftAp()
            } else {
                this.desc = " Distribution network failure "
                this.isFail = true
                this.disconnectDevice();
            }
        });
    },

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.

Distribution network in two ways , The success rate of distribution network will increase a lot , This method refers to  OpenHarmony-SIG/knowledge Examples of smart home development . This warehouse provides many OpenHarmony Examples of IOT devices , Interested partners , You can study it carefully .

control Control module

New equipment is defined in 3.HarmonyOS_APP/SolarControl/entry/src/main/java/com/zml/solarcontrol/MainAbility.java. When entry When the module is successfully distributed , Will pull up control Module interface and will productName Pass the parameters together .

public class MainAbility extends AceAbility {
    private static final String DEFAULT_MODULE = "default";
    private static final String LOGIN_MODULE = "login";
    private static final String JS_MODULE = DEFAULT_MODULE;
    private static String productId;
    private String productName = "SOLAR";		//  Specify the device name 

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

Add a new device under the control module SOLAR, Resources are contained in 3.HarmonyOS_APP/SolarControl/control/src/main/js/default/common/SOLAR Under the folder , The configuration file is contained in 3.HarmonyOS_APP/SolarControl/control/src/main/resources/rawfile/SOLAR Under the folder .

#DAYU200 Experience Officer #MPPT Photovoltaic power generation project DAYU200、Hi3861、 Hua Wei Yun IotDA_OpenHarmony_09

The configuration process is as follows :

1. Product profile 
src/main/resources/rawfile/XXXX/XXXX_zh.json

2.UX Resource map 
src/main/js/default/common/XXXX/XXXX.png

3. If you use web pictures 
src/main/java/com/liangzili/myonehop/DataHandlerAbility.java
// Assign the network prefix to iconUrl that will do 
result.put("iconUrl", SampleDeviceDataHandler.EXAMPLE_RESOURCE_DIR + "/" + productName);

4. Modify network device mode 
src/main/java/com/liangzili/myonehop/DataHandlerAbility.java
private static final int DEVICE_DATA_MODE = DEVICE_DATA_MODE_NETWORK_DEVICE;

5. add to XXXX Data processing logic of the device 
 Reference resources NetworkDeviceDataHandler.java Medium fanDataModel, The data processing logic of an intelligent electric fan has been implemented in the template 

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

At present, the basic framework of the project has been realized , Some functions are still being improved , We will continue to update the document in the near future .

  Want to know more about open source , Please visit :

 51CTO Open source basic software community

 https://ost.51cto.com/#bkwz

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072135076596.html