MartinFowler

[Training Camp_Advanced Class] Free network configuration + super small and simple cloud socket

 
Overview

Super simple socket design based on GPRS AIR202

1. Introduction

Free network configuration + smallest and most concise

Free network configuration + smallest and most concise

Free network configuration + smallest and most concise

Get started in one minute

It is developed using GPRS module + LUA language, which is super simple.

Mom no longer has to worry that I don’t understand C pronunciation.

There are only a few original parts, and the welding is done in five minutes.

Control the switch action through cloud intelligence and Tmall Genie

At first I thought 2G would have serious delays, but the test was perfect. See attachments

2. Function description

Common MQTT is used to connect to Alibaba Cloud, and the device is kept online through heartbeats.

If the device heartbeat report times out, the APP and Tmall Genie will prompt that the device is not online.

All cloud data processing is done on Alibaba Cloud, and local users are responsible for reporting on/off status.

3. Design features

1. The components are made on two sides to minimize the volume. They can be placed directly inside the electric fan, inside the speaker, or inside the power strip.

2. A KEY is reserved and the touch switch is used, but considering that the board has 220V, all control rights are left to the mobile APP and Tmall Genie.

3. The download interface uses a TOP single-sided pad, and you can directly use the serial port pressure pin to press the download

4. When designing, we considered that the router at home could not configure the WIFI network, so we directly used 2G. Network distribution is still a troublesome thing and affects the user experience.

5. The code is developed using LUA, which has nothing to do with C. Just call the interface and you're done. So the code debugging time is very short

6. Considering that it is placed directly into the electrical appliance, the outer shell is not considered.

7. The PCB area (width 3.5cm and length 4.5cm) is within the 10cm*10cm limit of Jialichuang's proofing, and the board production cost is extremely low.

4. Component selection

1. The main control uses AIR 202, which directly drives the NUD3124LT1G to pull the relay (thank you EDA teacher for recommending the artifact). Because GPIO8 is high impedance during master reset, there is no need to consider adding auxiliary circuits.

2. The download uses the download serial port and the main circuit board to be separated. Otherwise, the size of the circuit board will be increased and it will not be streamlined.

3. The power supply uses HLK-PM01, and the 5V voltage supplied to the relay operates. The main reason is that when the relay operates, it will pull down the voltage and supply power to the main control DCDC, so I added a solid capacitor of 100UF. The relay uses JZC-32F/005-HS3 (555) with a driving voltage of 5V, and the voltage required by the main control is 3.3V-4.2V, so a DCDC, DCDC of SW5033H, is used to take power from the 5V output and supply power to the main control. Two capacitors are connected in parallel to reduce ESR, a 100UF solid state and a 22UF 0603.

4. PCB antenna is not used, mainly because it is more troublesome to do impedance matching, so I directly use an external antenna from IPEX one generation at a time. The signal strength is ideal, CSQ can reach 23. You need to pay attention to the clearance of the antenna, otherwise it will easily roll over.

5. The wiring uses two 2P terminals. I initially wanted to use a single fire to draw power, but I didn’t have the materials on hand, so I gave up.

6. The indicator light is just a 0805 blue LED, which mainly distinguishes the networking status by flashing slowly and quickly. Because I plan to put the finished product into home appliances, I did not make an indicator light. The status of the relay can be checked through the APP or directly ask Tmall Genie

5. Layout and routing design

The placement of 1.202 is relatively random, mainly because the antenna needs to be cleared and the IPEX welding must be ensured to be welded in place (note that it is on both sides, otherwise it will affect the signal, and it will overturn if the Internet cannot be connected)

WeChat screenshot_20200817170955.png WeChat screenshot_20200817171030.png

2. Isolation of strong current and weak current. The physical distance is about 3mm. I was mainly worried about it, so I added a slot in the middle. The slot has a width of 1.5MM

WeChat screenshot_20200817171235.png

3. The copper pouring process is mainly to increase the reflection plane of the antenna, so more via holes are drilled irregularly.

WeChat screenshot_20200817171235.png

6. Design experience and debugging process

