#include <DHTxx.h>
#define PUBLISH_DELAY 5000
DHTXX io_HTS1 = DHTXX (8, 11);
long previousMillis;
int Motor1 = 7;
int Motor2 = 6;
int Motor3 = 5;
int Motor4 = 4;
void setup() {
Serial.begin(9600);
while(!Serial) {};
io_HTS1.begin();
previousMillis = millis();
pinMode(Motor1, OUTPUT);
pinMode(Motor2, OUTPUT);
pinMode(Motor3, OUTPUT);
pinMode(Motor4, OUTPUT);
digitalWrite(Motor1, HIGH);
digitalWrite(Motor2, HIGH);
digitalWrite(Motor3, HIGH);
digitalWrite(Motor4, HIGH);
void loop() {
if(millis() - previousMillis > PUBLISH_DELAY) {
sendData();
previousMillis = millis();
readData();
void readData()
char val = Serial.read();
if(val == '1')
digitalWrite(Motor2, LOW);
digitalWrite(Motor1, HIGH);
if(val == '0')
digitalWrite(Motor1, LOW);
digitalWrite(Motor2, LOW);
void sendData() {
char msgBuffer[50];
float var_Humidity=io_HTS1.readHumidity();
float var_tCelsius=io_HTS1.readTemperature(0);
float var_tFarhenheit=io_HTS1.readTemperature(1);
Serial.println(dtostrf(var_tCelsius, 6, 0, msgBuffer));
Serial.println(dtostrf(var_Humidity, 6, 0, msgBuffer));
MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的"轻量级"通讯协议,是 TCP/IP 的再封装,由 IBM 在 1999 年发布。MQTT 最大优点在于,地开销,少流量实现网络通信
mqtt 协议中有两种角色,客户端和服务端。服务.
使用Protues进行Arduino仿真——Blink一、准备工作(1)安装Proteus
Proteus简介 Proteus软件是英国Lab Center Electronics公司出版的EDA工具软件(该软件中国总代理为广州风标电子技术有限公司)。它不仅具有其它EDA工具软件的仿真功能,还能仿真单片机及外围器件。它是目前比较好的仿真单片机及外围器件的工具。虽然目前国内推广刚起步,但已受到单片
b)下载MQTT c语言的包:
C/C++ MQTT Embedded clients
https://www.eclipse.org/paho/clients/c/embedded/
c)MQTT基础知识
http://mqtt.org/
http://download....