学习笔记-ESP32_Wifi_Camera:SmartConfig编码规则及解码(以及crc踩坑;附python3代码)

购买了一个带有wifi的摄像头, 没有usb, 没有以太网, 没有蓝牙......如何配置这个摄像头接入家中的wifi?

一、代码

1.SmartConfig

from socket import *
import time
import struct
from app.libs.crc8 import Crc8


def creat_content(ssid, password_, ip, bssid):
    password = password_ + '1'
    guide_code = [515, 514, 513, 512]
    password_len = len(password)
    ssid_len = len(ssid)
    total_len = 5 + 4 + password_len + ssid_len
    ssid_crc = get_crc(ssid, 1)
    bssid_list = get_bssid_list(bssid)

    bssid_crc = get_crc(bssid_list, 0)
    datum_data = [total_len, password_len, ssid_crc, bssid_crc]
    ip_address = get_ip_list(ip)
    ap_password = [ord(str) for str in password]
    ap_ssid = [ord(str) for str in ssid]
    data = ip_address + ap_password + ap_ssid
    total_data = datum_data + data
    total_data_xor = 0
    for num in total_data:
        total_data_xor ^= num
    datum_data.append(total_data_xor)
    return guide_code, datum_data, data


def get_crc(list, str):
    crc = Crc8()
    list_num = list
    if str:
        list_str = list
        list_num = [ord(str) for str in list_str]
    [crc.update(num) for num in list_num]
    return crc.value & 0xFF


def get_ip_list(ip):
    return [int(num) for num in ip.split('.')]


def get_bssid_list(bssid):
    return [int(num, 16) for num in bssid.split(':')]


def get_upper_lower(num):
    high_ = num & 0xF0
    high = high_ >> 4
    low = num & 0x0F
    word = [high, low]
    return word[0], word[1]


def get_content(guide_code, datum_data, data):
    messages = []
    content_data = datum_data + data
    length = len(content_data)
    for k in range(20):
        messages.extend(guide_code)
    for j in range(25):
        for k, num in enumerate(content_data):
            crc = get_crc([num, k], 0)
            crc_high, crc_low = get_upper_lower(crc)
            data_high, data_low = get_upper_lower(num)
            message_1 = (crc_high*16 + data_high + 40) & 0x1FF
            message_2 = 296 + k % length
            message_3 = (crc_low*16 + data_low + 40) & 0x1FF
            message = [message_1, message_2, message_3]
            messages.extend(message)
    return messages


def add_contents(num_list):
    all_msg = []
    for num in num_list:
        words = []
        for i in range(num):
            words.append('a')
        one_msg = '&#
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值