* AM2321的取温度间隔得大于2s,否则,i2c会不工作了 * SimpleTimer有个bug,会导致两次快速的读温度,现在读温度函数里加了保护 * Blynk有个bug,会导致无法把数据传到服务器 * 现在可以正常工作了
BlynkDebug.h
00001 /** 00002 * @file BlynkDebug.h 00003 * @author Volodymyr Shymanskyy 00004 * @license This project is released under the MIT License (MIT) 00005 * @copyright Copyright (c) 2015 Volodymyr Shymanskyy 00006 * @date Jan 2015 00007 * @brief Debug utilities 00008 * 00009 */ 00010 00011 #ifndef BlynkDebug_h 00012 #define BlynkDebug_h 00013 00014 #include <Blynk/BlynkConfig.h> 00015 #include <stddef.h> 00016 #ifdef ESP8266 00017 extern "C" { 00018 #include "ets_sys.h" 00019 #include "os_type.h" 00020 #include "mem.h" 00021 } 00022 #else 00023 #include <inttypes.h> 00024 #endif 00025 00026 #if defined(ARDUINO_ARCH_ARC32) 00027 typedef uint64_t millis_time_t; 00028 #else 00029 typedef uint32_t millis_time_t; 00030 #endif 00031 00032 #if defined(SPARK) || defined(PARTICLE) 00033 #include "application.h" 00034 #endif 00035 00036 #if defined(ARDUINO) 00037 #if ARDUINO >= 100 00038 #include "Arduino.h" 00039 #else 00040 #include "WProgram.h" 00041 #endif 00042 #endif 00043 00044 #if !defined(ARDUINO) || (ARDUINO < 151) 00045 #define BLYNK_NO_YIELD 00046 #endif 00047 00048 // General defines 00049 00050 #define STRINGIFY(x) #x 00051 #define TOSTRING(x) STRINGIFY(x) 00052 #define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) 00053 #define BLYNK_ATTR_PACKED __attribute__ ((__packed__)) 00054 #define BLYNK_NORETURN __attribute__ ((noreturn)) 00055 00056 // Causes problems on some platforms 00057 #define BLYNK_FORCE_INLINE inline //__attribute__((always_inline)) 00058 00059 #if defined(__AVR__) 00060 #include <avr/pgmspace.h> 00061 #define BLYNK_HAS_PROGMEM 00062 #define BLYNK_PROGMEM PROGMEM 00063 #define BLYNK_F(s) F(s) 00064 #define BLYNK_PSTR(s) PSTR(s) 00065 #else 00066 #define BLYNK_PROGMEM 00067 #define BLYNK_F(s) s 00068 #define BLYNK_PSTR(s) s 00069 #endif 00070 00071 #ifndef LED_BUILTIN 00072 # define LED_BUILTIN 2 00073 #endif 00074 00075 // Diagnostic defines 00076 00077 size_t BlynkFreeRam(); 00078 void BlynkReset() BLYNK_NORETURN; 00079 void BlynkFatal() BLYNK_NORETURN; 00080 00081 #define BLYNK_FATAL(msg) { BLYNK_LOG1(msg); BlynkFatal(); } 00082 #define BLYNK_LOG_RAM() { BLYNK_LOG2(BLYNK_F("Free RAM: "), BlynkFreeRam()); } 00083 #define BLYNK_LOG_FN() BLYNK_LOG3(BLYNK_F(__FUNCTION__), '@', __LINE__); 00084 #define BLYNK_LOG_TROUBLE(t) BLYNK_LOG2(BLYNK_F("Trouble detected: http://docs.blynk.cc/#troubleshooting-"), t) 00085 00086 #ifndef BLYNK_PRINT 00087 #undef BLYNK_DEBUG 00088 #endif 00089 00090 #ifdef BLYNK_PRINT 00091 00092 #if defined(ARDUINO) || defined(SPARK) || defined(PARTICLE) 00093 00094 #if defined(ARDUINO_ARCH_ARC32) 00095 // This will cause error - on purpose 00096 #define BLYNK_LOG(msg, ...) BLYNK_LOG_UNAVAILABLE(msg, ##__VA_ARGS__) 00097 #else 00098 #define BLYNK_LOG(msg, ...) blynk_dbg_print(BLYNK_PSTR(msg), ##__VA_ARGS__) 00099 #endif 00100 00101 #define BLYNK_LOG1(p1) { BLYNK_LOG_TIME(); BLYNK_PRINT.println(p1); } 00102 #define BLYNK_LOG2(p1,p2) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.println(p2); } 00103 #define BLYNK_LOG3(p1,p2,p3) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.println(p3); } 00104 #define BLYNK_LOG4(p1,p2,p3,p4) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.print(p3); BLYNK_PRINT.println(p4); } 00105 #define BLYNK_LOG6(p1,p2,p3,p4,p5,p6) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.print(p3); BLYNK_PRINT.print(p4); BLYNK_PRINT.print(p5); BLYNK_PRINT.println(p6); } 00106 #define BLYNK_LOG_IP(msg, ip) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(BLYNK_F(msg)); \ 00107 BLYNK_PRINT.print(ip[0]); BLYNK_PRINT.print('.'); \ 00108 BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \ 00109 BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \ 00110 BLYNK_PRINT.println(ip[3]); } 00111 #define BLYNK_LOG_IP_REV(msg, ip) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(BLYNK_F(msg)); \ 00112 BLYNK_PRINT.print(ip[3]); BLYNK_PRINT.print('.'); \ 00113 BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \ 00114 BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \ 00115 BLYNK_PRINT.println(ip[0]); } 00116 00117 static 00118 void BLYNK_LOG_TIME() { 00119 BLYNK_PRINT.print('['); 00120 BLYNK_PRINT.print(millis()); 00121 BLYNK_PRINT.print(BLYNK_F("] ")); 00122 } 00123 00124 #ifdef BLYNK_DEBUG 00125 #include <ctype.h> 00126 #define BLYNK_DBG_BREAK() { for(;;); } 00127 #define BLYNK_ASSERT(expr) { if(!(expr)) { BLYNK_LOG2(BLYNK_F("Assertion failed: "), BLYNK_F(#expr)); BLYNK_DBG_BREAK() } } 00128 00129 static 00130 void BLYNK_DBG_DUMP(const char* msg, const void* addr, size_t len) { 00131 if (len) { 00132 BLYNK_LOG_TIME(); 00133 BLYNK_PRINT.print(msg); 00134 int l2 = len; 00135 const uint8_t* octets = (const uint8_t*)addr; 00136 bool prev_print = true; 00137 while (l2--) { 00138 const uint8_t c = *octets++ & 0xFF; 00139 if (isprint(c)) { 00140 if (!prev_print) { BLYNK_PRINT.print(']'); } 00141 BLYNK_PRINT.print((char)c); 00142 prev_print = true; 00143 } else { 00144 BLYNK_PRINT.print(prev_print?'[':'|'); 00145 if (c < 0x10) { BLYNK_PRINT.print('0'); } 00146 BLYNK_PRINT.print(c, HEX); 00147 prev_print = false; 00148 } 00149 } 00150 BLYNK_PRINT.println(prev_print?"":"]"); 00151 } 00152 } 00153 #endif 00154 00155 #if !defined(ARDUINO_ARCH_ARC32) 00156 #include <stdio.h> 00157 #include <stdarg.h> 00158 00159 static 00160 void blynk_dbg_print(const char* BLYNK_PROGMEM fmt, ...) 00161 { 00162 va_list ap; 00163 va_start(ap, fmt); 00164 char buff[128]; 00165 BLYNK_PRINT.print('['); 00166 BLYNK_PRINT.print(millis()); 00167 BLYNK_PRINT.print(F("] ")); 00168 #if defined(__AVR__) 00169 vsnprintf_P(buff, sizeof(buff), fmt, ap); 00170 #else 00171 vsnprintf(buff, sizeof(buff), fmt, ap); 00172 #endif 00173 BLYNK_PRINT.println(buff); 00174 va_end(ap); 00175 } 00176 #endif // ARDUINO_ARCH_ARC32 00177 00178 #elif defined(LINUX) || defined(MBED_LIBRARY_VERSION) 00179 00180 #include <assert.h> 00181 #include <stdio.h> 00182 #include <string.h> 00183 #include <errno.h> 00184 #include <signal.h> 00185 00186 #include <iostream> 00187 using namespace std; 00188 #define BLYNK_LOG(msg, ...) { fprintf(BLYNK_PRINT, "[%ld] " msg "\n", millis(), ##__VA_ARGS__); } 00189 #define BLYNK_LOG1(p1) { BLYNK_LOG_TIME(); cout << p1 << endl; } 00190 #define BLYNK_LOG2(p1,p2) { BLYNK_LOG_TIME(); cout << p1 << p2 << endl; } 00191 #define BLYNK_LOG3(p1,p2,p3) { BLYNK_LOG_TIME(); cout << p1 << p2 << p3 << endl; } 00192 #define BLYNK_LOG4(p1,p2,p3,p4) { BLYNK_LOG_TIME(); cout << p1 << p2 << p3 << p4 << endl; } 00193 #define BLYNK_LOG6(p1,p2,p3,p4,p5,p6) { BLYNK_LOG_TIME(); cout << p1 << p2 << p3 << p4 << p5 << p6 << endl; } 00194 00195 #define BLYNK_LOG_TIME() cout << '[' << millis() << "] "; 00196 00197 #ifdef BLYNK_DEBUG 00198 #define BLYNK_DBG_BREAK() raise(SIGTRAP); 00199 #define BLYNK_ASSERT(expr) assert(expr) 00200 #define BLYNK_DBG_DUMP(msg, addr, len) if (len) { fprintf(BLYNK_PRINT, msg); fwrite(addr, len, 1, BLYNK_PRINT); fputc('\n', BLYNK_PRINT); } 00201 #endif 00202 00203 #else 00204 00205 #warning Could not detect platform 00206 00207 #endif 00208 00209 #endif 00210 00211 #ifndef BLYNK_LOG 00212 #define BLYNK_LOG(...) 00213 #define BLYNK_LOG1(p1) 00214 #define BLYNK_LOG2(p1,p2) 00215 #define BLYNK_LOG3(p1,p2,p3) 00216 #define BLYNK_LOG4(p1,p2,p3,p4) 00217 #define BLYNK_LOG6(p1,p2,p3,p4,p5,p6) 00218 #define BLYNK_LOG_IP(msg, ip) 00219 #define BLYNK_LOG_IP_REV(msg, ip) 00220 #endif 00221 00222 #ifndef BLYNK_DBG_BREAK 00223 #define BLYNK_DBG_BREAK() 00224 #define BLYNK_ASSERT(expr) 00225 #define BLYNK_DBG_DUMP(msg, addr, len) 00226 #endif 00227 00228 #endif 00229
Generated on Tue Jul 12 2022 13:01:26 by 1.7.2