I began to consider using the 2G solution, which inherently does not have the low latency of WIFI, which generally requires one to two seconds of delay. At first, I thought it would take a long time to issue control instructions in the APP, but the test turned out to be perfect (the delay time was basically within 1 second, and the user felt no delay when using it). It is considered relatively perfect, and further proves that Alibaba's cloud platform is quite powerful. In the past, when the Alibaba platform launched the APP or asked about the status of the Tmall device, Alibaba's server would come over to ask about the status of the device, and then the device would respond. Now the mode has been changed. After changing to the open command issued by the server, the local device reports an open status after processing the open command. Later, I submitted a work order and asked about it, only to find out that it had been changed.

7. There are only a few original parts in the welding process, and it’s done in just a few welds.

WeChat picture_20200817171947.jpg WeChat picture_20200817171939.jpg

9.jpg



Eight LUA codes (relatively simple, just call the relevant API)

module(...,package.seeall)

require"aLiYun"
require"misc"
require"pm"

local PRODUCT_KEY = "your key"

local function getDeviceName()

    return misc.getImei()

end

local function setDeviceSecret(s)

    misc.setSn(s)
end

local function getDeviceSecret()

    return misc.getSn()

end

local sConnected

local publishCnt = 1

local function publishTestCb(result,para)
    log.info("testALiYun.publishTestCb",result,para)
    sys.timerStart(publishTest,20000)
    publishCnt = publishCnt+1
end

function publishTest()
    if sConnected then
        aLiYun.publish("/"..PRODUCT_KEY.."/"..getDeviceName().."/update","qos1data",1,publishTestCb,"publishTest_"..publishCnt)
    end
end

local function rcvCbFnc(topic,qos,payload)
    log.info("testALiYun.rcvCbFnc",topic,qos,payload)
end

local function connectCbFnc(result)
    log.info("testALiYun.connectCbFnc",result)
    sConnected = result
    if result then

        aLiYun.subscribe({["/"..PRODUCT_KEY.."/"..getDeviceName().."/get"]=0, ["/"..PRODUCT_KEY.."/"..getDeviceName().."/get"]=1})

        aLiYun.on("receive",rcvCbFnc)

        publishTest()
    end
end

local function authCbFnc(result)
    log.info("testALiYun.authCbFnc",result)
end

aLiYun.setup(PRODUCT_KEY,nil,getDeviceName,getDeviceSecret)

aLiYun.on("auth",authCbFnc)
aLiYun.on("connect",connectCbFnc)

require"aLiYunOta"

local function otaCb(result,filePath)
    log.info("testALiYun.otaCb",result,filePath)
    if result then
        local uartID = 1
        sys.taskInit(
            function()
                local fileHandle = io.open(filePath,"rb")
                if not fileHandle then
                    log.error("testALiYun.otaCb open file error")
                    if filePath then os.remove(filePath) end
                    return
                end

                pm.wake("UART_SENT2MCU")
                uart.on(uartID,"sent",function() sys.publish("UART_SENT2MCU_OK") end)
                uart.setup(uartID,115200,8,uart.PAR_NONE,uart.STOP_1,nil,1)
                while true do
                    local data = fileHandle:read(1460)
                    if not data then break end
                    uart.write(uartID,data)
                    sys.waitUntil("UART_SENT2MCU_OK")
                end

                aLiYunOta.setVer("MCU_VERSION_1.0.1")

                uart.close(uartID)
                pm.sleep("UART_SENT2MCU")
                fileHandle:close()
                if filePath then os.remove(filePath) end
            end
        )

    else

        if filePath then os.remove(filePath) end
    end
end
function
  local str = ...
  local off = '{"method":"thing.service.property.set","id":"","params":{"powerstate":0},"version":"1.0.0"}'
  local on = '{"method":"thing.service.property.set","id":"","params":{"powerstate":1},"version":"1.0.0"}'
  res,res1,res2 = json.decode(str)
 if res["params"]["powerstate"] == 0 then
  local led = pins.setup(pio.P0_8,0)
  led(0)
  return off, 1
elseif res["params"]["powerstate"] == 1 then
  local led = pins.setup(pio.P0_8,1)
  led(1)
  return on, 1
  else
  return str,1
  end
 end

Nine physical demonstrations (APP control and Tmall Genie voice control)



参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2024-11-22 23:21:23

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号