基于FPGA的ESP8266无线数据传输(温湿度DTH11、光照强度BH1750、WIFI模块)连接中国移动onenet云平台,仿真+上板通过+可视化平台搭建

一、创建云平台产品设备

在这里插入图片描述
在这里插入图片描述
使用串口助手测试传输过程

在这里插入图片描述

相关信息记录
在这里插入图片描述
在这里插入图片描述

二、FPGA仿真WIFI模块通信过程

仿真分析

在这里插入图片描述

 //各个状态tx_data
    always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        uart_tx_data <= 8'd0;
    end
    else if((state==AT) && tx_count<8'd6 ) begin
        uart_tx_data <= cmd_AT[47 - tx_count *8 -:8];
    end
    else if((state==CWMODE) && tx_count<8'd15 ) begin
        uart_tx_data <= cmd_CWMODE[119 - tx_count *8 -:8];
    end
    else if((state==RST) && tx_count<8'd10 ) begin
        uart_tx_data <= cmd_RST[79 - tx_count *8 -:8];
    end
    else if((state==CWJAP) && tx_count<8'd31 ) begin
        uart_tx_data <= cmd_CWJAP[247 - tx_count *8 -:8];
    end
    else if((state==CWDHCP) && tx_count<8'd17 ) begin
        uart_tx_data <= cmd_CWDHCP[135 - tx_count *8 -:8];
    end
    else if((state==MQTTUSERCFG) && tx_count<8'd172 ) begin
        uart_tx_data <= cmd_MQTTUSERCFG[1375 - tx_count *8 -:8];
    end
    else if((state==MQTTCONN) && tx_count<8'd45 ) begin
        uart_tx_data <= cmd_MQTTCONN[359 - tx_count *8 -:8];
    end
    else if((state==MQTTSUB) && tx_count<8'd67 ) begin
        uart_tx_data <= cmd_MQTTSUB[535 - tx_count *8 -:8];
    end
    else if((state==MQTTPUB) && tx_count<8'd123 ) begin
        uart_tx_data <= cmd_MQTTPUB[983 - tx_count *8 -:8];
    end
    else begin
        uart_tx_data <= uart_tx_data;
    end
end
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        state <= IDLE;
    end
    else begin
    case(state)
        IDLE:begin
               state<=AT;
        end
        AT:begin//at test
            if(tx_count==8'd6)begin
                state <= WAK_AT;
            end
            else begin
                state <= AT;
            end
        end
        WAK_AT:begin
            if(rx_count==8'd2)begin
                state <= CWMODE;
            end
            else begin
                state <= WAK_AT;
            end
        end
        CWMODE:begin//set mode
            if(tx_count==8'd15)begin
                state <= WAK_CWMODE;
            end
            else begin
                state <= CWMODE;
            end
        end
        WAK_CWMODE:begin
            if(rx_count==8'd2)begin
                state <= RST;
            end
            else begin
                state <= WAK_CWMODE;
            end
        end
        RST:begin//at rst
            if(tx_count==8'd10)begin
                state <= WAK_RST;
            end
            else begin
                state <= RST;
            end
        end
        WAK_RST:begin
            if(rx_count==8'd2)begin
                state <= CWJAP;
            end
            else begin
                state <= WAK_RST;
            end
        end
        CWJAP:begin//at rst
            if(tx_count==8'd31)begin
                state <= WAK_CWJAP;
            end
            else begin
                state <= CWJAP;
            end
        end
        WAK_CWJAP:begin//at rst
            if(rx_count==8'd2)begin
                state <= CWDHCP;
            end
            else begin
                state <= WAK_CWJAP;
            end
        end
        CWDHCP:begin//at rst
            if(tx_count==8'd17)begin
                state <= WAK_CWDHCP;
            end
            else begin
                state <= CWDHCP;
            end
        end
        WAK_CWDHCP:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTUSERCFG;
            end
            else begin
                state <= WAK_CWDHCP;
            end
        end
        MQTTUSERCFG:begin//at rst
            if(tx_count==8'd172)begin
                state <= WAK_MQTTUSERCFG;
            end
            else begin
                state <= MQTTUSERCFG;
            end
        end
        WAK_MQTTUSERCFG:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTCONN;
            end
            else begin
                state <= WAK_MQTTUSERCFG;
            end
        end
        MQTTCONN:begin//at rst
            if(tx_count==8'd45)begin
                state <= WAK_MQTTCONN;
            end
            else begin
                state <= MQTTCONN;
            end
        end
        WAK_MQTTCONN:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTSUB;
            end
            else begin
                state <= WAK_MQTTCONN;
            end
        end
        MQTTSUB:begin//at rst
            if(tx_count==8'd67)begin
                state <= WAK_MQTTSUB;
            end
            else begin
                state <= MQTTSUB;
            end
        end
        WAK_MQTTSUB:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTPUB;
            end
            else begin
                state <= WAK_MQTTSUB;
            end
        end
        MQTTPUB:begin//at rst
            if(tx_count==8'd123)begin
                state <= WAK_MQTTPUB;
            end
            else begin
                state <= MQTTPUB;
            end
        end
        WAK_MQTTPUB:begin//at rst
            if(rx_count==8'd2)begin
                state <= IDLE;
            end
            else begin
                state <= WAK_MQTTPUB;
            end
        end
        
        
        default:state <= IDLE;
        endcase
    end
    end

接收数据判断只是简单做了一下,因为是正确回应的话所有的指令最后都是OK。所以可以一直缓存16位数据,当持续时间大于串口接受结束标志之间的间隔后进行判断,如果最后接收到的缓存16位数据是“OK”,则进入下一个状态即可,仿真只是检验一下过程,没做这一块。

按照第一部分设置的AT指令进行发送,主要就是一个状态机,一个是数据缓存发送。

2.上板

在这里插入图片描述
上传了3种数据,分别是温度。湿度。光照强度。实测成功

在这里插入图片描述
在这里插入图片描述

演示视频:

基于fpga的数据上云展示平台,esp8266模块连接fpga开发板和中国移动onenet

总结

踩得坑:正点原子的esp8266模块不用刷固件,mqtt直接用,买其他的esp8266 -01需要刷固件,我还没买底座,比较麻烦,后来索性换了正点原子的wifi模块。其实用其他的效果一样,都是AT指令+MQTT,只不过需要刷固件。

参考:优快云大佬们 ID:紧邻的二氧化碳

虽然但是fpga做这些没什么优势,但是架不住有些毕业设计需要,emmmm当个参考吧。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值