资源简介
Wemos D1 mini阿里云MQTT例程
代码片段和文件信息
/**
* The MIT License (MIT)
* Copyright (c) 2015 by Fabrice Weinberg
*
* Permission is hereby granted free of charge to any person obtaining a copy
* of this software and associated documentation files (the “Software“) to deal
* in the Software without restriction including without limitation the rights
* to use copy modify merge publish distribute sublicense and/or sell
* copies of the Software and to permit persons to whom the Software is
* furnished to do so subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED “AS IS“ WITHOUT WARRANTY OF ANY KIND EXPRESS OR
* IMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM DAMAGES OR OTHER
* LIABILITY WHETHER IN AN ACTION OF CONTRACT TORT OR OTHERWISE ARISING FROM
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include “NTPClient.h“
NTPClient::NTPClient(UDP& udp) {
this->_udp = &udp;
}
NTPClient::NTPClient(UDP& udp int timeOffset) {
this->_udp = &udp;
this->_timeOffset = timeOffset;
}
NTPClient::NTPClient(UDP& udp const char* poolServerName) {
this->_udp = &udp;
this->_poolServerName = poolServerName;
}
NTPClient::NTPClient(UDP& udp const char* poolServerName int timeOffset) {
this->_udp = &udp;
this->_timeOffset = timeOffset;
this->_poolServerName = poolServerName;
}
NTPClient::NTPClient(UDP& udp const char* poolServerName int timeOffset int updateInterval) {
this->_udp = &udp;
this->_timeOffset = timeOffset;
this->_poolServerName = poolServerName;
this->_updateInterval = updateInterval;
}
void NTPClient::begin() {
this->begin(NTP_DEFAULT_LOCAL_PORT);
}
void NTPClient::begin(int port) {
this->_port = port;
this->_udp->begin(this->_port);
this->_udpSetup = true;
}
bool NTPClient::forceUpdate() {
#ifdef DEBUG_NTPClient
Serial.println(“Update from NTP Server“);
#endif
this->sendNTPPacket();
// Wait till data is there or timeout...
byte timeout = 0;
int cb = 0;
do {
delay ( 10 );
cb = this->_udp->parsePacket();
if (timeout > 100) return false; // timeout after 1000 ms
timeout++;
} while (cb == 0);
this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time
this->_udp->read(this->_packetBuffer NTP_PACKET_SIZE);
unsigned long highWord = word(this->_packetBuffer[40] this->_packetBuffer[41]);
unsigned long lowWord = word(this->_packetBuffer[42] this->_packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (se
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12000 2020-05-12 18:58 test10\IRremote.h
文件 3870 2020-05-12 18:58 test10\IRremoteInt.h
文件 5888 2020-05-12 18:58 test10\NTPClient.cpp
文件 2296 2020-05-12 18:58 test10\NTPClient.h
文件 19996 2020-05-12 18:58 test10\PubSubClient.cpp
文件 7538 2020-05-12 18:58 test10\PubSubClient.h
文件 8459 2020-10-12 14:00 test10\test10.ino
目录 0 2020-05-12 19:34 test10\log
目录 0 2020-10-12 14:00 test10
----------- --------- ---------- ----- ----
60047 9
- 上一篇:QT 计算文件夹内所有代码行数
- 下一篇:无人机飞控+ps2遥控代码
评论
共有 条评论