完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我有一个 ESP8266 配置为服务器,将从其 ADC 引脚读取的电压值发送到 ESP8266 客户端,当打印到服务器上的串行终端时,电压变量显示正常,但在客户端显示为两个问号。有人对此有解决方案吗?两个设备的代码以及串行日志如下所示。
服务器草图代码: 代码:全选/* This sketch sets up the ESP8266 as a WiFi softAP, starts a WiFi server with a fixed IP and listens * for a client's request, then sends the supply voltage taken from the ADC pin back to the client */ #include int adcvalue = 0; float LSB = .011887383; char ssid[] = "ESP07"; char pass[] = "xxxxxxxx"; WiFiServer server(80); IPAddress ip(192,168,8,1); // IP address of the server IPAddress gateway(192,168,8,1); // gateway of your network IPAddress subnet(255,255,255,0); // subnet mask of your network void setup() { Serial.begin(115200); WiFi.mode(WIFI_AP); //switching to AP mode WiFi.softAP(ssid, pass); //initializing the AP with ssid and password. This will create a WPA2-PSK secured AP WiFi.config(ip, gateway, subnet); // forces to use the fixed IP WiFi.begin(); Serial.println("."); Serial.println("Wifi Started"); server.begin(); // starts the server Serial.println("Server Started"); } void loop () { adcvalue = (analogRead(A0)); Serial.print("ADC Value is: "); Serial.println(adcvalue); float supplyvoltage = adcvalue*LSB; Serial.print("Supply Voltage is: "); Serial.println(supplyvoltage); char strvoltage[15]; dtostrf(supplyvoltage,6,2,strvoltage); Serial.print("strvoltage is: "); Serial.println(strvoltage); delay(1000); WiFiClient client = server.available(); if (client) { if (client.connected()) { Serial.println("."); String request = client.readStringUntil('r'); // receives the message from the client Serial.print("From client: "); Serial.println(request); client.flush(); client.println(strvoltage + 'r'); // sends the answer to the client } client.stop(); // terminates the connection with the client } } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
313 浏览 0 评论
1170 浏览 1 评论
585浏览 6评论
483浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
468浏览 5评论
467浏览 4评论
442浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 04:52 , Processed in 0.710397 second(s), Total 74, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号