C51解析天猫精灵队友的协议用于改装语音控制开关
事情是这样的,某鱼淘了一些一两块钱的天猫精灵队友香薰机主板,
可以用天猫精灵控制,但是只能喷雾用,喷雾呢,又是间歇的,间隔几分钟喷一次。
想用他这个喷雾信号来改装排插开关是不可能了。
于是用电脑抓了一下他的串口协议
发现每次开关都会先发一串FF 00 00 06 82 开头的指令
研究了一下发现是有规律的
当FF 00 00 06 82 02 xx=00的时候是关机, 当xx=01的时候是开机。
知道了这个就好办了,找个51单片机挂在串口这里,解析他的指令就可以 了。
当我收到FF 00 00 06 82 02 01时候,就把排插电源接通。
当我收到FF 00 00 06 82 02 00时候,就把排插电源断开。
这样我就可以通过天猫精灵的自定义场景功能来实现语音开关插座了。
在天猫精灵APP里面自定义场景,
当我对天猫精灵说:打开插座时,打开香薰电源;
当我对天猫精灵说:关闭插座时,关闭香薰电源;
这样就可以制作丐版的智能排查了,当然也可以通过香薰机的预约功能进行预约排查开启时间。
本帖最后由 gw168sh 于 2024-11-5 18:01 编辑
这楼重复了。 代码写的比较水,凑合能用,见笑了
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2014 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
//Nuvoton Technology Corp.
//Date: 23/Jan/2014
//E-Mail: MicroC-8bit@nuvoton.com
//***********************************************************************************************************
//Application : UART Function
//RXD => P1.1 ; TXD => P1.0 (default)
//
//Output : UART receive a byte and transmit the same byte to PC
//***********************************************************************************************************
//------------------------- <<< Use Configuration Wizard in Context Menu >>> --------------------------------
// <h> UART pin Select
// <o0.6> UART pin
// <0=> Select P1.0, P1.1 as UART pin(default)
// <1=> Select P2.6, P2.7 as UART pin(28 pin only)
// </h>
//-------------------------------- <<< end of configuration section >>> -------------------------------------
#define Uart_Port_Sel 0x00
#include <stdio.h>
#include "N79E81x.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include "Version.h"
UINT8 u8Uart_Data;
u8 RxBuf;
u8 TxBuf;
u8 StuNum[] = "201918060210";
bit bRxFlag = 0;
u8 RxLth = 0;
u8 TxLth = 0;
u8 Rxcounter = 0;
u8 Txcounter = 0;
u8 RxStus = 0;
u8 RxFunc = 0;
void Delay_ms(u16 ms)
{
unsigned char i, j;
while(ms--)
{
;;//_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
//-----------------------------------------------------------------------------------------------------------
void main (void)
{
AUXR1 |= Uart_Port_Sel; // Select P10/P11 as UART pin(default)
InitialUART0_Timer1(9600); // 9600 Baud Rate @ 11.0592MHz
TxBuf = 0x4a; //前导 0x4a
TxBuf = 0x43; //前导 0x43
TxBuf = 0x0a; //地址 0x0a 学号:10
TxBuf = 0x01; //功能号1
TxBuf = 0x01; //长度 1
Show_Version_Number_To_PC();
printf ("\n*===================================================================");
printf ("\n*Name: N79E84x Series UART Sample Code.");
printf ("\n*===================================================================");
printf ("\n UART receive a byte and transmit the same byte to PC.\n");
ES = 1; // Enable serial interrupt
EA = 1; // Enable global interrupt
while(1); // Endless
}
//开
//FF 00 00 06 82 02 01 CE 41 00 9A
//关
//FF 00 00 06 82 02 00 CF 41 00 9A
void UART_ISR(void) interrupt 4
{
u8 tmp;
static u8 sum = 0;
if(RI){
RI = 0;
tmp = SBUF;
switch(RxStus){
case 0 : //前导
if(tmp == 0xFF)
RxStus = 1;
break;
case 1 : //前导
if(tmp == 0x0)
RxStus = 2;
break;
case 2 : //地址
if(tmp == 0x0){
RxStus = 3;
sum = tmp;
}
break;
case 3 : //功能号
if(tmp == 0x06){
RxStus = 4;
sum = tmp;
}
break;
case 4 : //长度
if(tmp == 0x82){
RxStus = 5;
sum = tmp;
}
break;
case 5 : //数据
if(tmp == 0x02){
RxStus = 6;
sum = tmp;
}
break;
case 6 : //校验
if(tmp == 0x01) P02=0;
else if(tmp == 0x00)P02=1;
RxStus = 7;
sum = tmp;
break;
default :
RxStus = 0;
Rxcounter = 0;
break;
}
}
if(TI){
TI = 0;
if(Txcounter < TxLth){
SBUF = TxBuf;
}
else{
Txcounter = 0;
TxLth = 0;
}
}
}
厉害了。。。。。
页:
[1]