一、模块调试

1、水位模块

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <DHT.h>
const char* ssid = "ESP82666";//wifi账号
const char* password = "12345678";//wifi密码WiFiUDP Udp;
unsigned int localUdpPort = 2333;  // 本地监听端口
char incomingPacket[255];  // 存储Udp客户端发过来的数据
char  replyPacket[] = "Hi there! Got the message :-)";  // 应答信息
String comdata = "";
//*********设置固定IP*************//
IPAddress local_IP(192, 168, 137, 185);
// Set your Gateway IP address
IPAddress gateway(192, 168, 137, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
void setup()
{Serial.begin(9600);Serial.println();Serial.printf("Connecting to %s ", ssid);if(!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {Serial.println("STA Failed to configure");
}WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED){delay(500);Serial.print(".");}Serial.println(" connected");//启动Udp监听服务Udp.begin(localUdpPort);//打印本地ip地址,udp client端会使用到Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}void loop()
{while (Serial.available() > 0)  {comdata += char(Serial.read());delay(2);}if (comdata.length() > 0){Serial.println(comdata);int a_1=comdata.substring(7).toInt();if(a_1<0){a_1=0;}Udp.beginPacket("192.168.137.32", 2333);Udp.print(String(a_1));Udp.endPacket();comdata = "";}//解析Udp数据包int packetSize = Udp.parsePacket();if (packetSize){// 收到Udp数据包Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());// 读取Udp数据包int len = Udp.read(incomingPacket, 255);if (len > 0){incomingPacket[len] = 0;}//向串口调试器打印信息Serial.printf("UDP packet contents: %s\n", incomingPacket);//往udp 远端发送应答信息}
}

2、DS18B20

#include "OneWire.h"
#include "DallasTemperature.h"#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);void setup(void)
{Serial.begin(9600);
Serial.println("Begin get temp!");
Serial.println();
sensors.begin();
delay(5000);
}void loop()
{sensors.requestTemperatures();
Serial.print("Temperature : ");
Serial.println(sensors.getTempCByIndex(0));
delay(1000);}

3、PH

4.采集小结

//***************WIFI设置************//
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "ESP82666";//wifi账号
const char* password = "12345678";//wifi密码
WiFiUDP Udp;
unsigned int localUdpPort = 2333;  // 本地监听端口
char incomingPacket[255];  // 存储Udp客户端发过来的数据
String comdata = "";
//*********设置固定IP*************//
IPAddress local_IP(192, 168, 137, 185);
// Set your Gateway IP address
IPAddress gateway(192, 168, 137, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
//***********定义PH值***************//
#define SensorPin A0            //pH meter Analog output to Arduino Analog Input 1
#define Offset 21.677           //deviation compensate
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth  40    //times of collection
int pHArray[ArrayLenth];   //Store the average value of the sensor feedback
int pHArrayIndex=0;
//**********DS18B20*******//
#include "OneWire.h"
#include "DallasTemperature.h"#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup()
{Serial.begin(9600);Serial.println();
sensors.begin();Serial.printf("Connecting to %s ", ssid);if(!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {Serial.println("STA Failed to configure");
}WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED){delay(500);Serial.print(".");}Serial.println(" connected");//启动Udp监听服务Udp.begin(localUdpPort);//打印本地ip地址,udp client端会使用到Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}void loop()
{PHmain();shuiwei();UDP();//******ds18b20******//sensors.requestTemperatures();Serial.print("Temperature : ");Serial.println(sensors.getTempCByIndex(0));Udp.beginPacket("192.168.137.32", 2334);Udp.print(String(sensors.getTempCByIndex(0)));Udp.endPacket();}
void UDP(){//**********解析Udp数据包int packetSize = Udp.parsePacket();if (packetSize){// 收到Udp数据包Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());// 读取Udp数据包int len = Udp.read(incomingPacket, 255);if (len > 0){incomingPacket[len] = 0;}//向串口调试器打印信息Serial.printf("UDP packet contents: %s\n", incomingPacket);//往udp 远端发送应答信息}}
void shuiwei(){while (Serial.available() > 0)  {comdata += char(Serial.read());delay(2);}if (comdata.length() > 0){//Serial.println(comdata);int a_1=comdata.substring(7).toInt();if(a_1<0){a_1=0;}Udp.beginPacket("192.168.137.32", 2333);Udp.print(String(a_1));Udp.endPacket();comdata = "";}}
//**************PH值运算子程序******************//
double avergearray(int* arr, int number){int i;int max,min;double avg;long amount=0;if(number<=0){Serial.println("Error number for the array to avraging!/n");return 0;}if(number<5){   //less than 5, calculated directly statisticsfor(i=0;i<number;i++){amount+=arr[i];}avg = amount/number;return avg;}else{if(arr[0]<arr[1]){min = arr[0];max=arr[1];}else{min=arr[1];max=arr[0];}for(i=2;i<number;i++){if(arr[i]<min){amount+=min;        //arr<minmin=arr[i];}else {if(arr[i]>max){amount+=max;    //arr>maxmax=arr[i];}else{amount+=arr[i]; //min<=arr<=max}}//if}//foravg = (double)amount/(number-2);}//ifreturn avg;
}
void PHmain(){static unsigned long samplingTime = millis();static unsigned long printTime = millis();static float pHValue,voltage;if(millis()-samplingTime > samplingInterval){pHArray[pHArrayIndex++]=analogRead(SensorPin);if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;pHValue = -5.8887*voltage+Offset;if(pHValue<=0.0){pHValue=0.0;}if(pHValue>14.0){pHValue=14.0;}samplingTime=millis();}if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator{Serial.print("Voltage:");Serial.print(voltage,2);Serial.print("    pH value: ");Serial.println(pHValue,2);Udp.beginPacket("192.168.137.32", 2335);Udp.print(String(pHValue));Udp.endPacket();printTime=millis();}}

基于ESP8266的物联网智能鱼缸系统设计相关推荐

  1. 【基于RT-Thread+RA6M4的智能鱼缸系统设计之鱼我所欲也】

    [基于RT-Thread+RA6M4的智能鱼缸系统设计之鱼我所欲也] 摘 要: 0 引言 1. 总体设计 2. 硬件设计 2.1 控制器 2.2 传感器 2.3 执行器 2.4 电源 2.5 鱼缸 3 ...

  2. 最简单DIY基于ESP8266的物联网智能小车①(webserver服务器网页简单遥控版)

    ESP8266和ESP32物联网智能小车开发系列文章目录 第一篇:最简单DIY基于ESP8266的物联网智能小车①(webserver服务器网页简单遥控版) 文章目录 ESP8266和ESP32物联网 ...

  3. 基于ESP8266的物联网智能插排

    事情的起因是这样的.......... 为了伺候鱼缸里的几条小孔雀鱼,每天早上我都要起来开水泵.开水草灯,晚上睡前则要关灯关水泵. PS:晚上睡觉感觉水流声还是有些吵. 作为一个理工男,这种重复性的工 ...

  4. 基于STM32F103C8T6与ESP8266的物联网智能温度采集与蓝牙OLED数字钟的设计与实现

    基于STM32F103C8T6与ESP8266的物联网智能温度采集与蓝牙OLED数字钟的设计与实现 作者: 颜孙炜 文章目录 基于STM32F103C8T6与ESP8266的物联网智能温度采集与蓝牙O ...

  5. STM32物联网智能鱼缸智能家居系统(程序+原理图+PCB+图文教程)

    本设计: 基于STM32物联网智能鱼缸智能家居系统设计方案(程序+原理图+PCB) 原理图:Altium Designer 程序编译器:keil 5 编程语言:C语言 编号C0027 功能说明: 1. ...

  6. STM32物联网智能鱼缸智能家居系统设计方案 【评论区里留言领取资料】

    AD封装库元器件库大全: 封装库 本设计: 基于STM32物联网智能鱼缸智能家居系统设计方案(程序+原理图+PCB) 原理图:Altium Designer 程序编译器:keil 5 编程语言:C语言 ...

  7. 基于51单片机的智能鱼缸设计。 有原理图,程序,原文,可代做实物。 才用STC12C5A60S2,最新款国产51单片机

    基于51单片机的智能鱼缸设计. 有原理图,程序,原文,可代做实物. 才用STC12C5A60S2,最新款国产51单片机. 本系统设计的主要是基于单片机为核心,设计一款集温度检测.恒温控制.步进电机控制 ...

  8. 基于51单片机的智能鱼缸设计

    基于51单片机的智能鱼缸设计. 有原理图,程序,原文,可代做实物. 才用STC12C5A60S2,最新款国产51单片机. 本系统设计的主要是基于单片机为核心,设计一款集温度检测.恒温控制.步进电机控制 ...

  9. 基于FreeRTOS的物联网智能车库管理系统(可进行车牌识别)

    FreeRTOS操作系统与物联网项目实战 学了一周的FreeRTOS实时操作系统,物联网也学过了,看到网上低配版的操作系统车库,于是便想着自己做个高配版的,便开始了我的一周项目计划. 文章目录 Fre ...

最新文章

  1. xp下安装redmine 2.4.3
  2. 用Vue的父子组件通信实现todolist的功能
  3. SAP Spartacus B2B 页面 Disable 按钮的显示原理
  4. 基于python的性能测试工具–locust
  5. String length must be a multiple of four.
  6. 运行初始化过程代码笔记
  7. android第三方推送实现,Android--利用第三方推送实现APP伪保活(小米篇)
  8. NPM流行包再起波澜:维护人员对俄罗斯用户发特定消息,谁来保证开源可信?...
  9. Atitit管理学课程表 管理学体系
  10. RN上使用react-native-video视频播放器插件
  11. 【转载】Goldendict下优质词典简介及安装 (2016-07-29 23:33:20)
  12. 实现用python给微信指定联系人在指定时间发送消息(仅供学习)
  13. zte d90 java_zte d90 驱动程序(最新更新)尼康d90驱动
  14. 吱口令生成淘宝BP抢购链接
  15. 大数据开发有哪些难点?
  16. c语言void要用什么头文件,什么是C语言头文件?
  17. 画论24 郭若虛《图画见闻志》
  18. php随机分配班级座位,浅谈班级座位安排原则与方法
  19. GIS电子地图定制开发技术
  20. 找了这么多毕业设计题目,反而不知道选哪个了

热门文章

  1. python实现excel计算_用python实现简单EXCEL数据统计的实例
  2. [家里蹲大学数学杂志]第218期正项级数的审敛法与人生态度
  3. Android 4.1.2微信版本,ttkefu在线客服系统
  4. java.lang.ClassNotFoundException:如何解决
  5. 3. 站在使用层面,Bean Validation这些标准接口你需要烂熟于胸
  6. 2018下半年Android面试历程
  7. (以三星S8为例)安卓全面屏手势设置教程
  8. html自动对齐快捷键,Sketch 技巧:好用的对齐快捷键(附设置教程)
  9. 环境搭建 - 奥比中光3D摄像头(Deeyea)
  10. 化工原理 --- 流体流动 2