arduino uno 连接 tp-link wr703n 实例

本文介绍如何利用Arduino Uno与TP-Link WR703N路由器结合实现机房温度监测并上传至公网服务器的过程。首先需对WR703N进行OpenWRT固件刷写,并配置网络参数;接着通过USB连接Arduino与路由器,安装必要的串口识别库,最终实现实时数据传输。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

arduino uno 连接 tp-link wr703n  实例,arduino 连接wr703n  实例

最近应公司需求,需要做个小东西来实时反馈服务器机房温度,会上一提到这个事情脑袋里马上想起了我搁置很久的老家伙 ardino uno 板子。计划通过它加速个路由器搞得这个需求。

步骤 : (1):  arduino + 传感器  进行机房温度数据采集。

             (2):把采集的数据通usb 传给 wr703n

             (3): wr703n  把数据传给 公网服务器

             (4):android 应用访问公网服务器 通过走势图形式展示一天24小时机房温度变化。

 

第一步:改造TP-link WR703N

              (1): 下载 open wrt 固件 使用此固件升级wr703n

                            (a):  下载地址: http://downloads.openwrt.org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin

                            (b):  路由器加电,通过pc 访问路由器。默认是 :http://192.168.1.1  密码默认 是 admin

                                登陆成功后找到:

然后点击升级,这时候有提示。点击确定 进行升级。升级完成后浏览器处于无法访问的状态。

(c):  此时应用 putty 或者其他linux管理工具进行访问。

这里pc设置成1 段的网络,通过网络连接 路由器。

 

  i如下图:

 

登陆成功后如图:

(2): 进行 网络设置

      (a):wifi  设置

 vim /etc/config/wireless

 

 把里面的 option disabled 1  改成  option disabled 0  即:启用wifi

 

  (b): vim /etc/config/network

 

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd5a:9269:a137::/48'

config interface 'lan'
        #option ifname 'eth0'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        #option ip6assign '60'


config interface 'wan'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.8.101'
        option netmask '255.255.255.0'
        option gateway '192.168.8.1'
        option dns     '202.106.0.20'

 

加入一个 8 段的 网的目的是 一会 这个段用来接入一个可以上互联网的网线,以便接来下的更新包和安装包用。  重启网络/etc/init.d/network restart 。

启动成功后 pc通无线连接上该路由器。然后把8 段的网线插入路由器的网线口。通过putty再次登录到该路由器,执行:

1: opkg update

2:  opkg install minicom     安装minicom工具

 

 

 

arduino 接入路由器的

将路由器通过mini usb口直接由电源供电,将arudino nuo的usb线接入路由器。
•安装串口识别库:执行

1: opkg install kmod-usb-serial-ftdi

2: opkg install kmod-usb-acm 。
•执行ls /dev查看设备情况,如果是arduino UNO,应该有ttyACM0,表示成功识别。
•设置minicom,执行minicom -s启动minicom,选择Serial port setup,修改

1:  Serial Device: /dev/ttyACM0

2: 波特率修改为9600

3:  Hardware Flow Control改为 NO 
 •测试,可以写个简单的arduino程序,读取串口数据x,然后串口输出resut:x。 这样在minicom中输入字符,看arduino的返回结果。
•退出minicom,按 一下ctrl+A, 然后按Q。  在选择yes

 

未完,待续。

 

 

 

 

  • 大小: 13.7 KB
  • 大小: 41.6 KB
  • 大小: 73 KB
  • 大小: 34.5 KB
这是我的.cpp文件:#include "MLX90393.h" MLX90393::MLX90393(uint8_t csPin, SPIClass* spi) { _csPin = csPin; _spi = spi; pinMode(_csPin, OUTPUT); digitalWrite(_csPin, HIGH); } MLX90393::MLX90393(uint8_t i2cAddress, TwoWire* wire) { _i2cAddress = i2cAddress; _wire = wire; } void MLX90393::ChangeI2CAddress(uint8_t address) { _i2cAddress = address; } void MLX90393::EX(uint8_t *receiveBuffer, bool isSPI) { write_buffer[0] = 0x80; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::SB(uint8_t *receiveBuffer, uint8_t zyxt, bool isSPI) { write_buffer[0] = 0x10 | zyxt; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::SWOC(uint8_t *receiveBuffer, uint8_t zyxt, bool isSPI) { write_buffer[0] = 0x20 | zyxt; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::SM(uint8_t *receiveBuffer, uint8_t zyxt, bool isSPI) { write_buffer[0] = 0x30 | zyxt; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::RM(uint8_t *receiveBuffer, uint8_t zyxt, bool isSPI) { write_buffer[0] = 0x40 | zyxt; uint8_t dataLen = 2 * count_set_bits(zyxt); for (uint8_t i = 0; i < dataLen; i++) write_buffer[i + 1] = 0x00; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, dataLen + 1); else Send_I2C(receiveBuffer, write_buffer, 1, dataLen + 1); } void MLX90393::RR(uint8_t *receiveBuffer, uint8_t address, bool isSPI) { write_buffer[0] = 0x50; write_buffer[1] = address << 2; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 2, 3); else Send_I2C(receiveBuffer, write_buffer, 2, 3); } void MLX90393::WR(uint8_t *receiveBuffer, uint8_t address, uint16_t data, bool isSPI) { write_buffer[0] = 0x60; write_buffer[1] = (data >> 8) & 0xFF; write_buffer[2] = data & 0xFF; write_buffer[3] = address << 2; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 4, 1); else Send_I2C(receiveBuffer, write_buffer, 4, 1); } void MLX90393::RT(uint8_t *receiveBuffer, bool isSPI) { write_buffer[0] = 0xF0; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::NOP(uint8_t *receiveBuffer, bool isSPI) { write_buffer[0] = 0x00; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::HR(uint8_t *receiveBuffer, bool isSPI) { write_buffer[0] = 0xD0; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::HS(uint8_t *receiveBuffer, bool isSPI) { write_buffer[0] = 0xE0; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 1, 1); else Send_I2C(receiveBuffer, write_buffer, 1, 1); } void MLX90393::DT(uint8_t *receiveBuffer, uint16_t data, bool isSPI) { write_buffer[0] = 0x70; write_buffer[1] = (data >> 8) & 0xFF; write_buffer[2] = data & 0xFF; if (isSPI) Send_SPI(receiveBuffer, write_buffer, 3, 1); // I2C版本暂不实现 } void MLX90393::Send_SPI(uint8_t *receiveBuffer, uint8_t *sendBuffer, uint8_t sendLen, uint8_t recvLen) { digitalWrite(_csPin, LOW); for (uint8_t i = 0; i < sendLen; i++) { _spi->transfer(sendBuffer[i]); } for (uint8_t i = 0; i < recvLen; i++) { receiveBuffer[i] = _spi->transfer(0x00); } digitalWrite(_csPin, HIGH); } void MLX90393::Send_I2C(uint8_t *receiveBuffer, uint8_t *sendBuffer, uint8_t sendLen, uint8_t recvLen) { _wire->beginTransmission(_i2cAddress); _wire->write(sendBuffer, sendLen); _wire->endTransmission(false); _wire->requestFrom((int)_i2cAddress, (int)recvLen); for (uint8_t i = 0; i < recvLen && _wire->available(); i++) { receiveBuffer[i] = _wire->read(); } } uint8_t MLX90393::count_set_bits(uint8_t val) { uint8_t count = 0; while (val) { count += val & 1; val >>= 1; } return count; } 帮我分析为什么我的UNO串口输出为数据: FF FF FF FF FF FF
最新发布
07-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值