├── FRID智能控制门禁 ├── FRID_arduino │ └── FRID_arduino.ino └── read_code │ └── read_code.ino ├── MP3播放器 ├── MP3_test │ ├── DFPlayer_Mini_Mp3.h │ └── MP3_test.ino ├── mp3player_esp8266 │ ├── DFPlayer_Mini_Mp3.h │ └── mp3player_esp8266.ino └── 库文件 │ └── DFPlayer-Mini-mp3-master │ ├── DFPlayer_Mini_Mp3.cpp │ ├── DFPlayer_Mini_Mp3.h │ ├── README.md │ ├── keywords.txt │ └── license.txt ├── README.md ├── libraries ├── Adafruit_CCS811_Library │ ├── Adafruit_CCS811.cpp │ ├── Adafruit_CCS811.h │ ├── LICENSE │ ├── README.md │ ├── examples │ │ ├── CCS811_OLED_Demo │ │ │ └── CCS811_OLED_Demo.ino │ │ └── CCS811_test │ │ │ └── CCS811_test.ino │ └── library.properties ├── Adafruit_ESP8266 │ ├── Adafruit_ESP8266.cpp │ ├── Adafruit_ESP8266.h │ ├── README.md │ ├── examples │ │ └── webclient │ │ │ └── webclient.ino │ ├── library.properties │ └── previous │ │ └── Adafruit_ESP8266.ino ├── Adafruit_NeoPixel │ ├── Adafruit_NeoPixel.cpp │ ├── Adafruit_NeoPixel.h │ ├── COPYING │ ├── README.md │ ├── esp8266.c │ ├── examples │ │ ├── RGBLED │ │ │ └── RGBLED.ino │ │ ├── RGBWstrandtest │ │ │ └── RGBWstrandtest.ino │ │ ├── StrandtestBLE │ │ │ ├── BLESerial.cpp │ │ │ ├── BLESerial.h │ │ │ └── StrandtestBLE.ino │ │ ├── buttoncycler │ │ │ └── buttoncycler.ino │ │ ├── simple │ │ │ └── simple.ino │ │ └── strandtest │ │ │ └── strandtest.ino │ ├── keywords.txt │ └── library.properties ├── DHT_sensor_library │ ├── CONTRIBUTING.md │ ├── DHT.cpp │ ├── DHT.h │ ├── DHT_U.cpp │ ├── DHT_U.h │ ├── README.md │ ├── examples │ │ ├── DHT_Unified_Sensor │ │ │ └── DHT_Unified_Sensor.ino │ │ └── DHTtester │ │ │ └── DHTtester.ino │ ├── keywords.txt │ └── library.properties ├── IRremote │ ├── Contributing.md │ ├── Contributors.md │ ├── IRremote.cpp │ ├── IRremote.h │ ├── IRremoteInt.h │ ├── ISSUE_TEMPLATE.md │ ├── LICENSE.txt │ ├── README.md │ ├── arduino-irremote.sublime-workspace │ ├── boarddefs.h │ ├── changelog.md │ ├── esp32.cpp │ ├── examples │ │ ├── AiwaRCT501SendDemo │ │ │ └── AiwaRCT501SendDemo.ino │ │ ├── IRrecord │ │ │ └── IRrecord.ino │ │ ├── IRrecvDemo │ │ │ └── IRrecvDemo.ino │ │ ├── IRrecvDump │ │ │ └── IRrecvDump.ino │ │ ├── IRrecvDumpV2 │ │ │ └── IRrecvDumpV2.ino │ │ ├── IRrelay │ │ │ └── IRrelay.ino │ │ ├── IRremoteInfo │ │ │ └── IRremoteInfo.ino │ │ ├── IRsendDemo │ │ │ └── IRsendDemo.ino │ │ ├── IRsendRawDemo │ │ │ └── IRsendRawDemo.ino │ │ ├── IRtest │ │ │ └── IRtest.ino │ │ ├── IRtest2 │ │ │ └── IRtest2.ino │ │ ├── JVCPanasonicSendDemo │ │ │ └── JVCPanasonicSendDemo.ino │ │ ├── LGACSendDemo │ │ │ ├── LGACSendDemo.ino │ │ │ └── LGACSendDemo.md │ │ ├── LegoPowerFunctionsSendDemo │ │ │ └── LegoPowerFunctionsSendDemo.ino │ │ └── LegoPowerFunctionsTests │ │ │ └── LegoPowerFunctionsTests.ino │ ├── irPronto.cpp │ ├── irRecv.cpp │ ├── irSend.cpp │ ├── ir_Aiwa.cpp │ ├── ir_Denon.cpp │ ├── ir_Dish.cpp │ ├── ir_JVC.cpp │ ├── ir_LG.cpp │ ├── ir_Lego_PF.cpp │ ├── ir_Lego_PF_BitStreamEncoder.h │ ├── ir_Mitsubishi.cpp │ ├── ir_NEC.cpp │ ├── ir_Panasonic.cpp │ ├── ir_RC5_RC6.cpp │ ├── ir_Samsung.cpp │ ├── ir_Sanyo.cpp │ ├── ir_Sharp.cpp │ ├── ir_Sony.cpp │ ├── ir_Template.cpp │ ├── ir_Whynter.cpp │ ├── keywords.txt │ ├── library.json │ ├── library.properties │ └── sam.cpp ├── PubSubClient │ ├── CHANGES.txt │ ├── LICENSE.txt │ ├── README.md │ ├── examples │ │ ├── mqtt_auth │ │ │ └── mqtt_auth.ino │ │ ├── mqtt_basic │ │ │ └── mqtt_basic.ino │ │ ├── mqtt_esp8266 │ │ │ └── mqtt_esp8266.ino │ │ ├── mqtt_large_message │ │ │ └── mqtt_large_message.ino │ │ ├── mqtt_publish_in_callback │ │ │ └── mqtt_publish_in_callback.ino │ │ ├── mqtt_reconnect_nonblocking │ │ │ └── mqtt_reconnect_nonblocking.ino │ │ └── mqtt_stream │ │ │ └── mqtt_stream.ino │ ├── keywords.txt │ ├── library.json │ ├── library.properties │ ├── src │ │ ├── PubSubClient.cpp │ │ └── PubSubClient.h │ └── tests │ │ ├── Makefile │ │ ├── README.md │ │ ├── src │ │ ├── connect_spec.cpp │ │ ├── keepalive_spec.cpp │ │ ├── lib │ │ │ ├── Arduino.h │ │ │ ├── BDDTest.cpp │ │ │ ├── BDDTest.h │ │ │ ├── Buffer.cpp │ │ │ ├── Buffer.h │ │ │ ├── Client.h │ │ │ ├── IPAddress.cpp │ │ │ ├── IPAddress.h │ │ │ ├── Print.h │ │ │ ├── ShimClient.cpp │ │ │ ├── ShimClient.h │ │ │ ├── Stream.cpp │ │ │ ├── Stream.h │ │ │ └── trace.h │ │ ├── publish_spec.cpp │ │ ├── receive_spec.cpp │ │ └── subscribe_spec.cpp │ │ └── testcases │ │ ├── mqtt_basic.py │ │ ├── mqtt_publish_in_callback.py │ │ └── settings.py └── readme.md ├── 多模式氛围灯 ├── RGBLED │ └── RGBLED.ino ├── simple │ └── simple.ino └── ws2812_esp8266_color │ └── ws2812_esp8266_color.ino ├── 无线控制空调 └── IRremote_esp8266 │ └── IRremote_esp8266.ino ├── 智能多级照明灯 ├── RGBLED │ └── RGBLED.ino ├── simple │ └── simple.ino └── ws2812_esp8266_bright │ └── ws2812_esp8266_bright.ino └── 智能控制窗帘 ├── steper_arduino └── steper_arduino.ino └── steper_esp8266 └── steper_esp8266.ino /FRID智能控制门禁/FRID_arduino/FRID_arduino.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SS_PIN 10 4 | #define RST_PIN 9 5 | int mSwitch = 2 ; int LEDRed = 3 ; int LEDGreen = 4 ;//设定电磁阀开关及红绿灯Pin值 6 | MFRC522 mfrc522 ( SS_PIN , RST_PIN ); //建立MFRC522.
7 | void setup () { 8 | pinMode ( LEDRed , OUTPUT ); 9 | pinMode ( LEDGreen , OUTPUT ); 10 | pinMode ( mSwitch , OUTPUT ); 11 | Serial . begin ( 9600 ); //设定串列通讯速率 12 | SPI . begin (); //设定SPI bus 13 | mfrc522 . PCD_Init (); //设定MFRC522 14 | Serial . println ( " Put your card close to the reader… " ); 15 | Serial . println (); 16 | } 17 | void loop () { 18 | digitalWrite ( LEDGreen , LOW ); 19 | digitalWrite ( LEDRed , LOW ); 20 | digitalWrite ( mSwitch , LOW ); 21 | if ( ! mfrc522 . PICC_IsNewCardPresent ()) { return ; } // 22 | if ( ! mfrc522 . PICC_ReadCardSerial ()) { return ; } //Show UID on serial monitor 23 | Serial.print ( "Card No. :" 24 | ) ; 25 | String content = "" ; 26 | byte letter ; 27 | for ( byte i = 0 ; i < mfrc522 . uid . size ; i ++) 28 | { 29 | Serial . print ( mfrc522 . uid . uidByte [ i ] < 0x10 ? " 0" : " " ); 30 | Serial . print ( mfrc522 . uid . uidByte [ i ], HEX ); 31 | content . concat ( String ( mfrc522 . uid . uidByte [ i ] < 0x10 ? " 0" : " " )); 32 | content . concat ( String ( mfrc522 . uid . uidByte [ i ], HEX )); 33 | } 34 | Serial . println (); 35 | Serial . print ( " Message : " ); 36 | content . toUpperCase ();
37 | //需要改成可通行的卡号 38 | if ( content . substring ( 1 ) == "FA 91 83 08" ) { 39 | Serial . println ( " Pass… " ); 40 | Serial . println (); //亮绿灯,电磁阀开 41 | digitalWrite ( LEDGreen , HIGH ); 42 | digitalWrite ( LEDRed , LOW ); 43 | digitalWrite ( mSwitch , HIGH ); 44 | delay ( 3000 ); 45 | } 46 | else { Serial . println ( " Stop…" ); //亮红灯,电磁阀关 47 | digitalWrite ( LEDGreen , LOW ); 48 | digitalWrite ( LEDRed , HIGH ); 49 | digitalWrite ( mSwitch , LOW ); 50 | delay ( 3000 ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /FRID智能控制门禁/read_code/read_code.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include // 引用程式庫 3 | 4 | #define RST_PIN A0 // 讀卡機的重置腳位 5 | #define SS_PIN 10 // 晶片選擇腳位 6 | 7 | MFRC522 mfrc522(SS_PIN, RST_PIN); // 建立MFRC522物件 8 | 9 | void setup() { 10 | Serial.begin(9600); 11 | Serial.println("RFID reader is ready!"); 12 | 13 | SPI.begin(); 14 | mfrc522.PCD_Init(); // 初始化MFRC522讀卡機模組 15 | } 16 | 17 | void loop() { 18 | // 確認是否有新卡片 19 | if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) { 20 | byte *id = mfrc522.uid.uidByte; // 取得卡片的UID 21 | byte idSize = mfrc522.uid.size; // 取得UID的長度 22 | 23 | Serial.print("PICC type: "); // 顯示卡片類型 24 | // 根據卡片回應的SAK值(mfrc522.uid.sak)判斷卡片類型 25 | MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak); 26 | Serial.println(mfrc522.PICC_GetTypeName(piccType)); 27 | 28 | Serial.print("UID Size: "); // 顯示卡片的UID長度值 29 | Serial.println(idSize); 30 | 31 | for (byte i = 0; i < idSize; i++) { // 逐一顯示UID碼 32 | Serial.print("id["); 33 | Serial.print(i); 34 | Serial.print("]: "); 35 | Serial.println(id[i], HEX); // 以16進位顯示UID值 36 | } 37 | Serial.println(); 38 | 39 | mfrc522.PICC_HaltA(); // 卡片停止模式 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MP3播放器/MP3_test/MP3_test.ino: -------------------------------------------------------------------------------- 1 | 2 | #include //软串口头文件名 3 | #include //MP3头文件名 4 | 5 | void setup () { 6 | Serial.begin (9600);//串口波特率,9600 7 | mp3_set_serial(Serial);//定义MP3串口为Arduino串口。 8 | mp3_set_volume(30);//设置音量。 9 | } 10 | 11 | void loop () { 12 | mp3_play (1);//播放第一首。 13 | delay (6000);//播放6秒。 14 | mp3_next ();//播放下一首。 15 | delay (6000);//播放6秒。 16 | mp3_prev ();//上一曲 17 | delay (6000);//播放6秒。 18 | mp3_play (3);//播放第3首。 19 | delay (6000);//播放6秒。 20 | } 21 | -------------------------------------------------------------------------------- /MP3播放器/mp3player_esp8266/mp3player_esp8266.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include //软串口头文件名 4 | #include //MP3头文件名 5 | 6 | const char* ssid = "niehen_pc"; 7 | const char* password = "*"; 8 | const char* mqtt_server = "*"; 9 | 10 | WiFiClient espClient; 11 | PubSubClient client(espClient); 12 | long lastMsg = 0; 13 | char msg[50]; 14 | int value = 0; 15 | String tmpTopic; 16 | String strplayload; 17 | 18 | void setup_wifi() { 19 | delay(10); 20 | // We start by connecting to a WiFi network 21 | // Serial.println(); 22 | // Serial.print("Connecting to "); 23 | // Serial.println(ssid); 24 | 25 | WiFi.begin(ssid, password); 26 | while (WiFi.status() != WL_CONNECTED) { 27 | delay(500); 28 | // Serial.print("."); 29 | } 30 | 31 | randomSeed(micros()); 32 | //Serial.println(WiFi.localIP()); 33 | } 34 | void callback(char* topic, byte* payload, unsigned int length) { 35 | 36 | tmpTopic = String((char *)topic); 37 | payload[length] = '\0'; 38 | strplayload = String((char*)payload); 39 | Serial.println("get the order"); 40 | client.publish("itgzs/mp3player/status", "get older "); 41 | if (strplayload == "off") { // 判断是否是off 关闭指令 42 | mp3_stop (); 43 | 44 | client.publish("itgzs/mp3player/status", "mp3 stop"); 45 | }else { 46 | int isint = 0;// 如果有字母 就为1 全数字就为0 47 | for (int i=0; i< strplayload.length();i++) // 检测接收到的命令里面是否含有 非数字的字符 48 | { 49 | if (!isDigit(strplayload[i])) 50 | { 51 | isint = 1; 52 | break; 53 | } 54 | } 55 | if(isint == 0){ 56 | int older_mp3 = strplayload.toInt() ; // 转换为 int类型 57 | if(older_mp3 >=1 && older_mp3<=20){ 58 | mp3_play (older_mp3); 59 | Serial.println("mp3 running"); 60 | Serial.println(older_mp3); 61 | client.publish("itgzs/mp3player/status", "mp3 is running"); 62 | delay(2000); 63 | } 64 | } 65 | } 66 | } 67 | 68 | 69 | 70 | void reconnect() { 71 | // Loop until we're reconnected 72 | while (!client.connected()) { 73 | Serial.print("Attempting MQTT connection..."); 74 | String clientId = "ESP8266Client-"; 75 | clientId += String(random(0xffff), HEX); 76 | if (client.connect(clientId.c_str())) { 77 | Serial.println("connected"); 78 | 79 | client.publish("itgzs/mp3player/status", "init..."); 80 | // ... and resubscribe 81 | client.subscribe("itgzs/mp3player/older"); 82 | } else { 83 | Serial.print("failed, rc="); 84 | Serial.print(client.state()); 85 | Serial.println(" try again in 5 seconds"); 86 | // Wait 5 seconds before retrying 87 | delay(5000); 88 | } 89 | } 90 | } 91 | 92 | void setup() { 93 | Serial.begin(9600); 94 | setup_wifi(); 95 | mp3_set_serial(Serial);//定义MP3串口为Arduino串口。 96 | 97 | mp3_set_volume(30);//设置音量。 98 | client.setServer(mqtt_server, 1883); 99 | client.setCallback(callback); 100 | 101 | } 102 | 103 | void loop() { 104 | // if (value == 4){ 105 | // client.publish("mp3/status", "music one"); 106 | // mp3_play (1);//播放第一首。 107 | // delay (2000);//播放6秒。 108 | // value = 5; 109 | // } 110 | 111 | if (!client.connected()) { 112 | reconnect(); 113 | } 114 | client.loop(); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /MP3播放器/库文件/DFPlayer-Mini-mp3-master/README.md: -------------------------------------------------------------------------------- 1 | DFPlayer-Mini-mp3 2 | ================= 3 | 4 | Install instructions: 5 | 6 | * Download file 7 | * decompress 8 | * copy inside folder to your Arduino library folder 9 | * restart your Arduino IDE 10 | 11 | 12 | Check the wiki for more information: 13 | http://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299 14 | -------------------------------------------------------------------------------- /MP3播放器/库文件/DFPlayer-Mini-mp3-master/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map for DFPlayer_Mini_Mp3 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | mp3_set_reply KEYWORD2 14 | fill_uint16_bigend KEYWORD2 15 | mp3_set_serial KEYWORD2 16 | get_mp3_checksum KEYWORD2 17 | mp3_fill_checksum KEYWORD2 18 | mp3_play KEYWORD2 19 | mp3_next KEYWORD2 20 | mp3_prev KEYWORD2 21 | mp3_set_volume KEYWORD2 22 | mp3_set_EQ KEYWORD2 23 | mp3_set_device KEYWORD2 24 | mp3_sleep KEYWORD2 25 | mp3_reset KEYWORD2 26 | mp3_pause KEYWORD2 27 | mp3_stop KEYWORD2 28 | mp3_play_mp3 KEYWORD2 29 | mp3_get_state KEYWORD2 30 | mp3_get_volume KEYWORD2 31 | mp3_get_u_sum KEYWORD2 32 | mp3_get_tf_sum KEYWORD2 33 | mp3_get_flash_sum KEYWORD2 34 | mp3_get_tf_current KEYWORD2 35 | mp3_get_u_current KEYWORD2 36 | mp3_get_flash_current KEYWORD2 37 | mp3_single_loop KEYWORD2 38 | mp3_DAC KEYWORD2 39 | mp3_random_play KEYWORD2 40 | 41 | ####################################### 42 | # Constants (LITERAL1) 43 | ####################################### 44 | 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 访问niehen.cn 学习更多嵌入式IOT知识,计算机视觉! 2 | 3 | 4 | ### 更多学习教程 5 | ##### ESP开发学习基础知识 6 | 基础知识包括对esp模块的认识与了解 mqtt协议的了解,arduino IDE运用代码编写等等。 7 | 1. [arduino基础学习](http://niehen.cn/arduino/arduino%e4%bb%8b%e7%bb%8d%e4%b8%8e%e6%95%99%e7%a8%8b/) 8 | 2. [esp系列模块的介绍](http://niehen.cn/esp8266/esp8266%e7%b3%bb%e5%88%97-wifi%e6%a8%a1%e5%9d%97/) 9 | 3. [mqtt协议的介绍与使用](http://niehen.cn/esp8266/mqtt%e5%8d%8f%e8%ae%ae%e4%bb%8b%e7%bb%8d%e4%b8%8e%e5%ba%94%e7%94%a8/) 10 | 4. [利用mqtt esp模块 基于arduino IDE开发方法](http://niehen.cn/esp8266/esp8266-mqtt-%e4%bd%bf%e7%94%a8arduino%e5%bc%80%e5%8f%91%e6%95%99%e7%a8%8b/) 11 | 5. [esp模块的AT指令 刷固件](http://niehen.cn/esp8266/esp8266-at%e6%8c%87%e4%bb%a4%e4%bb%a5%e5%8f%8a%e5%88%b7%e5%9b%ba%e4%bb%b6/) 12 | 6. [esp模块睡眠模式使用](http://niehen.cn/esp8266/esp8266%e6%a8%a1%e5%9d%97%e7%9d%a1%e7%9c%a0%e6%a8%a1%e5%bc%8f/) 13 | 7. [esp8266-01s介绍与使用](http://niehen.cn/esp8266/esp8266-01s%e4%bb%8b%e7%bb%8d/) 14 | 8. [esp8266-12f介绍与使用](http://niehen.cn/esp8266/esp8266-12f%e4%bb%8b%e7%bb%8d%e4%b8%8e%e4%bd%bf%e7%94%a8/) 15 | 9. [NodeMcu介绍与使用](http://niehen.cn/esp8266/nodemcu%e4%bd%bf%e7%94%a8/) 16 | 17 | ##### esp开发IOT应用 18 | 基于esp8266的模块以及其他模块根据实际的应用场景与需求制作的物联网应用 19 | 20 | 1. [基于FRID arduino 继电器 电磁锁开发的FRID门禁系统](http://niehen.cn/arduino/rfid%e6%99%ba%e8%83%bd%e6%8e%a7%e5%88%b6%e9%97%a8%e7%a6%81/) 21 | 2. [esp32-cam获取视频流图像处理](http://niehen.cn/esp8266/esp32-cam-arduino%e5%bc%80%e5%8f%91/) 22 | 4. [基于步进电机 esp8266 mqtt开发的自动窗帘控制](http://niehen.cn/esp8266/%e6%99%ba%e8%83%bd%e6%97%a0%e7%ba%bf%e6%8e%a7%e5%88%b6%e7%aa%97%e5%b8%98/) 23 | 5. [基于DHT11 Esp8266 mqtt获取室内温湿度](http://niehen.cn/esp8266/esp8266%e3%80%81mqtt%e8%8e%b7%e5%8f%96%e6%b8%a9%e6%b9%bf%e5%ba%a6/) 24 | 6. [基于CCS811 esp8266 mqtt 获取室内空气质量](http://niehen.cn/arduino/ccs811%e7%a9%ba%e6%b0%94%e8%b4%a8%e9%87%8f%e6%a3%80%e6%b5%8b/) 25 | 7. [基于红外模块 esp8266 mqtt开发的智能遥控控制](http://niehen.cn/esp8266/%e5%88%a9%e7%94%a8%e7%ba%a2%e5%a4%96%e6%97%a0%e7%ba%bf%e6%8e%a7%e5%88%b6%e7%a9%ba%e8%b0%83/) 26 | 8. [基于ws2812 esp8266 mqtt开发的智能多级照明灯](http://niehen.cn/esp8266/%e6%99%ba%e8%83%bd%e6%97%a0%e7%ba%bf%e5%a4%9a%e7%ba%a7%e6%8e%a7%e5%88%b6%e7%85%a7%e6%98%8e%e7%81%af/) 27 | 9. [基于ws2812 esp8266 mqtt开发的智能多模式氛围灯](http://niehen.cn/esp8266/%e6%99%ba%e8%83%bd%e5%a4%9a%e6%a8%a1%e5%bc%8f%e6%b0%9b%e5%9b%b4%e7%81%af/) 28 | 10. [基于mp3player esp8266 mqtt开发的智能语音播报系统](http://niehen.cn/arduino/mp3%e6%92%ad%e6%94%be%e5%99%a8%e6%a8%a1%e5%9d%97/) 29 | 30 | -------------------------------------------------------------------------------- /libraries/Adafruit_CCS811_Library/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /libraries/Adafruit_CCS811_Library/README.md: -------------------------------------------------------------------------------- 1 | # Adafruit CCS811 Library [![Build Status](https://travis-ci.org/adafruit/Adafruit_CCS811.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit_CCS811) 2 | 3 | 4 | 5 | This is a library for the Adafruit CCS811 gas sensor breakout board: 6 | * https://www.adafruit.com/product/3566 7 | 8 | Check out the links above for our tutorials and wiring diagrams. This chip uses I2C to communicate 9 | 10 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 11 | 12 | Written by Dean Miller for Adafruit Industries. 13 | MIT license, all text above must be included in any redistribution 14 | -------------------------------------------------------------------------------- /libraries/Adafruit_CCS811_Library/examples/CCS811_OLED_Demo/CCS811_OLED_Demo.ino: -------------------------------------------------------------------------------- 1 | /* This demo shows how to display the CCS811 readings on an Adafruit I2C OLED. 2 | * (We used a Feather + OLED FeatherWing) 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include "Adafruit_CCS811.h" 11 | 12 | Adafruit_CCS811 ccs; 13 | Adafruit_SSD1306 display = Adafruit_SSD1306(); 14 | 15 | void setup() { 16 | Serial.begin(115200); 17 | 18 | if(!ccs.begin()){ 19 | Serial.println("Failed to start sensor! Please check your wiring."); 20 | while(1); 21 | } 22 | 23 | // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) 24 | display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) 25 | 26 | // Show image buffer on the display hardware. 27 | // Since the buffer is intialized with an Adafruit splashscreen 28 | // internally, this will display the splashscreen. 29 | display.display(); 30 | delay(500); 31 | 32 | // Clear the buffer. 33 | display.clearDisplay(); 34 | display.display(); 35 | 36 | //calibrate temperature sensor 37 | while(!ccs.available()); 38 | float temp = ccs.calculateTemperature(); 39 | ccs.setTempOffset(temp - 25.0); 40 | 41 | Serial.println("IO test"); 42 | 43 | // text display tests 44 | display.setTextSize(1); 45 | display.setTextColor(WHITE); 46 | } 47 | 48 | 49 | void loop() { 50 | display.setCursor(0,0); 51 | if(ccs.available()){ 52 | display.clearDisplay(); 53 | float temp = ccs.calculateTemperature(); 54 | if(!ccs.readData()){ 55 | display.print("eCO2: "); 56 | Serial.print("eCO2: "); 57 | float eCO2 = ccs.geteCO2(); 58 | display.print(eCO2); 59 | Serial.print(eCO2); 60 | 61 | display.print(" ppm\nTVOC: "); 62 | Serial.print(" ppm, TVOC: "); 63 | float TVOC = ccs.getTVOC(); 64 | display.print(TVOC); 65 | Serial.print(TVOC); 66 | 67 | Serial.print(" ppb Temp:"); 68 | display.print(" ppb\nTemp: "); 69 | Serial.println(temp); 70 | display.println(temp); 71 | display.display(); 72 | } 73 | else{ 74 | Serial.println("ERROR!"); 75 | while(1); 76 | } 77 | } 78 | delay(500); 79 | } 80 | 81 | -------------------------------------------------------------------------------- /libraries/Adafruit_CCS811_Library/examples/CCS811_test/CCS811_test.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the CCS811 air 3 | 4 | This sketch reads the sensor 5 | 6 | Designed specifically to work with the Adafruit CCS811 breakout 7 | ----> http://www.adafruit.com/products/3566 8 | 9 | These sensors use I2C to communicate. The device's I2C address is 0x5A 10 | 11 | Adafruit invests time and resources providing this open source code, 12 | please support Adafruit andopen-source hardware by purchasing products 13 | from Adafruit! 14 | 15 | Written by Dean Miller for Adafruit Industries. 16 | BSD license, all text above must be included in any redistribution 17 | ***************************************************************************/ 18 | 19 | #include "Adafruit_CCS811.h" 20 | 21 | Adafruit_CCS811 ccs; 22 | 23 | void setup() { 24 | Serial.begin(9600); 25 | 26 | Serial.println("CCS811 test"); 27 | 28 | if(!ccs.begin()){ 29 | Serial.println("Failed to start sensor! Please check your wiring."); 30 | while(1); 31 | } 32 | 33 | // Wait for the sensor to be ready 34 | while(!ccs.available()); 35 | } 36 | 37 | void loop() { 38 | if(ccs.available()){ 39 | if(!ccs.readData()){ 40 | Serial.print("CO2: "); 41 | Serial.print(ccs.geteCO2()); 42 | Serial.print("ppm, TVOC: "); 43 | Serial.print(ccs.getTVOC()); 44 | } 45 | else{ 46 | Serial.println("ERROR!"); 47 | while(1); 48 | } 49 | } 50 | delay(500); 51 | } -------------------------------------------------------------------------------- /libraries/Adafruit_CCS811_Library/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit CCS811 Library 2 | version=1.0.2 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=This is a library for the Adafruit CCS811 I2C gas sensor breakout. 6 | paragraph=CCS811 is a gas sensor that can detect a wide range of Volatile Organic Compounds (VOCs) and is intended for indoor air quality monitoring. 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit_CCS811 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/Adafruit_ESP8266/Adafruit_ESP8266.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | An Arduino library for the ESP8266 WiFi-serial bridge 3 | 4 | https://www.adafruit.com/product/2282 5 | 6 | The ESP8266 is a 3.3V device. Safe operation with 5V devices (most 7 | Arduino boards) requires a logic-level shifter for TX and RX signals. 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried and Phil Burgess for Adafruit Industries. 14 | MIT license, all text above must be included in any redistribution. 15 | ------------------------------------------------------------------------*/ 16 | 17 | #ifndef _ADAFRUIT_ESP8266_H_ 18 | #define _ADAFRUIT_ESP8266_H_ 19 | 20 | #include 21 | 22 | #define ESP_RECEIVE_TIMEOUT 1000L 23 | #define ESP_RESET_TIMEOUT 5000L 24 | #define ESP_CONNECT_TIMEOUT 15000L 25 | #define ESP_IPD_TIMEOUT 120000L 26 | 27 | typedef const __FlashStringHelper Fstr; // PROGMEM/flash-resident string 28 | typedef const PROGMEM char Pchr; // Ditto, kindasorta 29 | 30 | #define defaultBootMarker F("ready\r\n") 31 | 32 | // Subclassing Print makes debugging easier -- output en route to 33 | // WiFi module can be duplicated on a second stream (e.g. Serial). 34 | class Adafruit_ESP8266 : public Print { 35 | public: 36 | Adafruit_ESP8266(Stream *s = &Serial, Stream *d = NULL, int8_t r = -1); 37 | boolean hardReset(void), 38 | softReset(void), 39 | find(Fstr *str = NULL, boolean ipd = false), 40 | connectToAP(Fstr *ssid, Fstr *pass), 41 | connectTCP(Fstr *host, int port), 42 | requestURL(Fstr *url), 43 | requestURL(char* url); 44 | int readLine(char *buf, int bufSiz); 45 | void closeAP(void), 46 | closeTCP(void), 47 | debugLoop(void), 48 | setDebug(Stream *d = NULL), 49 | setTimeouts(uint32_t rcv = ESP_RECEIVE_TIMEOUT, 50 | uint32_t rst = ESP_RESET_TIMEOUT, 51 | uint32_t con = ESP_CONNECT_TIMEOUT, 52 | uint32_t ipd = ESP_IPD_TIMEOUT), 53 | setBootMarker(Fstr *s = NULL); 54 | private: 55 | Stream *stream, // -> ESP8266, e.g. SoftwareSerial or Serial1 56 | *debug; // -> host, e.g. Serial 57 | uint32_t receiveTimeout, resetTimeout, connectTimeout, ipdTimeout; 58 | int8_t reset_pin; // -1 if RST not connected 59 | Fstr *host, // Non-NULL when TCP connection open 60 | *bootMarker; // String indicating successful boot 61 | boolean writing; 62 | virtual size_t write(uint8_t); // Because Print subclass 63 | }; 64 | 65 | #endif // _ADAFRUIT_ESP8266_H_ 66 | -------------------------------------------------------------------------------- /libraries/Adafruit_ESP8266/README.md: -------------------------------------------------------------------------------- 1 | Adafruit_ESP8266 2 | ================ 3 | 4 | Example code for ESP8266 chipset 5 | -------------------------------------------------------------------------------- /libraries/Adafruit_ESP8266/examples/webclient/webclient.ino: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | Simple ESP8266 test. Requires SoftwareSerial and an ESP8266 that's been 3 | flashed with recent 'AT' firmware operating at 9600 baud. Only tested 4 | w/Adafruit-programmed modules: https://www.adafruit.com/product/2282 5 | 6 | The ESP8266 is a 3.3V device. Safe operation with 5V devices (most 7 | Arduino boards) requires a logic-level shifter for TX and RX signals. 8 | ------------------------------------------------------------------------*/ 9 | 10 | #include 11 | #include 12 | 13 | #define ESP_RX 2 14 | #define ESP_TX 3 15 | #define ESP_RST 4 16 | SoftwareSerial softser(ESP_RX, ESP_TX); 17 | 18 | // Must declare output stream before Adafruit_ESP8266 constructor; can be 19 | // a SoftwareSerial stream, or Serial/Serial1/etc. for UART. 20 | Adafruit_ESP8266 wifi(&softser, &Serial, ESP_RST); 21 | // Must call begin() on the stream(s) before using Adafruit_ESP8266 object. 22 | 23 | #define ESP_SSID "SSIDNAME" // Your network name here 24 | #define ESP_PASS "PASSWORD" // Your network password here 25 | 26 | #define HOST "www.adafruit.com" // Host to contact 27 | #define PAGE "/testwifi/index.html" // Web page to request 28 | #define PORT 80 // 80 = HTTP default port 29 | 30 | #define LED_PIN 13 31 | 32 | void setup() { 33 | char buffer[50]; 34 | 35 | // Flash LED on power-up 36 | pinMode(LED_PIN, OUTPUT); 37 | for(uint8_t i=0; i<3; i++) { 38 | digitalWrite(13, HIGH); delay(50); 39 | digitalWrite(13, LOW); delay(100); 40 | } 41 | 42 | // This might work with other firmware versions (no guarantees) 43 | // by providing a string to ID the tail end of the boot message: 44 | 45 | // comment/replace this if you are using something other than v 0.9.2.4! 46 | wifi.setBootMarker(F("Version:0.9.2.4]\r\n\r\nready")); 47 | 48 | softser.begin(9600); // Soft serial connection to ESP8266 49 | Serial.begin(57600); while(!Serial); // UART serial debug 50 | 51 | Serial.println(F("Adafruit ESP8266 Demo")); 52 | 53 | // Test if module is ready 54 | Serial.print(F("Hard reset...")); 55 | if(!wifi.hardReset()) { 56 | Serial.println(F("no response from module.")); 57 | for(;;); 58 | } 59 | Serial.println(F("OK.")); 60 | 61 | Serial.print(F("Soft reset...")); 62 | if(!wifi.softReset()) { 63 | Serial.println(F("no response from module.")); 64 | for(;;); 65 | } 66 | Serial.println(F("OK.")); 67 | 68 | Serial.print(F("Checking firmware version...")); 69 | wifi.println(F("AT+GMR")); 70 | if(wifi.readLine(buffer, sizeof(buffer))) { 71 | Serial.println(buffer); 72 | wifi.find(); // Discard the 'OK' that follows 73 | } else { 74 | Serial.println(F("error")); 75 | } 76 | 77 | Serial.print(F("Connecting to WiFi...")); 78 | if(wifi.connectToAP(F(ESP_SSID), F(ESP_PASS))) { 79 | 80 | // IP addr check isn't part of library yet, but 81 | // we can manually request and place in a string. 82 | Serial.print(F("OK\nChecking IP addr...")); 83 | wifi.println(F("AT+CIFSR")); 84 | if(wifi.readLine(buffer, sizeof(buffer))) { 85 | Serial.println(buffer); 86 | wifi.find(); // Discard the 'OK' that follows 87 | 88 | Serial.print(F("Connecting to host...")); 89 | if(wifi.connectTCP(F(HOST), PORT)) { 90 | Serial.print(F("OK\nRequesting page...")); 91 | if(wifi.requestURL(F(PAGE))) { 92 | Serial.println("OK\nSearching for string..."); 93 | // Search for a phrase in the open stream. 94 | // Must be a flash-resident string (F()). 95 | if(wifi.find(F("working"), true)) { 96 | Serial.println(F("found!")); 97 | } else { 98 | Serial.println(F("not found.")); 99 | } 100 | } else { // URL request failed 101 | Serial.println(F("error")); 102 | } 103 | wifi.closeTCP(); 104 | } else { // TCP connect failed 105 | Serial.println(F("D'oh!")); 106 | } 107 | } else { // IP addr check failed 108 | Serial.println(F("error")); 109 | } 110 | wifi.closeAP(); 111 | } else { // WiFi connection failed 112 | Serial.println(F("FAIL")); 113 | } 114 | } 115 | 116 | void loop() { 117 | } 118 | -------------------------------------------------------------------------------- /libraries/Adafruit_ESP8266/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit ESP8266 2 | version=1.0.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Example code for ESP8266 chipset 6 | paragraph=Example code for ESP8266 chipset 7 | category=Communication 8 | url=https://github.com/adafruit/Adafruit_ESP8266 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/Adafruit_NeoPixel/README.md: -------------------------------------------------------------------------------- 1 | # Adafruit NeoPixel Library [![Build Status](https://travis-ci.org/adafruit/Adafruit_NeoPixel.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit_NeoPixel) 2 | 3 | Arduino library for controlling single-wire-based LED pixels and strip such as the [Adafruit 60 LED/meter Digital LED strip][strip], the [Adafruit FLORA RGB Smart Pixel][flora], the [Adafruit Breadboard-friendly RGB Smart Pixel][pixel], the [Adafruit NeoPixel Stick][stick], and the [Adafruit NeoPixel Shield][shield]. 4 | 5 | After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch. 6 | 7 | Compatibility notes: Port A is not supported on any AVR processors at this time 8 | 9 | [flora]: http://adafruit.com/products/1060 10 | [strip]: http://adafruit.com/products/1138 11 | [pixel]: http://adafruit.com/products/1312 12 | [stick]: http://adafruit.com/products/1426 13 | [shield]: http://adafruit.com/products/1430 14 | -------------------------------------------------------------------------------- /libraries/Adafruit_NeoPixel/esp8266.c: -------------------------------------------------------------------------------- 1 | // This is a mash-up of the Due show() code + insights from Michael Miller's 2 | // ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus 3 | // Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution. 4 | 5 | #if defined(ESP8266) || defined(ESP32) 6 | 7 | #include 8 | #ifdef ESP8266 9 | #include 10 | #endif 11 | 12 | static uint32_t _getCycleCount(void) __attribute__((always_inline)); 13 | static inline uint32_t _getCycleCount(void) { 14 | uint32_t ccount; 15 | __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); 16 | return ccount; 17 | } 18 | 19 | #ifdef ESP8266 20 | void ICACHE_RAM_ATTR espShow( 21 | uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { 22 | #else 23 | void espShow( 24 | uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { 25 | #endif 26 | 27 | #define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us 28 | #define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us 29 | #define CYCLES_800 (F_CPU / 800000) // 1.25us per bit 30 | #define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS 31 | #define CYCLES_400_T1H (F_CPU / 833333) // 1.2us 32 | #define CYCLES_400 (F_CPU / 400000) // 2.5us per bit 33 | 34 | uint8_t *p, *end, pix, mask; 35 | uint32_t t, time0, time1, period, c, startTime, pinMask; 36 | 37 | pinMask = _BV(pin); 38 | p = pixels; 39 | end = p + numBytes; 40 | pix = *p++; 41 | mask = 0x80; 42 | startTime = 0; 43 | 44 | #ifdef NEO_KHZ400 45 | if(is800KHz) { 46 | #endif 47 | time0 = CYCLES_800_T0H; 48 | time1 = CYCLES_800_T1H; 49 | period = CYCLES_800; 50 | #ifdef NEO_KHZ400 51 | } else { // 400 KHz bitstream 52 | time0 = CYCLES_400_T0H; 53 | time1 = CYCLES_400_T1H; 54 | period = CYCLES_400; 55 | } 56 | #endif 57 | 58 | for(t = time0;; t = time0) { 59 | if(pix & mask) t = time1; // Bit high duration 60 | while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start 61 | #ifdef ESP8266 62 | GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high 63 | #else 64 | gpio_set_level(pin, HIGH); 65 | #endif 66 | startTime = c; // Save start time 67 | while(((c = _getCycleCount()) - startTime) < t); // Wait high duration 68 | #ifdef ESP8266 69 | GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low 70 | #else 71 | gpio_set_level(pin, LOW); 72 | #endif 73 | if(!(mask >>= 1)) { // Next bit/byte 74 | if(p >= end) break; 75 | pix = *p++; 76 | mask = 0x80; 77 | } 78 | } 79 | while((_getCycleCount() - startTime) < period); // Wait for last bit 80 | } 81 | 82 | #endif // ESP8266 83 | -------------------------------------------------------------------------------- /libraries/Adafruit_NeoPixel/examples/RGBLED/RGBLED.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | // Which pin on the ESP8266 is connected to the NeoPixels? 6 | #define PIN 2 7 | 8 | // How many NeoPixels are attached to the ESP8266? 9 | #define NUMPIXELS 16 10 | 11 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 12 | 13 | int delayval = 500; // delay for half a second 14 | 15 | void setup() { 16 | // put your setup code here, to run once: 17 | pixels.begin(); // This initializes the NeoPixel library. 18 | } 19 | 20 | void loop() { 21 | // put your main code here, to run repeatedly: 22 | for(int i=0;i_txCount = 0; 11 | this->_rxHead = this->_rxTail = 0; 12 | this->_flushed = 0; 13 | BLESerial::_instance = this; 14 | 15 | addAttribute(this->_uartService); 16 | addAttribute(this->_uartNameDescriptor); 17 | setAdvertisedServiceUuid(this->_uartService.uuid()); 18 | addAttribute(this->_rxCharacteristic); 19 | addAttribute(this->_rxNameDescriptor); 20 | this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received); 21 | addAttribute(this->_txCharacteristic); 22 | addAttribute(this->_txNameDescriptor); 23 | } 24 | 25 | void BLESerial::begin(...) { 26 | BLEPeripheral::begin(); 27 | #ifdef BLE_SERIAL_DEBUG 28 | Serial.println(F("BLESerial::begin()")); 29 | #endif 30 | } 31 | 32 | void BLESerial::poll() { 33 | if (millis() < this->_flushed + 100) { 34 | BLEPeripheral::poll(); 35 | } else { 36 | flush(); 37 | } 38 | } 39 | 40 | void BLESerial::end() { 41 | this->_rxCharacteristic.setEventHandler(BLEWritten, NULL); 42 | this->_rxHead = this->_rxTail = 0; 43 | flush(); 44 | BLEPeripheral::disconnect(); 45 | } 46 | 47 | int BLESerial::available(void) { 48 | BLEPeripheral::poll(); 49 | int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer); 50 | #ifdef BLE_SERIAL_DEBUG 51 | Serial.print(F("BLESerial::available() = ")); 52 | Serial.println(retval); 53 | #endif 54 | return retval; 55 | } 56 | 57 | int BLESerial::peek(void) { 58 | BLEPeripheral::poll(); 59 | if (this->_rxTail == this->_rxHead) return -1; 60 | uint8_t byte = this->_rxBuffer[this->_rxTail]; 61 | #ifdef BLE_SERIAL_DEBUG 62 | Serial.print(F("BLESerial::peek() = ")); 63 | Serial.print((char) byte); 64 | Serial.print(F(" 0x")); 65 | Serial.println(byte, HEX); 66 | #endif 67 | return byte; 68 | } 69 | 70 | int BLESerial::read(void) { 71 | BLEPeripheral::poll(); 72 | if (this->_rxTail == this->_rxHead) return -1; 73 | this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer); 74 | uint8_t byte = this->_rxBuffer[this->_rxTail]; 75 | #ifdef BLE_SERIAL_DEBUG 76 | Serial.print(F("BLESerial::read() = ")); 77 | Serial.print((char) byte); 78 | Serial.print(F(" 0x")); 79 | Serial.println(byte, HEX); 80 | #endif 81 | return byte; 82 | } 83 | 84 | void BLESerial::flush(void) { 85 | if (this->_txCount == 0) return; 86 | this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount); 87 | this->_flushed = millis(); 88 | this->_txCount = 0; 89 | BLEPeripheral::poll(); 90 | #ifdef BLE_SERIAL_DEBUG 91 | Serial.println(F("BLESerial::flush()")); 92 | #endif 93 | } 94 | 95 | size_t BLESerial::write(uint8_t byte) { 96 | BLEPeripheral::poll(); 97 | if (this->_txCharacteristic.subscribed() == false) return 0; 98 | this->_txBuffer[this->_txCount++] = byte; 99 | if (this->_txCount == sizeof(this->_txBuffer)) flush(); 100 | #ifdef BLE_SERIAL_DEBUG 101 | Serial.print(F("BLESerial::write(")); 102 | Serial.print((char) byte); 103 | Serial.print(F(" 0x")); 104 | Serial.print(byte, HEX); 105 | Serial.println(F(") = 1")); 106 | #endif 107 | return 1; 108 | } 109 | 110 | BLESerial::operator bool() { 111 | bool retval = BLEPeripheral::connected(); 112 | #ifdef BLE_SERIAL_DEBUG 113 | Serial.print(F("BLESerial::operator bool() = ")); 114 | Serial.println(retval); 115 | #endif 116 | return retval; 117 | } 118 | 119 | void BLESerial::_received(const uint8_t* data, size_t size) { 120 | for (int i = 0; i < size; i++) { 121 | this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer); 122 | this->_rxBuffer[this->_rxHead] = data[i]; 123 | } 124 | #ifdef BLE_SERIAL_DEBUG 125 | Serial.print(F("BLESerial::received(")); 126 | for (int i = 0; i < size; i++) Serial.print((char) data[i]); 127 | Serial.println(F(")")); 128 | #endif 129 | } 130 | 131 | void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) { 132 | BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength()); 133 | } 134 | -------------------------------------------------------------------------------- /libraries/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h: -------------------------------------------------------------------------------- 1 | #ifndef _BLE_SERIAL_H_ 2 | #define _BLE_SERIAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class BLESerial : public BLEPeripheral, public Stream 8 | { 9 | public: 10 | BLESerial(unsigned char req, unsigned char rdy, unsigned char rst); 11 | 12 | void begin(...); 13 | void poll(); 14 | void end(); 15 | 16 | virtual int available(void); 17 | virtual int peek(void); 18 | virtual int read(void); 19 | virtual void flush(void); 20 | virtual size_t write(uint8_t byte); 21 | using Print::write; 22 | virtual operator bool(); 23 | 24 | private: 25 | unsigned long _flushed; 26 | static BLESerial* _instance; 27 | 28 | size_t _rxHead; 29 | size_t _rxTail; 30 | size_t _rxCount() const; 31 | uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; 32 | size_t _txCount; 33 | uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; 34 | 35 | BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"); 36 | BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART"); 37 | BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); 38 | BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)"); 39 | BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); 40 | BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)"); 41 | 42 | void _received(const uint8_t* data, size_t size); 43 | static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic); 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libraries/Adafruit_NeoPixel/examples/simple/simple.ino: -------------------------------------------------------------------------------- 1 | // NeoPixel Ring simple sketch (c) 2013 Shae Erisson 2 | // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library 3 | 4 | #include 5 | #ifdef __AVR__ 6 | #include 7 | #endif 8 | 9 | // Which pin on the Arduino is connected to the NeoPixels? 10 | // On a Trinket or Gemma we suggest changing this to 1 11 | #define PIN 6 12 | 13 | // How many NeoPixels are attached to the Arduino? 14 | #define NUMPIXELS 16 15 | 16 | // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. 17 | // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest 18 | // example for more information on possible values. 19 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 20 | 21 | int delayval = 500; // delay for half a second 22 | 23 | void setup() { 24 | // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket 25 | #if defined (__AVR_ATtiny85__) 26 | if (F_CPU == 16000000) clock_prescale_set(clock_div_1); 27 | #endif 28 | // End of trinket special code 29 | 30 | pixels.begin(); // This initializes the NeoPixel library. 31 | } 32 | 33 | void loop() { 34 | 35 | // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. 36 | 37 | for(int i=0;i 2 | #ifdef __AVR__ 3 | #include 4 | #endif 5 | 6 | #define PIN 6 7 | 8 | // Parameter 1 = number of pixels in strip 9 | // Parameter 2 = Arduino pin number (most are valid) 10 | // Parameter 3 = pixel type flags, add together as needed: 11 | // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 12 | // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) 13 | // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) 14 | // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) 15 | // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) 16 | Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); 17 | 18 | // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across 19 | // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input 20 | // and minimize distance between Arduino and first pixel. Avoid connecting 21 | // on a live circuit...if you must, connect GND first. 22 | 23 | void setup() { 24 | // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket 25 | #if defined (__AVR_ATtiny85__) 26 | if (F_CPU == 16000000) clock_prescale_set(clock_div_1); 27 | #endif 28 | // End of trinket special code 29 | 30 | 31 | strip.begin(); 32 | strip.show(); // Initialize all pixels to 'off' 33 | } 34 | 35 | void loop() { 36 | // Some example procedures showing how to display to the pixels: 37 | colorWipe(strip.Color(255, 0, 0), 50); // Red 38 | colorWipe(strip.Color(0, 255, 0), 50); // Green 39 | colorWipe(strip.Color(0, 0, 255), 50); // Blue 40 | //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW 41 | // Send a theater pixel chase in... 42 | theaterChase(strip.Color(127, 127, 127), 50); // White 43 | theaterChase(strip.Color(127, 0, 0), 50); // Red 44 | theaterChase(strip.Color(0, 0, 127), 50); // Blue 45 | 46 | rainbow(20); 47 | rainbowCycle(20); 48 | theaterChaseRainbow(50); 49 | } 50 | 51 | // Fill the dots one after the other with a color 52 | void colorWipe(uint32_t c, uint8_t wait) { 53 | for(uint16_t i=0; i 5 | sentence=Arduino library for controlling single-wire-based LED pixels and strip. 6 | paragraph=Arduino library for controlling single-wire-based LED pixels and strip. 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit_NeoPixel 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/DHT_sensor_library/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidlines 2 | 3 | This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/adafruit/DHT-sensor-library/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community. 4 | 5 | The following are some guidelines to observe when creating issues or PRs: 6 | 7 | - Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas 8 | 9 | - [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets 10 | 11 | - Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile: 12 | 13 | - Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library 14 | -------------------------------------------------------------------------------- /libraries/DHT_sensor_library/DHT.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file DHT.h 3 | * 4 | * This is a library for DHT series of low cost temperature/humidity sensors. 5 | * 6 | * You must have Adafruit Unified Sensor Library library installed to use this class. 7 | * 8 | * Adafruit invests time and resources providing this open source code, 9 | * please support Adafruit andopen-source hardware by purchasing products 10 | * from Adafruit! 11 | * 12 | * Written by Adafruit Industries. 13 | * 14 | * MIT license, all text above must be included in any redistribution 15 | */ 16 | 17 | #ifndef DHT_H 18 | #define DHT_H 19 | 20 | #include "Arduino.h" 21 | 22 | /* Uncomment to enable printing out nice debug messages. */ 23 | //#define DHT_DEBUG 24 | 25 | 26 | #define DEBUG_PRINTER Serial /**< Define where debug output will be printed. */ 27 | 28 | /* Setup debug printing macros. */ 29 | #ifdef DHT_DEBUG 30 | #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); } 31 | #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); } 32 | #else 33 | #define DEBUG_PRINT(...) {} /**< Debug Print Placeholder if Debug is disabled */ 34 | #define DEBUG_PRINTLN(...) {} /**< Debug Print Line Placeholder if Debug is disabled */ 35 | #endif 36 | 37 | /* Define types of sensors. */ 38 | #define DHT11 11 /**< DHT TYPE 11 */ 39 | #define DHT12 12 /**< DHY TYPE 12 */ 40 | #define DHT22 22 /**< DHT TYPE 22 */ 41 | #define DHT21 21 /**< DHT TYPE 21 */ 42 | #define AM2301 21 /**< AM2301 */ 43 | 44 | /*! 45 | * @brief Class that stores state and functions for DHT 46 | */ 47 | class DHT { 48 | public: 49 | DHT(uint8_t pin, uint8_t type, uint8_t count=6); 50 | void begin(uint8_t usec=55); 51 | float readTemperature(bool S=false, bool force=false); 52 | float convertCtoF(float); 53 | float convertFtoC(float); 54 | float computeHeatIndex(bool isFahrenheit=true); 55 | float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); 56 | float readHumidity(bool force=false); 57 | bool read(bool force=false); 58 | 59 | private: 60 | uint8_t data[5]; 61 | uint8_t _pin, _type; 62 | #ifdef __AVR 63 | // Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask 64 | // for the digital pin connected to the DHT. Other platforms will use digitalRead. 65 | uint8_t _bit, _port; 66 | #endif 67 | uint32_t _lastreadtime, _maxcycles; 68 | bool _lastresult; 69 | uint8_t pullTime; // Time (in usec) to pull up data line before reading 70 | 71 | uint32_t expectPulse(bool level); 72 | 73 | }; 74 | 75 | /*! 76 | * @brief Class that defines Interrupt Lock Avaiability 77 | */ 78 | class InterruptLock { 79 | public: 80 | InterruptLock() { 81 | #if !defined(ARDUINO_ARCH_NRF52) 82 | noInterrupts(); 83 | #endif 84 | } 85 | ~InterruptLock() { 86 | #if !defined(ARDUINO_ARCH_NRF52) 87 | interrupts(); 88 | #endif 89 | } 90 | }; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /libraries/DHT_sensor_library/DHT_U.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file DHT_U.h 3 | * 4 | * DHT Temperature & Humidity Unified Sensor Library 5 | * 6 | * Adafruit invests time and resources providing this open source code, 7 | * please support Adafruit andopen-source hardware by purchasing products 8 | * from Adafruit! 9 | * 10 | * Written by Tony DiCola (Adafruit Industries) 2014. 11 | * 12 | * MIT license, all text above must be included in any redistribution 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to 16 | * deal in the Software without restriction, including without limitation the 17 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 18 | * sell copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 30 | * IN THE SOFTWARE. 31 | */ 32 | 33 | #ifndef DHT_U_H 34 | #define DHT_U_H 35 | 36 | #include 37 | #include 38 | 39 | #define DHT_SENSOR_VERSION 1 /**< Sensor Version */ 40 | 41 | /*! 42 | * @brief Class that stores state and functions for interacting with 43 | * DHT_Unified. 44 | */ 45 | class DHT_Unified { 46 | public: 47 | DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6, 48 | int32_t tempSensorId = -1, int32_t humiditySensorId = -1); 49 | void begin(); 50 | 51 | /*! 52 | * @brief Class that stores state and functions about Temperature 53 | */ 54 | class Temperature : public Adafruit_Sensor { 55 | public: 56 | Temperature(DHT_Unified *parent, int32_t id); 57 | bool getEvent(sensors_event_t *event); 58 | void getSensor(sensor_t *sensor); 59 | 60 | private: 61 | DHT_Unified *_parent; 62 | int32_t _id; 63 | }; 64 | 65 | /*! 66 | * @brief Class that stores state and functions about Humidity 67 | */ 68 | class Humidity : public Adafruit_Sensor { 69 | public: 70 | Humidity(DHT_Unified *parent, int32_t id); 71 | bool getEvent(sensors_event_t *event); 72 | void getSensor(sensor_t *sensor); 73 | 74 | private: 75 | DHT_Unified *_parent; 76 | int32_t _id; 77 | }; 78 | 79 | /*! 80 | * @brief Returns temperature stored in _temp 81 | * @return Temperature value 82 | */ 83 | Temperature temperature() { return _temp; } 84 | 85 | /*! 86 | * @brief Returns humidity stored in _humidity 87 | * @return Humidity value 88 | */ 89 | Humidity humidity() { return _humidity; } 90 | 91 | private: 92 | DHT _dht; 93 | uint8_t _type; 94 | Temperature _temp; 95 | Humidity _humidity; 96 | 97 | void setName(sensor_t *sensor); 98 | void setMinDelay(sensor_t *sensor); 99 | }; 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /libraries/DHT_sensor_library/examples/DHT_Unified_Sensor/DHT_Unified_Sensor.ino: -------------------------------------------------------------------------------- 1 | // DHT Temperature & Humidity Sensor 2 | // Unified Sensor Library Example 3 | // Written by Tony DiCola for Adafruit Industries 4 | // Released under an MIT license. 5 | 6 | // REQUIRES the following Arduino libraries: 7 | // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library 8 | // - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define DHTPIN 2 // Digital pin connected to the DHT sensor 15 | // Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- 16 | // Pin 15 can work but DHT must be disconnected during program upload. 17 | 18 | // Uncomment the type of sensor in use: 19 | //#define DHTTYPE DHT11 // DHT 11 20 | #define DHTTYPE DHT22 // DHT 22 (AM2302) 21 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 22 | 23 | // See guide for details on sensor wiring and usage: 24 | // https://learn.adafruit.com/dht/overview 25 | 26 | DHT_Unified dht(DHTPIN, DHTTYPE); 27 | 28 | uint32_t delayMS; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | // Initialize device. 33 | dht.begin(); 34 | Serial.println(F("DHTxx Unified Sensor Example")); 35 | // Print temperature sensor details. 36 | sensor_t sensor; 37 | dht.temperature().getSensor(&sensor); 38 | Serial.println(F("------------------------------------")); 39 | Serial.println(F("Temperature Sensor")); 40 | Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); 41 | Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); 42 | Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); 43 | Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C")); 44 | Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C")); 45 | Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C")); 46 | Serial.println(F("------------------------------------")); 47 | // Print humidity sensor details. 48 | dht.humidity().getSensor(&sensor); 49 | Serial.println(F("Humidity Sensor")); 50 | Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); 51 | Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); 52 | Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); 53 | Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%")); 54 | Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%")); 55 | Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%")); 56 | Serial.println(F("------------------------------------")); 57 | // Set delay between sensor readings based on sensor details. 58 | delayMS = sensor.min_delay / 1000; 59 | } 60 | 61 | void loop() { 62 | // Delay between measurements. 63 | delay(delayMS); 64 | // Get temperature event and print its value. 65 | sensors_event_t event; 66 | dht.temperature().getEvent(&event); 67 | if (isnan(event.temperature)) { 68 | Serial.println(F("Error reading temperature!")); 69 | } 70 | else { 71 | Serial.print(F("Temperature: ")); 72 | Serial.print(event.temperature); 73 | Serial.println(F("°C")); 74 | } 75 | // Get humidity event and print its value. 76 | dht.humidity().getEvent(&event); 77 | if (isnan(event.relative_humidity)) { 78 | Serial.println(F("Error reading humidity!")); 79 | } 80 | else { 81 | Serial.print(F("Humidity: ")); 82 | Serial.print(event.relative_humidity); 83 | Serial.println(F("%")); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /libraries/DHT_sensor_library/examples/DHTtester/DHTtester.ino: -------------------------------------------------------------------------------- 1 | // Example testing sketch for various DHT humidity/temperature sensors 2 | // Written by ladyada, public domain 3 | 4 | // REQUIRES the following Arduino libraries: 5 | // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library 6 | // - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor 7 | 8 | #include "DHT.h" 9 | 10 | #define DHTPIN 2 // Digital pin connected to the DHT sensor 11 | // Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- 12 | // Pin 15 can work but DHT must be disconnected during program upload. 13 | 14 | // Uncomment whatever type you're using! 15 | //#define DHTTYPE DHT11 // DHT 11 16 | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 17 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 18 | 19 | // Connect pin 1 (on the left) of the sensor to +5V 20 | // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 21 | // to 3.3V instead of 5V! 22 | // Connect pin 2 of the sensor to whatever your DHTPIN is 23 | // Connect pin 4 (on the right) of the sensor to GROUND 24 | // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 25 | 26 | // Initialize DHT sensor. 27 | // Note that older versions of this library took an optional third parameter to 28 | // tweak the timings for faster processors. This parameter is no longer needed 29 | // as the current DHT reading algorithm adjusts itself to work on faster procs. 30 | DHT dht(DHTPIN, DHTTYPE); 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | Serial.println(F("DHTxx test!")); 35 | 36 | dht.begin(); 37 | } 38 | 39 | void loop() { 40 | // Wait a few seconds between measurements. 41 | delay(2000); 42 | 43 | // Reading temperature or humidity takes about 250 milliseconds! 44 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 45 | float h = dht.readHumidity(); 46 | // Read temperature as Celsius (the default) 47 | float t = dht.readTemperature(); 48 | // Read temperature as Fahrenheit (isFahrenheit = true) 49 | float f = dht.readTemperature(true); 50 | 51 | // Check if any reads failed and exit early (to try again). 52 | if (isnan(h) || isnan(t) || isnan(f)) { 53 | Serial.println(F("Failed to read from DHT sensor!")); 54 | return; 55 | } 56 | 57 | // Compute heat index in Fahrenheit (the default) 58 | float hif = dht.computeHeatIndex(f, h); 59 | // Compute heat index in Celsius (isFahreheit = false) 60 | float hic = dht.computeHeatIndex(t, h, false); 61 | 62 | Serial.print(F("Humidity: ")); 63 | Serial.print(h); 64 | Serial.print(F("% Temperature: ")); 65 | Serial.print(t); 66 | Serial.print(F("°C ")); 67 | Serial.print(f); 68 | Serial.print(F("°F Heat index: ")); 69 | Serial.print(hic); 70 | Serial.print(F("°C ")); 71 | Serial.print(hif); 72 | Serial.println(F("°F")); 73 | } 74 | -------------------------------------------------------------------------------- /libraries/DHT_sensor_library/keywords.txt: -------------------------------------------------------------------------------- 1 | ########################################### 2 | # Syntax Coloring Map For DHT-sensor-library 3 | ########################################### 4 | 5 | ########################################### 6 | # Datatypes (KEYWORD1) 7 | ########################################### 8 | 9 | DHT KEYWORD1 10 | 11 | ########################################### 12 | # Methods and Functions (KEYWORD2) 13 | ########################################### 14 | 15 | begin KEYWORD2 16 | readTemperature KEYWORD2 17 | convertCtoF KEYWORD2 18 | convertFtoC KEYWORD2 19 | computeHeatIndex KEYWORD2 20 | readHumidity KEYWORD2 21 | read KEYWORD2 22 | 23 | -------------------------------------------------------------------------------- /libraries/DHT_sensor_library/library.properties: -------------------------------------------------------------------------------- 1 | name=DHT sensor library 2 | version=1.3.8 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors 6 | paragraph=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors 7 | category=Sensors 8 | url=https://github.com/adafruit/DHT-sensor-library 9 | architectures=* 10 | depends=Adafruit Unified Sensor 11 | -------------------------------------------------------------------------------- /libraries/IRremote/Contributing.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidlines 2 | 3 | This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/z3t0/Arduino-IRremote/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community. 4 | 5 | The following are some guidelines to observe when creating issues or PRs: 6 | - Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas 7 | - [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets 8 | - Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile: 9 | - Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library 10 | 11 | If there is any need to contact me then you can find my email on the README, I do not mind responding to emails but it would be in your own interests to create issues if you need help with the library as responses would be from a larger community with greater knowledge! -------------------------------------------------------------------------------- /libraries/IRremote/Contributors.md: -------------------------------------------------------------------------------- 1 | ## Contributors 2 | These are the active contributors of this project that you may contact if there is anything you need help with or if you have suggestions. 3 | 4 | - [z3t0](https://github.com/z3t0) : Active Contributor and currently also the main contributor. 5 | * Email: zetoslab@gmail.com 6 | - [shirriff](https://github.com/shirriff) : An amazing person who worked to create this awesome library and provide unending support 7 | - [AnalysIR](https:/github.com/AnalysIR): Active contributor and is amazing with providing support! 8 | - [Informatic](https://github.com/Informatic) : Active contributor 9 | - [fmeschia](https://github.com/fmeschia) : Active contributor 10 | - [PaulStoffregen](https://github.com/paulstroffregen) : Active contributor 11 | - [crash7](https://github.com/crash7) : Active contributor 12 | - [Neco777](https://github.com/neco777) : Active contributor 13 | - [Lauszus](https://github.com/lauszus) : Active contributor 14 | - [csBlueChip](https://github.com/csbluechip) : Active contributor, who contributed major and vital changes to the code base. 15 | - [Sebazzz](https://github.com/sebazz): Contributor 16 | - [lumbric](https://github.com/lumbric): Contributor 17 | - [ElectricRCAircraftGuy](https://github.com/electricrcaircraftguy): Active Contributor 18 | - [philipphenkel](https://github.com/philipphenkel): Active Contributor 19 | - [MCUdude](https://github.com/MCUdude): Contributor 20 | - [marcmerlin](https://github.com/marcmerlin): Contributor (ESP32 port) 21 | - [bengtmartensson](https://github.com/bengtmartensson): Active Contributor 22 | - [MrBryonMiller](https://github.com/MrBryonMiller): Contributor 23 | 24 | Note: This list is being updated constantly so please let [z3t0](https://github.com/z3t0) know if you have been missed. 25 | -------------------------------------------------------------------------------- /libraries/IRremote/IRremoteInt.h: -------------------------------------------------------------------------------- 1 | //****************************************************************************** 2 | // IRremote 3 | // Version 2.0.1 June, 2015 4 | // Copyright 2009 Ken Shirriff 5 | // For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html 6 | // 7 | // Modified by Paul Stoffregen to support other boards and timers 8 | // 9 | // Interrupt code based on NECIRrcv by Joe Knapp 10 | // http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 11 | // Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ 12 | // 13 | // JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) 14 | // Whynter A/C ARC-110WD added by Francesco Meschia 15 | //****************************************************************************** 16 | 17 | #ifndef IRremoteint_h 18 | #define IRremoteint_h 19 | 20 | //------------------------------------------------------------------------------ 21 | // Include the right Arduino header 22 | // 23 | #if defined(ARDUINO) && (ARDUINO >= 100) 24 | # include 25 | #else 26 | # if !defined(IRPRONTO) 27 | # include 28 | # endif 29 | #endif 30 | 31 | //------------------------------------------------------------------------------ 32 | // This handles definition and access to global variables 33 | // 34 | #ifdef IR_GLOBAL 35 | # define EXTERN 36 | #else 37 | # define EXTERN extern 38 | #endif 39 | 40 | //------------------------------------------------------------------------------ 41 | // Information for the Interrupt Service Routine 42 | // 43 | #define RAWBUF 101 // Maximum length of raw duration buffer 44 | 45 | typedef 46 | struct { 47 | // The fields are ordered to reduce memory over caused by struct-padding 48 | uint8_t rcvstate; // State Machine state 49 | uint8_t recvpin; // Pin connected to IR data from detector 50 | uint8_t blinkpin; 51 | uint8_t blinkflag; // true -> enable blinking of pin on IR processing 52 | uint8_t rawlen; // counter of entries in rawbuf 53 | unsigned int timer; // State timer, counts 50uS ticks. 54 | unsigned int rawbuf[RAWBUF]; // raw data 55 | uint8_t overflow; // Raw buffer overflow occurred 56 | } 57 | irparams_t; 58 | 59 | // ISR State-Machine : Receiver States 60 | #define STATE_IDLE 2 61 | #define STATE_MARK 3 62 | #define STATE_SPACE 4 63 | #define STATE_STOP 5 64 | #define STATE_OVERFLOW 6 65 | 66 | // Allow all parts of the code access to the ISR data 67 | // NB. The data can be changed by the ISR at any time, even mid-function 68 | // Therefore we declare it as "volatile" to stop the compiler/CPU caching it 69 | EXTERN volatile irparams_t irparams; 70 | 71 | //------------------------------------------------------------------------------ 72 | // Defines for setting and clearing register bits 73 | // 74 | #ifndef cbi 75 | # define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 76 | #endif 77 | 78 | #ifndef sbi 79 | # define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 80 | #endif 81 | 82 | //------------------------------------------------------------------------------ 83 | // Pulse parms are ((X*50)-100) for the Mark and ((X*50)+100) for the Space. 84 | // First MARK is the one after the long gap 85 | // Pulse parameters in uSec 86 | // 87 | 88 | // Due to sensor lag, when received, Marks tend to be 100us too long and 89 | // Spaces tend to be 100us too short 90 | #define MARK_EXCESS 100 91 | 92 | // Upper and Lower percentage tolerances in measurements 93 | #define TOLERANCE 25 94 | #define LTOL (1.0 - (TOLERANCE/100.)) 95 | #define UTOL (1.0 + (TOLERANCE/100.)) 96 | 97 | // Minimum gap between IR transmissions 98 | #define _GAP 5000 99 | #define GAP_TICKS (_GAP/USECPERTICK) 100 | 101 | #define TICKS_LOW(us) ((int)(((us)*LTOL/USECPERTICK))) 102 | #define TICKS_HIGH(us) ((int)(((us)*UTOL/USECPERTICK + 1))) 103 | 104 | //------------------------------------------------------------------------------ 105 | // IR detector output is active low 106 | // 107 | #define MARK 0 108 | #define SPACE 1 109 | 110 | // All board specific stuff has been moved to its own file, included here. 111 | #include "boarddefs.h" 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /libraries/IRremote/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Board:** ARDUINO UNO 2 | **Library Version:** 2.1.0 3 | **Protocol:** Sony (if any) 4 | 5 | **Code Block:** 6 | ```c 7 | 8 | #include 9 | 10 | ..... 11 | 12 | ``` 13 | 14 | Use [a gist](gist.github.com) if the code exceeds 30 lines 15 | 16 | **checklist:** 17 | - [] I have **read** the README.md file thoroughly 18 | - [] I have searched existing issues to see if there is anything I have missed. 19 | - [] The latest [release](https://github.com/z3t0/Arduino-IRremote/releases/latest) is used 20 | - [] Any code referenced is provided and if over 30 lines a gist is linked INSTEAD of it being pasted in here 21 | - [] The title of the issue is helpful and relevant 22 | 23 | ** We will start to close issues that do not follow these guidelines as it doesn't help the contributors who spend time trying to solve issues if the community ignores guidelines!** 24 | 25 | The above is a short template allowing you to make detailed issues! 26 | -------------------------------------------------------------------------------- /libraries/IRremote/changelog.md: -------------------------------------------------------------------------------- 1 | ## 2.4.0 - 2017/08/10 2 | - Cleanup of hardware dependencies. Merge in SAM support [PR #437](https://github.com/z3t0/Arduino-IRremote/pull/437) 3 | 4 | ## 2.3.3 - 2017/03/31 5 | - Added ESP32 IR receive support [PR #427](https://github.com/z3t0/Arduino-IRremote/pull/425) 6 | 7 | ## 2.2.3 - 2017/03/27 8 | - Fix calculation of pause length in LEGO PF protocol [PR #427](https://github.com/z3t0/Arduino-IRremote/pull/427) 9 | 10 | ## 2.2.2 - 2017/01/20 11 | - Fixed naming bug [PR #398](https://github.com/z3t0/Arduino-IRremote/pull/398) 12 | 13 | ## 2.2.1 - 2016/07/27 14 | - Added tests for Lego Power Functions Protocol [PR #336](https://github.com/z3t0/Arduino-IRremote/pull/336) 15 | 16 | ## 2.2.0 - 2016/06/28 17 | - Added support for ATmega8535 18 | - Added support for ATmega16 19 | - Added support for ATmega32 20 | - Added support for ATmega164 21 | - Added support for ATmega324 22 | - Added support for ATmega644 23 | - Added support for ATmega1284 24 | - Added support for ATmega64 25 | - Added support for ATmega128 26 | 27 | [PR](https://github.com/z3t0/Arduino-IRremote/pull/324) 28 | 29 | ## 2.1.1 - 2016/05/04 30 | - Added Lego Power Functions Protocol [PR #309](https://github.com/z3t0/Arduino-IRremote/pull/309) 31 | 32 | ## 2.1.0 - 2016/02/20 33 | - Improved Debugging [PR #258](https://github.com/z3t0/Arduino-IRremote/pull/258) 34 | - Display TIME instead of TICKS [PR #258](https://github.com/z3t0/Arduino-IRremote/pull/258) 35 | 36 | ## 2.0.4 - 2016/02/20 37 | - Add Panasonic and JVC to IRrecord example [PR](https://github.com/z3t0/Arduino-IRremote/pull/54) 38 | 39 | ## 2.0.3 - 2016/02/20 40 | - Change IRSend Raw parameter to const [PR](https://github.com/z3t0/Arduino-IRremote/pull/227) 41 | 42 | ## 2.0.2 - 2015/12/02 43 | - Added IRremoteInfo Sketch - [PR](https://github.com/z3t0/Arduino-IRremote/pull/241) 44 | - Enforcing changelog.md 45 | 46 | ## 2.0.1 - 2015/07/26 - [Release](https://github.com/shirriff/Arduino-IRremote/releases/tag/BETA) 47 | ### Changes 48 | - Updated README 49 | - Updated Contributors 50 | - Fixed #110 Mess 51 | - Created Gitter Room 52 | - Added Gitter Badge 53 | - Standardised Code Base 54 | - Clean Debug Output 55 | - Optimized Send Loops 56 | - Modularized Design 57 | - Optimized and Updated Examples 58 | - Improved Documentation 59 | - Fixed and Improved many coding errors 60 | - Fixed Aiwa RC-T501 Decoding 61 | - Fixed Interrupt on ATmega8 62 | - Switched to Stable Release of @PlatformIO 63 | 64 | ### Additions 65 | - Added Aiwa RC-T501 Protocol 66 | - Added Denon Protocol 67 | - Added Pronto Support 68 | - Added Library Properties 69 | - Added Template For New Protocols 70 | - Added this changelog 71 | - Added Teensy LC Support 72 | - Added ATtiny84 Support 73 | - Added ATtiny85 Support 74 | - Added isIdle method 75 | 76 | ### Deletions 77 | - Removed (Fixed) #110 78 | - Broke Teensy 3 / 3.1 Support 79 | 80 | ### Not Working 81 | - Teensy 3 / 3.1 Support is in Development 82 | -------------------------------------------------------------------------------- /libraries/IRremote/esp32.cpp: -------------------------------------------------------------------------------- 1 | #ifdef ESP32 2 | 3 | // This file contains functions specific to the ESP32. 4 | 5 | #include "IRremote.h" 6 | #include "IRremoteInt.h" 7 | 8 | // "Idiot check" 9 | #ifdef USE_DEFAULT_ENABLE_IR_IN 10 | #error Must undef USE_DEFAULT_ENABLE_IR_IN 11 | #endif 12 | 13 | hw_timer_t *timer; 14 | void IRTimer(); // defined in IRremote.cpp, masqueraded as ISR(TIMER_INTR_NAME) 15 | 16 | //+============================================================================= 17 | // initialization 18 | // 19 | void IRrecv::enableIRIn ( ) 20 | { 21 | // Interrupt Service Routine - Fires every 50uS 22 | // ESP32 has a proper API to setup timers, no weird chip macros needed 23 | // simply call the readable API versions :) 24 | // 3 timers, choose #1, 80 divider nanosecond precision, 1 to count up 25 | timer = timerBegin(1, 80, 1); 26 | timerAttachInterrupt(timer, &IRTimer, 1); 27 | // every 50ns, autoreload = true 28 | timerAlarmWrite(timer, 50, true); 29 | timerAlarmEnable(timer); 30 | 31 | // Initialize state machine variables 32 | irparams.rcvstate = STATE_IDLE; 33 | irparams.rawlen = 0; 34 | 35 | // Set pin modes 36 | pinMode(irparams.recvpin, INPUT); 37 | } 38 | 39 | #endif // ESP32 40 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/AiwaRCT501SendDemo/AiwaRCT501SendDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend 3 | * An IR LED must be connected to Arduino PWM pin 3. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | #include "IRremote.h" 10 | 11 | #define POWER 0x7F80 12 | #define AIWA_RC_T501 13 | 14 | IRsend irsend; 15 | 16 | void setup() { 17 | Serial.begin(9600); 18 | Serial.println("Arduino Ready"); 19 | } 20 | 21 | void loop() { 22 | if (Serial.read() != -1) { 23 | irsend.sendAiwaRCT501(POWER); 24 | delay(60); // Optional 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/IRrecvDemo/IRrecvDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv 3 | * An IR detector/demodulator must be connected to the input RECV_PIN. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | #include 10 | 11 | int RECV_PIN = 11; 12 | 13 | IRrecv irrecv(RECV_PIN); 14 | 15 | decode_results results; 16 | 17 | void setup() 18 | { 19 | Serial.begin(9600); 20 | // In case the interrupt driver crashes on setup, give a clue 21 | // to the user what's going on. 22 | Serial.println("Enabling IRin"); 23 | irrecv.enableIRIn(); // Start the receiver 24 | Serial.println("Enabled IRin"); 25 | } 26 | 27 | void loop() { 28 | if (irrecv.decode(&results)) { 29 | Serial.println(results.value, HEX); 30 | irrecv.resume(); // Receive the next value 31 | } 32 | delay(100); 33 | } 34 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/IRrecvDump/IRrecvDump.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRrecvDump - dump details of IR codes with IRrecv 3 | * An IR detector/demodulator must be connected to the input RECV_PIN. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) 8 | * LG added by Darryl Smith (based on the JVC protocol) 9 | */ 10 | 11 | #include 12 | 13 | /* 14 | * Default is Arduino pin D11. 15 | * You can change this to another available Arduino Pin. 16 | * Your IR receiver should be connected to the pin defined here 17 | */ 18 | int RECV_PIN = 11; 19 | 20 | IRrecv irrecv(RECV_PIN); 21 | 22 | decode_results results; 23 | 24 | void setup() 25 | { 26 | Serial.begin(9600); 27 | irrecv.enableIRIn(); // Start the receiver 28 | } 29 | 30 | 31 | void dump(decode_results *results) { 32 | // Dumps out the decode_results structure. 33 | // Call this after IRrecv::decode() 34 | int count = results->rawlen; 35 | if (results->decode_type == UNKNOWN) { 36 | Serial.print("Unknown encoding: "); 37 | } 38 | else if (results->decode_type == NEC) { 39 | Serial.print("Decoded NEC: "); 40 | 41 | } 42 | else if (results->decode_type == SONY) { 43 | Serial.print("Decoded SONY: "); 44 | } 45 | else if (results->decode_type == RC5) { 46 | Serial.print("Decoded RC5: "); 47 | } 48 | else if (results->decode_type == RC6) { 49 | Serial.print("Decoded RC6: "); 50 | } 51 | else if (results->decode_type == PANASONIC) { 52 | Serial.print("Decoded PANASONIC - Address: "); 53 | Serial.print(results->address, HEX); 54 | Serial.print(" Value: "); 55 | } 56 | else if (results->decode_type == LG) { 57 | Serial.print("Decoded LG: "); 58 | } 59 | else if (results->decode_type == JVC) { 60 | Serial.print("Decoded JVC: "); 61 | } 62 | else if (results->decode_type == AIWA_RC_T501) { 63 | Serial.print("Decoded AIWA RC T501: "); 64 | } 65 | else if (results->decode_type == WHYNTER) { 66 | Serial.print("Decoded Whynter: "); 67 | } 68 | Serial.print(results->value, HEX); 69 | Serial.print(" ("); 70 | Serial.print(results->bits, DEC); 71 | Serial.println(" bits)"); 72 | Serial.print("Raw ("); 73 | Serial.print(count, DEC); 74 | Serial.print("): "); 75 | 76 | for (int i = 1; i < count; i++) { 77 | if (i & 1) { 78 | Serial.print(results->rawbuf[i]*USECPERTICK, DEC); 79 | } 80 | else { 81 | Serial.write('-'); 82 | Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC); 83 | } 84 | Serial.print(" "); 85 | } 86 | Serial.println(); 87 | } 88 | 89 | void loop() { 90 | if (irrecv.decode(&results)) { 91 | Serial.println(results.value, HEX); 92 | dump(&results); 93 | irrecv.resume(); // Receive the next value 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/IRrelay/IRrelay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv 3 | * An IR detector/demodulator must be connected to the input RECV_PIN. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | #include 10 | 11 | int RECV_PIN = 11; 12 | int RELAY_PIN = 4; 13 | 14 | IRrecv irrecv(RECV_PIN); 15 | decode_results results; 16 | 17 | // Dumps out the decode_results structure. 18 | // Call this after IRrecv::decode() 19 | // void * to work around compiler issue 20 | //void dump(void *v) { 21 | // decode_results *results = (decode_results *)v 22 | void dump(decode_results *results) { 23 | int count = results->rawlen; 24 | if (results->decode_type == UNKNOWN) { 25 | Serial.println("Could not decode message"); 26 | } 27 | else { 28 | if (results->decode_type == NEC) { 29 | Serial.print("Decoded NEC: "); 30 | } 31 | else if (results->decode_type == SONY) { 32 | Serial.print("Decoded SONY: "); 33 | } 34 | else if (results->decode_type == RC5) { 35 | Serial.print("Decoded RC5: "); 36 | } 37 | else if (results->decode_type == RC6) { 38 | Serial.print("Decoded RC6: "); 39 | } 40 | Serial.print(results->value, HEX); 41 | Serial.print(" ("); 42 | Serial.print(results->bits, DEC); 43 | Serial.println(" bits)"); 44 | } 45 | Serial.print("Raw ("); 46 | Serial.print(count, DEC); 47 | Serial.print("): "); 48 | 49 | for (int i = 0; i < count; i++) { 50 | if ((i % 2) == 1) { 51 | Serial.print(results->rawbuf[i]*USECPERTICK, DEC); 52 | } 53 | else { 54 | Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); 55 | } 56 | Serial.print(" "); 57 | } 58 | Serial.println(""); 59 | } 60 | 61 | void setup() 62 | { 63 | pinMode(RELAY_PIN, OUTPUT); 64 | pinMode(13, OUTPUT); 65 | Serial.begin(9600); 66 | irrecv.enableIRIn(); // Start the receiver 67 | } 68 | 69 | int on = 0; 70 | unsigned long last = millis(); 71 | 72 | void loop() { 73 | if (irrecv.decode(&results)) { 74 | // If it's been at least 1/4 second since the last 75 | // IR received, toggle the relay 76 | if (millis() - last > 250) { 77 | on = !on; 78 | digitalWrite(RELAY_PIN, on ? HIGH : LOW); 79 | digitalWrite(13, on ? HIGH : LOW); 80 | dump(&results); 81 | } 82 | last = millis(); 83 | irrecv.resume(); // Receive the next value 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/IRsendDemo/IRsendDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend 3 | * An IR LED must be connected to Arduino PWM pin 3. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | 10 | #include 11 | 12 | IRsend irsend; 13 | 14 | void setup() 15 | { 16 | } 17 | 18 | void loop() { 19 | for (int i = 0; i < 3; i++) { 20 | irsend.sendSony(0xa90, 12); 21 | delay(40); 22 | } 23 | delay(5000); //5 second delay between each signal burst 24 | } 25 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/IRsendRawDemo/IRsendRawDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRsendRawDemo - demonstrates sending IR codes with sendRaw 3 | * An IR LED must be connected to Arduino PWM pin 3. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | * 8 | * IRsendRawDemo - added by AnalysIR (via www.AnalysIR.com), 24 August 2015 9 | * 10 | * This example shows how to send a RAW signal using the IRremote library. 11 | * The example signal is actually a 32 bit NEC signal. 12 | * Remote Control button: LGTV Power On/Off. 13 | * Hex Value: 0x20DF10EF, 32 bits 14 | * 15 | * It is more efficient to use the sendNEC function to send NEC signals. 16 | * Use of sendRaw here, serves only as an example of using the function. 17 | * 18 | */ 19 | 20 | 21 | #include 22 | 23 | IRsend irsend; 24 | 25 | void setup() 26 | { 27 | 28 | } 29 | 30 | void loop() { 31 | int khz = 38; // 38kHz carrier frequency for the NEC protocol 32 | unsigned int irSignal[] = {9000, 4500, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 39416, 9000, 2210, 560}; //AnalysIR Batch Export (IRremote) - RAW 33 | 34 | irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array. 35 | 36 | delay(5000); //In this example, the signal will be repeated every 5 seconds, approximately. 37 | } 38 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend 3 | * An IR LED must be connected to Arduino PWM pin 3. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) 8 | */ 9 | #include 10 | 11 | #define PanasonicAddress 0x4004 // Panasonic address (Pre data) 12 | #define PanasonicPower 0x100BCBD // Panasonic Power button 13 | 14 | #define JVCPower 0xC5E8 15 | 16 | IRsend irsend; 17 | 18 | void setup() 19 | { 20 | } 21 | 22 | void loop() { 23 | irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off 24 | 25 | irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat 26 | delayMicroseconds(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information 27 | irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat 28 | delayMicroseconds(50); 29 | } 30 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/LGACSendDemo/LGACSendDemo.md: -------------------------------------------------------------------------------- 1 | === decoding for LG A/C ==== 2 | - 1) remote of LG AC has two type of HDR mark/space, 8000/4000 and 3100/10000 3 | - 2) HDR 8000/4000 is decoded using decodeLG(IRrecvDumpV2) without problem 4 | - 3) for HDR 3100/10000, use AnalysIR's code : http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/ 5 | - 4) for bin output based on AnalysIR's code : https://gist.github.com/chaeplin/a3a4b4b6b887c663bfe8 6 | - 5) remove first two byte(11) 7 | - 6) sample rawcode with bin output : https://gist.github.com/chaeplin/134d232e0b8cfb898860 8 | 9 | 10 | === *** === 11 | - 1) Sample raw code : https://gist.github.com/chaeplin/ab2a7ad1533c41260f0d 12 | - 2) send raw code : https://gist.github.com/chaeplin/7c800d3166463bb51be4 13 | 14 | 15 | === *** === 16 | - (0) : Cooling or Heating 17 | - (1) : fixed 18 | - (2) : fixed 19 | - (3) : special(power, swing, air clean) 20 | - (4) : change air flow, temperature, cooling(0)/heating(4) 21 | - (5) : temperature ( 15 + (5) = ) 22 | - (6) : air flow 23 | - (7) : crc ( 3 + 4 + 5 + 6 ) & B00001111 24 | 25 | 26 | °F = °C × 1.8 + 32 27 | °C = (°F − 32) / 1.8 28 | 29 | 30 | === *** === 31 | * remote / Korea / without heating 32 | 33 | | status |(0)| (1)| (2)| (3)| (4)| (5)| (6)| (7) 34 | |----------------|---|----|----|----|----|----|----|---- 35 | | on / 25 / mid | C |1000|1000|0000|0000|1010|0010|1100 36 | | on / 26 / mid | C |1000|1000|0000|0000|1011|0010|1101 37 | | on / 27 / mid | C |1000|1000|0000|0000|1100|0010|1110 38 | | on / 28 / mid | C |1000|1000|0000|0000|1101|0010|1111 39 | | on / 25 / high | C |1000|1000|0000|0000|1010|0100|1110 40 | | on / 26 / high | C |1000|1000|0000|0000|1011|0100|1111 41 | | on / 27 / high | C |1000|1000|0000|0000|1100|0100|0000 42 | | on / 28 / high | C |1000|1000|0000|0000|1101|0100|0001 43 | |----------------|---|----|----|----|----|----|----|---- 44 | | 1 up | C |1000|1000|0000|1000|1101|0100|1001 45 | |----------------|---|----|----|----|----|----|----|---- 46 | | Cool power | C |1000|1000|0001|0000|0000|1100|1101 47 | | energy saving | C |1000|1000|0001|0000|0000|0100|0101 48 | | power | C |1000|1000|0001|0000|0000|1000|1001 49 | | flow/up/down | C |1000|1000|0001|0011|0001|0100|1001 50 | | up/down off | C |1000|1000|0001|0011|0001|0101|1010 51 | | flow/left/right| C |1000|1000|0001|0011|0001|0110|1011 52 | | left/right off | C |1000|1000|0001|0011|0001|0111|1100 53 | |----------------|---|----|----|----|----|----|----|---- 54 | | Air clean | C |1000|1000|1100|0000|0000|0000|1100 55 | |----------------|---|----|----|----|----|----|----|---- 56 | | off | C |1000|1000|1100|0000|0000|0101|0001 57 | 58 | 59 | 60 | * remote / with heating 61 | * converted using raw code at https://github.com/chaeplin/RaspAC/blob/master/lircd.conf 62 | 63 | | status |(0)| (1)| (2)| (3)| (4)| (5)| (6)| (7) 64 | |----------------|---|----|----|----|----|----|----|---- 65 | | on | C |1000|1000|0000|0000|1011|0010|1101 66 | |----------------|---|----|----|----|----|----|----|---- 67 | | off | C |1000|1000|1100|0000|0000|0101|0001 68 | |----------------|---|----|----|----|----|----|----|---- 69 | | 64 / 18 | C |1000|1000|0000|0000|0011|0100|0111 70 | | 66 / 19 | C |1000|1000|0000|0000|0100|0100|1000 71 | | 68 / 20 | C |1000|1000|0000|0000|0101|0100|1001 72 | | 70 / 21 | C |1000|1000|0000|0000|0110|0100|1010 73 | | 72 / 22 | C |1000|1000|0000|0000|0111|0100|1011 74 | | 74 / 23 | C |1000|1000|0000|0000|1000|0100|1100 75 | | 76 / 25 | C |1000|1000|0000|0000|1010|0100|1110 76 | | 78 / 26 | C |1000|1000|0000|0000|1011|0100|1111 77 | | 80 / 27 | C |1000|1000|0000|0000|1100|0100|0000 78 | | 82 / 28 | C |1000|1000|0000|0000|1101|0100|0001 79 | | 84 / 29 | C |1000|1000|0000|0000|1110|0100|0010 80 | | 86 / 30 | C |1000|1000|0000|0000|1111|0100|0011 81 | |----------------|---|----|----|----|----|----|----|---- 82 | | heat64 | H |1000|1000|0000|0100|0011|0100|1011 83 | | heat66 | H |1000|1000|0000|0100|0100|0100|1100 84 | | heat68 | H |1000|1000|0000|0100|0101|0100|1101 85 | | heat70 | H |1000|1000|0000|0100|0110|0100|1110 86 | | heat72 | H |1000|1000|0000|0100|0111|0100|1111 87 | | heat74 | H |1000|1000|0000|0100|1000|0100|0000 88 | | heat76 | H |1000|1000|0000|0100|1001|0100|0001 89 | | heat78 | H |1000|1000|0000|0100|1011|0100|0011 90 | | heat80 | H |1000|1000|0000|0100|1100|0100|0100 91 | | heat82 | H |1000|1000|0000|0100|1101|0100|0101 92 | | heat84 | H |1000|1000|0000|0100|1110|0100|0110 93 | | heat86 | H |1000|1000|0000|0100|1111|0100|0111 94 | -------------------------------------------------------------------------------- /libraries/IRremote/examples/LegoPowerFunctionsSendDemo/LegoPowerFunctionsSendDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * LegoPowerFunctionsSendDemo: LEGO Power Functions 3 | * Copyright (c) 2016 Philipp Henkel 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | IRsend irsend; 10 | 11 | void setup() { 12 | } 13 | 14 | void loop() { 15 | // Send repeated command "channel 1, blue forward, red backward" 16 | irsend.sendLegoPowerFunctions(0x197); 17 | delay(2000); 18 | 19 | // Send single command "channel 1, blue forward, red backward" 20 | irsend.sendLegoPowerFunctions(0x197, false); 21 | delay(2000); 22 | } 23 | -------------------------------------------------------------------------------- /libraries/IRremote/irSend.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | #ifdef SENDING_SUPPORTED 5 | //+============================================================================= 6 | void IRsend::sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz) 7 | { 8 | // Set IR carrier frequency 9 | enableIROut(hz); 10 | 11 | for (unsigned int i = 0; i < len; i++) { 12 | if (i & 1) space(buf[i]) ; 13 | else mark (buf[i]) ; 14 | } 15 | 16 | space(0); // Always end with the LED off 17 | } 18 | 19 | #ifdef USE_SOFT_CARRIER 20 | void inline IRsend::sleepMicros(unsigned long us) 21 | { 22 | #ifdef USE_SPIN_WAIT 23 | sleepUntilMicros(micros() + us); 24 | #else 25 | if (us > 0U) // Is this necessary? (Official docu https://www.arduino.cc/en/Reference/DelayMicroseconds does not tell.) 26 | delayMicroseconds((unsigned int) us); 27 | #endif 28 | } 29 | 30 | void inline IRsend::sleepUntilMicros(unsigned long targetTime) 31 | { 32 | #ifdef USE_SPIN_WAIT 33 | while (micros() < targetTime) 34 | ; 35 | #else 36 | unsigned long now = micros(); 37 | if (now < targetTime) 38 | sleepMicros(targetTime - now); 39 | #endif 40 | } 41 | #endif // USE_SOFT_CARRIER 42 | 43 | //+============================================================================= 44 | // Sends an IR mark for the specified number of microseconds. 45 | // The mark output is modulated at the PWM frequency. 46 | // 47 | 48 | void IRsend::mark(unsigned int time) 49 | { 50 | #ifdef USE_SOFT_CARRIER 51 | unsigned long start = micros(); 52 | unsigned long stop = start + time; 53 | if (stop + periodTime < start) 54 | // Counter wrap-around, happens very seldomly, but CAN happen. 55 | // Just give up instead of possibly damaging the hardware. 56 | return; 57 | 58 | unsigned long nextPeriodEnding = start; 59 | unsigned long now = micros(); 60 | while (now < stop) { 61 | SENDPIN_ON(sendPin); 62 | sleepMicros(periodOnTime); 63 | SENDPIN_OFF(sendPin); 64 | nextPeriodEnding += periodTime; 65 | sleepUntilMicros(nextPeriodEnding); 66 | now = micros(); 67 | } 68 | #else 69 | TIMER_ENABLE_PWM; // Enable pin 3 PWM output 70 | if (time > 0) custom_delay_usec(time); 71 | #endif 72 | } 73 | 74 | //+============================================================================= 75 | // Leave pin off for time (given in microseconds) 76 | // Sends an IR space for the specified number of microseconds. 77 | // A space is no output, so the PWM output is disabled. 78 | // 79 | void IRsend::space (unsigned int time) 80 | { 81 | TIMER_DISABLE_PWM; // Disable pin 3 PWM output 82 | if (time > 0) IRsend::custom_delay_usec(time); 83 | } 84 | 85 | 86 | 87 | 88 | 89 | //+============================================================================= 90 | // Enables IR output. The khz value controls the modulation frequency in kilohertz. 91 | // The IR output will be on pin 3 (OC2B). 92 | // This routine is designed for 36-40KHz; if you use it for other values, it's up to you 93 | // to make sure it gives reasonable results. (Watch out for overflow / underflow / rounding.) 94 | // TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B 95 | // controlling the duty cycle. 96 | // There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A) 97 | // To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin. 98 | // A few hours staring at the ATmega documentation and this will all make sense. 99 | // See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details. 100 | // 101 | void IRsend::enableIROut (int khz) 102 | { 103 | #ifdef USE_SOFT_CARRIER 104 | periodTime = (1000U + khz/2) / khz; // = 1000/khz + 1/2 = round(1000.0/khz) 105 | periodOnTime = periodTime * DUTY_CYCLE / 100U - PULSE_CORRECTION; 106 | #endif 107 | 108 | // Disable the Timer2 Interrupt (which is used for receiving IR) 109 | TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt 110 | 111 | pinMode(sendPin, OUTPUT); 112 | SENDPIN_OFF(sendPin); // When not sending, we want it low 113 | 114 | // COM2A = 00: disconnect OC2A 115 | // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted 116 | // WGM2 = 101: phase-correct PWM with OCRA as top 117 | // CS2 = 000: no prescaling 118 | // The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A. 119 | TIMER_CONFIG_KHZ(khz); 120 | } 121 | 122 | //+============================================================================= 123 | // Custom delay function that circumvents Arduino's delayMicroseconds limit 124 | 125 | void IRsend::custom_delay_usec(unsigned long uSecs) { 126 | if (uSecs > 4) { 127 | unsigned long start = micros(); 128 | unsigned long endMicros = start + uSecs - 4; 129 | if (endMicros < start) { // Check if overflow 130 | while ( micros() > start ) {} // wait until overflow 131 | } 132 | while ( micros() < endMicros ) {} // normal wait 133 | } 134 | //else { 135 | // __asm__("nop\n\t"); // must have or compiler optimizes out 136 | //} 137 | } 138 | 139 | #endif // SENDING_SUPPORTED -------------------------------------------------------------------------------- /libraries/IRremote/ir_Aiwa.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // AAA IIIII W W AAA 6 | // A A I W W A A 7 | // AAAAA I W W W AAAAA 8 | // A A I W W W A A 9 | // A A IIIII WWW A A 10 | //============================================================================== 11 | 12 | // Based off the RC-T501 RCU 13 | // Lirc file http://lirc.sourceforge.net/remotes/aiwa/RC-T501 14 | 15 | #define AIWA_RC_T501_HZ 38 16 | #define AIWA_RC_T501_BITS 15 17 | #define AIWA_RC_T501_PRE_BITS 26 18 | #define AIWA_RC_T501_POST_BITS 1 19 | #define AIWA_RC_T501_SUM_BITS (AIWA_RC_T501_PRE_BITS + AIWA_RC_T501_BITS + AIWA_RC_T501_POST_BITS) 20 | #define AIWA_RC_T501_HDR_MARK 8800 21 | #define AIWA_RC_T501_HDR_SPACE 4500 22 | #define AIWA_RC_T501_BIT_MARK 500 23 | #define AIWA_RC_T501_ONE_SPACE 600 24 | #define AIWA_RC_T501_ZERO_SPACE 1700 25 | 26 | //+============================================================================= 27 | #if SEND_AIWA_RC_T501 28 | void IRsend::sendAiwaRCT501 (int code) 29 | { 30 | unsigned long pre = 0x0227EEC0; // 26-bits 31 | 32 | // Set IR carrier frequency 33 | enableIROut(AIWA_RC_T501_HZ); 34 | 35 | // Header 36 | mark(AIWA_RC_T501_HDR_MARK); 37 | space(AIWA_RC_T501_HDR_SPACE); 38 | 39 | // Send "pre" data 40 | for (unsigned long mask = 1UL << (26 - 1); mask; mask >>= 1) { 41 | mark(AIWA_RC_T501_BIT_MARK); 42 | if (pre & mask) space(AIWA_RC_T501_ONE_SPACE) ; 43 | else space(AIWA_RC_T501_ZERO_SPACE) ; 44 | } 45 | 46 | //-v- THIS CODE LOOKS LIKE IT MIGHT BE WRONG - CHECK! 47 | // it only send 15bits and ignores the top bit 48 | // then uses TOPBIT which is 0x80000000 to check the bit code 49 | // I suspect TOPBIT should be changed to 0x00008000 50 | 51 | // Skip first code bit 52 | code <<= 1; 53 | // Send code 54 | for (int i = 0; i < 15; i++) { 55 | mark(AIWA_RC_T501_BIT_MARK); 56 | if (code & 0x80000000) space(AIWA_RC_T501_ONE_SPACE) ; 57 | else space(AIWA_RC_T501_ZERO_SPACE) ; 58 | code <<= 1; 59 | } 60 | 61 | //-^- THIS CODE LOOKS LIKE IT MIGHT BE WRONG - CHECK! 62 | 63 | // POST-DATA, 1 bit, 0x0 64 | mark(AIWA_RC_T501_BIT_MARK); 65 | space(AIWA_RC_T501_ZERO_SPACE); 66 | 67 | mark(AIWA_RC_T501_BIT_MARK); 68 | space(0); 69 | } 70 | #endif 71 | 72 | //+============================================================================= 73 | #if DECODE_AIWA_RC_T501 74 | bool IRrecv::decodeAiwaRCT501 (decode_results *results) 75 | { 76 | int data = 0; 77 | int offset = 1; 78 | 79 | // Check SIZE 80 | if (irparams.rawlen < 2 * (AIWA_RC_T501_SUM_BITS) + 4) return false ; 81 | 82 | // Check HDR Mark/Space 83 | if (!MATCH_MARK (results->rawbuf[offset++], AIWA_RC_T501_HDR_MARK )) return false ; 84 | if (!MATCH_SPACE(results->rawbuf[offset++], AIWA_RC_T501_HDR_SPACE)) return false ; 85 | 86 | offset += 26; // skip pre-data - optional 87 | while(offset < irparams.rawlen - 4) { 88 | if (MATCH_MARK(results->rawbuf[offset], AIWA_RC_T501_BIT_MARK)) offset++ ; 89 | else return false ; 90 | 91 | // ONE & ZERO 92 | if (MATCH_SPACE(results->rawbuf[offset], AIWA_RC_T501_ONE_SPACE)) data = (data << 1) | 1 ; 93 | else if (MATCH_SPACE(results->rawbuf[offset], AIWA_RC_T501_ZERO_SPACE)) data = (data << 1) | 0 ; 94 | else break ; // End of one & zero detected 95 | offset++; 96 | } 97 | 98 | results->bits = (offset - 1) / 2; 99 | if (results->bits < 42) return false ; 100 | 101 | results->value = data; 102 | results->decode_type = AIWA_RC_T501; 103 | return true; 104 | } 105 | #endif 106 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Denon.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | // Reverse Engineered by looking at RAW dumps generated by IRremote 5 | 6 | // I have since discovered that Denon publish all their IR codes: 7 | // https://www.google.co.uk/search?q=DENON+MASTER+IR+Hex+Command+Sheet 8 | // -> http://assets.denon.com/documentmaster/us/denon%20master%20ir%20hex.xls 9 | 10 | // Having looked at the official Denon Pronto sheet and reverse engineered 11 | // the timing values from it, it is obvious that Denon have a range of 12 | // different timings and protocols ...the values here work for my AVR-3801 Amp! 13 | 14 | //============================================================================== 15 | // DDDD EEEEE N N OOO N N 16 | // D D E NN N O O NN N 17 | // D D EEE N N N O O N N N 18 | // D D E N NN O O N NN 19 | // DDDD EEEEE N N OOO N N 20 | //============================================================================== 21 | 22 | #define BITS 14 // The number of bits in the command 23 | 24 | #define HDR_MARK 300 // The length of the Header:Mark 25 | #define HDR_SPACE 750 // The lenght of the Header:Space 26 | 27 | #define BIT_MARK 300 // The length of a Bit:Mark 28 | #define ONE_SPACE 1800 // The length of a Bit:Space for 1's 29 | #define ZERO_SPACE 750 // The length of a Bit:Space for 0's 30 | 31 | //+============================================================================= 32 | // 33 | #if SEND_DENON 34 | void IRsend::sendDenon (unsigned long data, int nbits) 35 | { 36 | // Set IR carrier frequency 37 | enableIROut(38); 38 | 39 | // Header 40 | mark (HDR_MARK); 41 | space(HDR_SPACE); 42 | 43 | // Data 44 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 45 | if (data & mask) { 46 | mark (BIT_MARK); 47 | space(ONE_SPACE); 48 | } else { 49 | mark (BIT_MARK); 50 | space(ZERO_SPACE); 51 | } 52 | } 53 | 54 | // Footer 55 | mark(BIT_MARK); 56 | space(0); // Always end with the LED off 57 | } 58 | #endif 59 | 60 | //+============================================================================= 61 | // 62 | #if DECODE_DENON 63 | bool IRrecv::decodeDenon (decode_results *results) 64 | { 65 | unsigned long data = 0; // Somewhere to build our code 66 | int offset = 1; // Skip the Gap reading 67 | 68 | // Check we have the right amount of data 69 | if (irparams.rawlen != 1 + 2 + (2 * BITS) + 1) return false ; 70 | 71 | // Check initial Mark+Space match 72 | if (!MATCH_MARK (results->rawbuf[offset++], HDR_MARK )) return false ; 73 | if (!MATCH_SPACE(results->rawbuf[offset++], HDR_SPACE)) return false ; 74 | 75 | // Read the bits in 76 | for (int i = 0; i < BITS; i++) { 77 | // Each bit looks like: MARK + SPACE_1 -> 1 78 | // or : MARK + SPACE_0 -> 0 79 | if (!MATCH_MARK(results->rawbuf[offset++], BIT_MARK)) return false ; 80 | 81 | // IR data is big-endian, so we shuffle it in from the right: 82 | if (MATCH_SPACE(results->rawbuf[offset], ONE_SPACE)) data = (data << 1) | 1 ; 83 | else if (MATCH_SPACE(results->rawbuf[offset], ZERO_SPACE)) data = (data << 1) | 0 ; 84 | else return false ; 85 | offset++; 86 | } 87 | 88 | // Success 89 | results->bits = BITS; 90 | results->value = data; 91 | results->decode_type = DENON; 92 | return true; 93 | } 94 | #endif 95 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Dish.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // DDDD IIIII SSSS H H 6 | // D D I S H H 7 | // D D I SSS HHHHH 8 | // D D I S H H 9 | // DDDD IIIII SSSS H H 10 | //============================================================================== 11 | 12 | // Sharp and DISH support by Todd Treece ( http://unionbridge.org/design/ircommand ) 13 | // 14 | // The sned function needs to be repeated 4 times 15 | // 16 | // Only send the last for characters of the hex. 17 | // I.E. Use 0x1C10 instead of 0x0000000000001C10 as listed in the LIRC file. 18 | // 19 | // Here is the LIRC file I found that seems to match the remote codes from the 20 | // oscilloscope: 21 | // DISH NETWORK (echostar 301): 22 | // http://lirc.sourceforge.net/remotes/echostar/301_501_3100_5100_58xx_59xx 23 | 24 | #define DISH_BITS 16 25 | #define DISH_HDR_MARK 400 26 | #define DISH_HDR_SPACE 6100 27 | #define DISH_BIT_MARK 400 28 | #define DISH_ONE_SPACE 1700 29 | #define DISH_ZERO_SPACE 2800 30 | #define DISH_RPT_SPACE 6200 31 | 32 | //+============================================================================= 33 | #if SEND_DISH 34 | void IRsend::sendDISH (unsigned long data, int nbits) 35 | { 36 | // Set IR carrier frequency 37 | enableIROut(56); 38 | 39 | mark(DISH_HDR_MARK); 40 | space(DISH_HDR_SPACE); 41 | 42 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 43 | if (data & mask) { 44 | mark(DISH_BIT_MARK); 45 | space(DISH_ONE_SPACE); 46 | } else { 47 | mark(DISH_BIT_MARK); 48 | space(DISH_ZERO_SPACE); 49 | } 50 | } 51 | mark(DISH_HDR_MARK); //added 26th March 2016, by AnalysIR ( https://www.AnalysIR.com ) 52 | } 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_JVC.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // JJJJJ V V CCCC 6 | // J V V C 7 | // J V V C 8 | // J J V V C 9 | // J V CCCC 10 | //============================================================================== 11 | 12 | #define JVC_BITS 16 13 | #define JVC_HDR_MARK 8000 14 | #define JVC_HDR_SPACE 4000 15 | #define JVC_BIT_MARK 600 16 | #define JVC_ONE_SPACE 1600 17 | #define JVC_ZERO_SPACE 550 18 | #define JVC_RPT_LENGTH 60000 19 | 20 | //+============================================================================= 21 | // JVC does NOT repeat by sending a separate code (like NEC does). 22 | // The JVC protocol repeats by skipping the header. 23 | // To send a JVC repeat signal, send the original code value 24 | // and set 'repeat' to true 25 | // 26 | #if SEND_JVC 27 | void IRsend::sendJVC (unsigned long data, int nbits, bool repeat) 28 | { 29 | // Set IR carrier frequency 30 | enableIROut(38); 31 | 32 | // Only send the Header if this is NOT a repeat command 33 | if (!repeat){ 34 | mark(JVC_HDR_MARK); 35 | space(JVC_HDR_SPACE); 36 | } 37 | 38 | // Data 39 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 40 | if (data & mask) { 41 | mark(JVC_BIT_MARK); 42 | space(JVC_ONE_SPACE); 43 | } else { 44 | mark(JVC_BIT_MARK); 45 | space(JVC_ZERO_SPACE); 46 | } 47 | } 48 | 49 | // Footer 50 | mark(JVC_BIT_MARK); 51 | space(0); // Always end with the LED off 52 | } 53 | #endif 54 | 55 | //+============================================================================= 56 | #if DECODE_JVC 57 | bool IRrecv::decodeJVC (decode_results *results) 58 | { 59 | long data = 0; 60 | int offset = 1; // Skip first space 61 | 62 | // Check for repeat 63 | if ( (irparams.rawlen - 1 == 33) 64 | && MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK) 65 | && MATCH_MARK(results->rawbuf[irparams.rawlen-1], JVC_BIT_MARK) 66 | ) { 67 | results->bits = 0; 68 | results->value = REPEAT; 69 | results->decode_type = JVC; 70 | return true; 71 | } 72 | 73 | // Initial mark 74 | if (!MATCH_MARK(results->rawbuf[offset++], JVC_HDR_MARK)) return false ; 75 | 76 | if (irparams.rawlen < (2 * JVC_BITS) + 1 ) return false ; 77 | 78 | // Initial space 79 | if (!MATCH_SPACE(results->rawbuf[offset++], JVC_HDR_SPACE)) return false ; 80 | 81 | for (int i = 0; i < JVC_BITS; i++) { 82 | if (!MATCH_MARK(results->rawbuf[offset++], JVC_BIT_MARK)) return false ; 83 | 84 | if (MATCH_SPACE(results->rawbuf[offset], JVC_ONE_SPACE)) data = (data << 1) | 1 ; 85 | else if (MATCH_SPACE(results->rawbuf[offset], JVC_ZERO_SPACE)) data = (data << 1) | 0 ; 86 | else return false ; 87 | offset++; 88 | } 89 | 90 | // Stop bit 91 | if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)) return false ; 92 | 93 | // Success 94 | results->bits = JVC_BITS; 95 | results->value = data; 96 | results->decode_type = JVC; 97 | 98 | return true; 99 | } 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_LG.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // L GGGG 6 | // L G 7 | // L G GG 8 | // L G G 9 | // LLLLL GGG 10 | //============================================================================== 11 | 12 | #define LG_BITS 28 13 | 14 | #define LG_HDR_MARK 8000 15 | #define LG_HDR_SPACE 4000 16 | #define LG_BIT_MARK 600 17 | #define LG_ONE_SPACE 1600 18 | #define LG_ZERO_SPACE 550 19 | #define LG_RPT_LENGTH 60000 20 | 21 | //+============================================================================= 22 | #if DECODE_LG 23 | bool IRrecv::decodeLG (decode_results *results) 24 | { 25 | long data = 0; 26 | int offset = 1; // Skip first space 27 | 28 | // Check we have the right amount of data 29 | if (irparams.rawlen < (2 * LG_BITS) + 1 ) return false ; 30 | 31 | // Initial mark/space 32 | if (!MATCH_MARK(results->rawbuf[offset++], LG_HDR_MARK)) return false ; 33 | if (!MATCH_SPACE(results->rawbuf[offset++], LG_HDR_SPACE)) return false ; 34 | 35 | for (int i = 0; i < LG_BITS; i++) { 36 | if (!MATCH_MARK(results->rawbuf[offset++], LG_BIT_MARK)) return false ; 37 | 38 | if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) data = (data << 1) | 1 ; 39 | else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) data = (data << 1) | 0 ; 40 | else return false ; 41 | offset++; 42 | } 43 | 44 | // Stop bit 45 | if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) return false ; 46 | 47 | // Success 48 | results->bits = LG_BITS; 49 | results->value = data; 50 | results->decode_type = LG; 51 | return true; 52 | } 53 | #endif 54 | 55 | //+============================================================================= 56 | #if SEND_LG 57 | void IRsend::sendLG (unsigned long data, int nbits) 58 | { 59 | // Set IR carrier frequency 60 | enableIROut(38); 61 | 62 | // Header 63 | mark(LG_HDR_MARK); 64 | space(LG_HDR_SPACE); 65 | mark(LG_BIT_MARK); 66 | 67 | // Data 68 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 69 | if (data & mask) { 70 | space(LG_ONE_SPACE); 71 | mark(LG_BIT_MARK); 72 | } else { 73 | space(LG_ZERO_SPACE); 74 | mark(LG_BIT_MARK); 75 | } 76 | } 77 | space(0); // Always end with the LED off 78 | } 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Lego_PF.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | #include "ir_Lego_PF_BitStreamEncoder.h" 4 | 5 | //============================================================================== 6 | // L EEEEEE EEEE OOOO 7 | // L E E O O 8 | // L EEEE E EEE O O 9 | // L E E E O O LEGO Power Functions 10 | // LLLLLL EEEEEE EEEE OOOO Copyright (c) 2016 Philipp Henkel 11 | //============================================================================== 12 | 13 | // Supported Devices 14 | // LEGO® Power Functions IR Receiver 8884 15 | 16 | //+============================================================================= 17 | // 18 | #if SEND_LEGO_PF 19 | 20 | #if DEBUG 21 | namespace { 22 | void logFunctionParameters(uint16_t data, bool repeat) { 23 | DBG_PRINT("sendLegoPowerFunctions(data="); 24 | DBG_PRINT(data); 25 | DBG_PRINT(", repeat="); 26 | DBG_PRINTLN(repeat?"true)" : "false)"); 27 | } 28 | } // anonymous namespace 29 | #endif // DEBUG 30 | 31 | void IRsend::sendLegoPowerFunctions(uint16_t data, bool repeat) 32 | { 33 | #if DEBUG 34 | ::logFunctionParameters(data, repeat); 35 | #endif // DEBUG 36 | 37 | enableIROut(38); 38 | static LegoPfBitStreamEncoder bitStreamEncoder; 39 | bitStreamEncoder.reset(data, repeat); 40 | do { 41 | mark(bitStreamEncoder.getMarkDuration()); 42 | space(bitStreamEncoder.getPauseDuration()); 43 | } while (bitStreamEncoder.next()); 44 | } 45 | 46 | #endif // SEND_LEGO_PF 47 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Lego_PF_BitStreamEncoder.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================== 3 | // L EEEEEE EEEE OOOO 4 | // L E E O O 5 | // L EEEE E EEE O O 6 | // L E E E O O LEGO Power Functions 7 | // LLLLLL EEEEEE EEEE OOOO Copyright (c) 2016, 2017 Philipp Henkel 8 | //============================================================================== 9 | 10 | //+============================================================================= 11 | // 12 | 13 | class LegoPfBitStreamEncoder { 14 | private: 15 | uint16_t data; 16 | bool repeatMessage; 17 | uint8_t messageBitIdx; 18 | uint8_t repeatCount; 19 | uint16_t messageLength; 20 | 21 | public: 22 | // HIGH data bit = IR mark + high pause 23 | // LOW data bit = IR mark + low pause 24 | static const uint16_t LOW_BIT_DURATION = 421; 25 | static const uint16_t HIGH_BIT_DURATION = 711; 26 | static const uint16_t START_BIT_DURATION = 1184; 27 | static const uint16_t STOP_BIT_DURATION = 1184; 28 | static const uint8_t IR_MARK_DURATION = 158; 29 | static const uint16_t HIGH_PAUSE_DURATION = HIGH_BIT_DURATION - IR_MARK_DURATION; 30 | static const uint16_t LOW_PAUSE_DURATION = LOW_BIT_DURATION - IR_MARK_DURATION; 31 | static const uint16_t START_PAUSE_DURATION = START_BIT_DURATION - IR_MARK_DURATION; 32 | static const uint16_t STOP_PAUSE_DURATION = STOP_BIT_DURATION - IR_MARK_DURATION; 33 | static const uint8_t MESSAGE_BITS = 18; 34 | static const uint16_t MAX_MESSAGE_LENGTH = 16000; 35 | 36 | void reset(uint16_t data, bool repeatMessage) { 37 | this->data = data; 38 | this->repeatMessage = repeatMessage; 39 | messageBitIdx = 0; 40 | repeatCount = 0; 41 | messageLength = getMessageLength(); 42 | } 43 | 44 | int getChannelId() const { return 1 + ((data >> 12) & 0x3); } 45 | 46 | uint16_t getMessageLength() const { 47 | // Sum up all marks 48 | uint16_t length = MESSAGE_BITS * IR_MARK_DURATION; 49 | 50 | // Sum up all pauses 51 | length += START_PAUSE_DURATION; 52 | for (unsigned long mask = 1UL << 15; mask; mask >>= 1) { 53 | if (data & mask) { 54 | length += HIGH_PAUSE_DURATION; 55 | } else { 56 | length += LOW_PAUSE_DURATION; 57 | } 58 | } 59 | length += STOP_PAUSE_DURATION; 60 | return length; 61 | } 62 | 63 | boolean next() { 64 | messageBitIdx++; 65 | if (messageBitIdx >= MESSAGE_BITS) { 66 | repeatCount++; 67 | messageBitIdx = 0; 68 | } 69 | if (repeatCount >= 1 && !repeatMessage) { 70 | return false; 71 | } else if (repeatCount >= 5) { 72 | return false; 73 | } else { 74 | return true; 75 | } 76 | } 77 | 78 | uint8_t getMarkDuration() const { return IR_MARK_DURATION; } 79 | 80 | uint32_t getPauseDuration() const { 81 | if (messageBitIdx == 0) 82 | return START_PAUSE_DURATION; 83 | else if (messageBitIdx < MESSAGE_BITS - 1) { 84 | return getDataBitPause(); 85 | } else { 86 | return getStopPause(); 87 | } 88 | } 89 | 90 | private: 91 | uint16_t getDataBitPause() const { 92 | const int pos = MESSAGE_BITS - 2 - messageBitIdx; 93 | const bool isHigh = data & (1 << pos); 94 | return isHigh ? HIGH_PAUSE_DURATION : LOW_PAUSE_DURATION; 95 | } 96 | 97 | uint32_t getStopPause() const { 98 | if (repeatMessage) { 99 | return getRepeatStopPause(); 100 | } else { 101 | return STOP_PAUSE_DURATION; 102 | } 103 | } 104 | 105 | uint32_t getRepeatStopPause() const { 106 | if (repeatCount == 0 || repeatCount == 1) { 107 | return STOP_PAUSE_DURATION + (uint32_t)5 * MAX_MESSAGE_LENGTH - messageLength; 108 | } else if (repeatCount == 2 || repeatCount == 3) { 109 | return STOP_PAUSE_DURATION 110 | + (uint32_t)(6 + 2 * getChannelId()) * MAX_MESSAGE_LENGTH - messageLength; 111 | } else { 112 | return STOP_PAUSE_DURATION; 113 | } 114 | } 115 | }; 116 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Mitsubishi.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // MMMMM IIIII TTTTT SSSS U U BBBB IIIII SSSS H H IIIII 6 | // M M M I T S U U B B I S H H I 7 | // M M M I T SSS U U BBBB I SSS HHHHH I 8 | // M M I T S U U B B I S H H I 9 | // M M IIIII T SSSS UUU BBBBB IIIII SSSS H H IIIII 10 | //============================================================================== 11 | 12 | // Looks like Sony except for timings, 48 chars of data and time/space different 13 | 14 | #define MITSUBISHI_BITS 16 15 | 16 | // Mitsubishi RM 75501 17 | // 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7 18 | // #define MITSUBISHI_HDR_MARK 250 // seen range 3500 19 | #define MITSUBISHI_HDR_SPACE 350 // 7*50+100 20 | #define MITSUBISHI_ONE_MARK 1950 // 41*50-100 21 | #define MITSUBISHI_ZERO_MARK 750 // 17*50-100 22 | // #define MITSUBISHI_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround 23 | // #define MITSUBISHI_RPT_LENGTH 45000 24 | 25 | //+============================================================================= 26 | #if DECODE_MITSUBISHI 27 | bool IRrecv::decodeMitsubishi (decode_results *results) 28 | { 29 | // Serial.print("?!? decoding Mitsubishi:");Serial.print(irparams.rawlen); Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2); 30 | long data = 0; 31 | if (irparams.rawlen < 2 * MITSUBISHI_BITS + 2) return false ; 32 | int offset = 0; // Skip first space 33 | // Initial space 34 | 35 | #if 0 36 | // Put this back in for debugging - note can't use #DEBUG as if Debug on we don't see the repeat cos of the delay 37 | Serial.print("IR Gap: "); 38 | Serial.println( results->rawbuf[offset]); 39 | Serial.println( "test against:"); 40 | Serial.println(results->rawbuf[offset]); 41 | #endif 42 | 43 | #if 0 44 | // Not seeing double keys from Mitsubishi 45 | if (results->rawbuf[offset] < MITSUBISHI_DOUBLE_SPACE_USECS) { 46 | // Serial.print("IR Gap found: "); 47 | results->bits = 0; 48 | results->value = REPEAT; 49 | results->decode_type = MITSUBISHI; 50 | return true; 51 | } 52 | #endif 53 | 54 | offset++; 55 | 56 | // Typical 57 | // 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7 58 | 59 | // Initial Space 60 | if (!MATCH_MARK(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) return false ; 61 | offset++; 62 | 63 | while (offset + 1 < irparams.rawlen) { 64 | if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ONE_MARK)) data = (data << 1) | 1 ; 65 | else if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ZERO_MARK)) data <<= 1 ; 66 | else return false ; 67 | offset++; 68 | 69 | if (!MATCH_SPACE(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) break ; 70 | offset++; 71 | } 72 | 73 | // Success 74 | results->bits = (offset - 1) / 2; 75 | if (results->bits < MITSUBISHI_BITS) { 76 | results->bits = 0; 77 | return false; 78 | } 79 | 80 | results->value = data; 81 | results->decode_type = MITSUBISHI; 82 | return true; 83 | } 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_NEC.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // N N EEEEE CCCC 6 | // NN N E C 7 | // N N N EEE C 8 | // N NN E C 9 | // N N EEEEE CCCC 10 | //============================================================================== 11 | 12 | #define NEC_BITS 32 13 | #define NEC_HDR_MARK 9000 14 | #define NEC_HDR_SPACE 4500 15 | #define NEC_BIT_MARK 560 16 | #define NEC_ONE_SPACE 1690 17 | #define NEC_ZERO_SPACE 560 18 | #define NEC_RPT_SPACE 2250 19 | 20 | //+============================================================================= 21 | #if SEND_NEC 22 | void IRsend::sendNEC (unsigned long data, int nbits) 23 | { 24 | // Set IR carrier frequency 25 | enableIROut(38); 26 | 27 | // Header 28 | mark(NEC_HDR_MARK); 29 | space(NEC_HDR_SPACE); 30 | 31 | // Data 32 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 33 | if (data & mask) { 34 | mark(NEC_BIT_MARK); 35 | space(NEC_ONE_SPACE); 36 | } else { 37 | mark(NEC_BIT_MARK); 38 | space(NEC_ZERO_SPACE); 39 | } 40 | } 41 | 42 | // Footer 43 | mark(NEC_BIT_MARK); 44 | space(0); // Always end with the LED off 45 | } 46 | #endif 47 | 48 | //+============================================================================= 49 | // NECs have a repeat only 4 items long 50 | // 51 | #if DECODE_NEC 52 | bool IRrecv::decodeNEC (decode_results *results) 53 | { 54 | long data = 0; // We decode in to here; Start with nothing 55 | int offset = 1; // Index in to results; Skip first entry!? 56 | 57 | // Check header "mark" 58 | if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) return false ; 59 | offset++; 60 | 61 | // Check for repeat 62 | if ( (irparams.rawlen == 4) 63 | && MATCH_SPACE(results->rawbuf[offset ], NEC_RPT_SPACE) 64 | && MATCH_MARK (results->rawbuf[offset+1], NEC_BIT_MARK ) 65 | ) { 66 | results->bits = 0; 67 | results->value = REPEAT; 68 | results->decode_type = NEC; 69 | return true; 70 | } 71 | 72 | // Check we have enough data 73 | if (irparams.rawlen < (2 * NEC_BITS) + 4) return false ; 74 | 75 | // Check header "space" 76 | if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) return false ; 77 | offset++; 78 | 79 | // Build the data 80 | for (int i = 0; i < NEC_BITS; i++) { 81 | // Check data "mark" 82 | if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) return false ; 83 | offset++; 84 | // Suppend this bit 85 | if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE )) data = (data << 1) | 1 ; 86 | else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) data = (data << 1) | 0 ; 87 | else return false ; 88 | offset++; 89 | } 90 | 91 | // Success 92 | results->bits = NEC_BITS; 93 | results->value = data; 94 | results->decode_type = NEC; 95 | 96 | return true; 97 | } 98 | #endif 99 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Panasonic.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // PPPP AAA N N AAA SSSS OOO N N IIIII CCCC 6 | // P P A A NN N A A S O O NN N I C 7 | // PPPP AAAAA N N N AAAAA SSS O O N N N I C 8 | // P A A N NN A A S O O N NN I C 9 | // P A A N N A A SSSS OOO N N IIIII CCCC 10 | //============================================================================== 11 | 12 | #define PANASONIC_BITS 48 13 | #define PANASONIC_HDR_MARK 3502 14 | #define PANASONIC_HDR_SPACE 1750 15 | #define PANASONIC_BIT_MARK 502 16 | #define PANASONIC_ONE_SPACE 1244 17 | #define PANASONIC_ZERO_SPACE 400 18 | 19 | //+============================================================================= 20 | #if SEND_PANASONIC 21 | void IRsend::sendPanasonic (unsigned int address, unsigned long data) 22 | { 23 | // Set IR carrier frequency 24 | enableIROut(35); 25 | 26 | // Header 27 | mark(PANASONIC_HDR_MARK); 28 | space(PANASONIC_HDR_SPACE); 29 | 30 | // Address 31 | for (unsigned long mask = 1UL << (16 - 1); mask; mask >>= 1) { 32 | mark(PANASONIC_BIT_MARK); 33 | if (address & mask) space(PANASONIC_ONE_SPACE) ; 34 | else space(PANASONIC_ZERO_SPACE) ; 35 | } 36 | 37 | // Data 38 | for (unsigned long mask = 1UL << (32 - 1); mask; mask >>= 1) { 39 | mark(PANASONIC_BIT_MARK); 40 | if (data & mask) space(PANASONIC_ONE_SPACE) ; 41 | else space(PANASONIC_ZERO_SPACE) ; 42 | } 43 | 44 | // Footer 45 | mark(PANASONIC_BIT_MARK); 46 | space(0); // Always end with the LED off 47 | } 48 | #endif 49 | 50 | //+============================================================================= 51 | #if DECODE_PANASONIC 52 | bool IRrecv::decodePanasonic (decode_results *results) 53 | { 54 | unsigned long long data = 0; 55 | int offset = 1; 56 | 57 | if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_MARK )) return false ; 58 | if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_SPACE)) return false ; 59 | 60 | // decode address 61 | for (int i = 0; i < PANASONIC_BITS; i++) { 62 | if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_BIT_MARK)) return false ; 63 | 64 | if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ONE_SPACE )) data = (data << 1) | 1 ; 65 | else if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) data = (data << 1) | 0 ; 66 | else return false ; 67 | offset++; 68 | } 69 | 70 | results->value = (unsigned long)data; 71 | results->address = (unsigned int)(data >> 32); 72 | results->decode_type = PANASONIC; 73 | results->bits = PANASONIC_BITS; 74 | 75 | return true; 76 | } 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Samsung.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS AAA MMM SSSS U U N N GGGG 6 | // S A A M M M S U U NN N G 7 | // SSS AAAAA M M M SSS U U N N N G GG 8 | // S A A M M S U U N NN G G 9 | // SSSS A A M M SSSS UUU N N GGG 10 | //============================================================================== 11 | 12 | #define SAMSUNG_BITS 32 13 | #define SAMSUNG_HDR_MARK 5000 14 | #define SAMSUNG_HDR_SPACE 5000 15 | #define SAMSUNG_BIT_MARK 560 16 | #define SAMSUNG_ONE_SPACE 1600 17 | #define SAMSUNG_ZERO_SPACE 560 18 | #define SAMSUNG_RPT_SPACE 2250 19 | 20 | //+============================================================================= 21 | #if SEND_SAMSUNG 22 | void IRsend::sendSAMSUNG (unsigned long data, int nbits) 23 | { 24 | // Set IR carrier frequency 25 | enableIROut(38); 26 | 27 | // Header 28 | mark(SAMSUNG_HDR_MARK); 29 | space(SAMSUNG_HDR_SPACE); 30 | 31 | // Data 32 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 33 | if (data & mask) { 34 | mark(SAMSUNG_BIT_MARK); 35 | space(SAMSUNG_ONE_SPACE); 36 | } else { 37 | mark(SAMSUNG_BIT_MARK); 38 | space(SAMSUNG_ZERO_SPACE); 39 | } 40 | } 41 | 42 | // Footer 43 | mark(SAMSUNG_BIT_MARK); 44 | space(0); // Always end with the LED off 45 | } 46 | #endif 47 | 48 | //+============================================================================= 49 | // SAMSUNGs have a repeat only 4 items long 50 | // 51 | #if DECODE_SAMSUNG 52 | bool IRrecv::decodeSAMSUNG (decode_results *results) 53 | { 54 | long data = 0; 55 | int offset = 1; // Skip first space 56 | 57 | // Initial mark 58 | if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) return false ; 59 | offset++; 60 | 61 | // Check for repeat 62 | if ( (irparams.rawlen == 4) 63 | && MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE) 64 | && MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK) 65 | ) { 66 | results->bits = 0; 67 | results->value = REPEAT; 68 | results->decode_type = SAMSUNG; 69 | return true; 70 | } 71 | if (irparams.rawlen < (2 * SAMSUNG_BITS) + 4) return false ; 72 | 73 | // Initial space 74 | if (!MATCH_SPACE(results->rawbuf[offset++], SAMSUNG_HDR_SPACE)) return false ; 75 | 76 | for (int i = 0; i < SAMSUNG_BITS; i++) { 77 | if (!MATCH_MARK(results->rawbuf[offset++], SAMSUNG_BIT_MARK)) return false ; 78 | 79 | if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) data = (data << 1) | 1 ; 80 | else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) data = (data << 1) | 0 ; 81 | else return false ; 82 | offset++; 83 | } 84 | 85 | // Success 86 | results->bits = SAMSUNG_BITS; 87 | results->value = data; 88 | results->decode_type = SAMSUNG; 89 | return true; 90 | } 91 | #endif 92 | 93 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Sanyo.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS AAA N N Y Y OOO 6 | // S A A NN N Y Y O O 7 | // SSS AAAAA N N N Y O O 8 | // S A A N NN Y O O 9 | // SSSS A A N N Y OOO 10 | //============================================================================== 11 | 12 | // I think this is a Sanyo decoder: Serial = SA 8650B 13 | // Looks like Sony except for timings, 48 chars of data and time/space different 14 | 15 | #define SANYO_BITS 12 16 | #define SANYO_HDR_MARK 3500 // seen range 3500 17 | #define SANYO_HDR_SPACE 950 // seen 950 18 | #define SANYO_ONE_MARK 2400 // seen 2400 19 | #define SANYO_ZERO_MARK 700 // seen 700 20 | #define SANYO_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround 21 | #define SANYO_RPT_LENGTH 45000 22 | 23 | //+============================================================================= 24 | #if DECODE_SANYO 25 | bool IRrecv::decodeSanyo (decode_results *results) 26 | { 27 | long data = 0; 28 | int offset = 0; // Skip first space <-- CHECK THIS! 29 | 30 | if (irparams.rawlen < (2 * SANYO_BITS) + 2) return false ; 31 | 32 | #if 0 33 | // Put this back in for debugging - note can't use #DEBUG as if Debug on we don't see the repeat cos of the delay 34 | Serial.print("IR Gap: "); 35 | Serial.println( results->rawbuf[offset]); 36 | Serial.println( "test against:"); 37 | Serial.println(results->rawbuf[offset]); 38 | #endif 39 | 40 | // Initial space 41 | if (results->rawbuf[offset] < SANYO_DOUBLE_SPACE_USECS) { 42 | //Serial.print("IR Gap found: "); 43 | results->bits = 0; 44 | results->value = REPEAT; 45 | results->decode_type = SANYO; 46 | return true; 47 | } 48 | offset++; 49 | 50 | // Initial mark 51 | if (!MATCH_MARK(results->rawbuf[offset++], SANYO_HDR_MARK)) return false ; 52 | 53 | // Skip Second Mark 54 | if (!MATCH_MARK(results->rawbuf[offset++], SANYO_HDR_MARK)) return false ; 55 | 56 | while (offset + 1 < irparams.rawlen) { 57 | if (!MATCH_SPACE(results->rawbuf[offset++], SANYO_HDR_SPACE)) break ; 58 | 59 | if (MATCH_MARK(results->rawbuf[offset], SANYO_ONE_MARK)) data = (data << 1) | 1 ; 60 | else if (MATCH_MARK(results->rawbuf[offset], SANYO_ZERO_MARK)) data = (data << 1) | 0 ; 61 | else return false ; 62 | offset++; 63 | } 64 | 65 | // Success 66 | results->bits = (offset - 1) / 2; 67 | if (results->bits < 12) { 68 | results->bits = 0; 69 | return false; 70 | } 71 | 72 | results->value = data; 73 | results->decode_type = SANYO; 74 | return true; 75 | } 76 | #endif 77 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Sharp.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS H H AAA RRRR PPPP 6 | // S H H A A R R P P 7 | // SSS HHHHH AAAAA RRRR PPPP 8 | // S H H A A R R P 9 | // SSSS H H A A R R P 10 | //============================================================================== 11 | 12 | // Sharp and DISH support by Todd Treece: http://unionbridge.org/design/ircommand 13 | // 14 | // The send function has the necessary repeat built in because of the need to 15 | // invert the signal. 16 | // 17 | // Sharp protocol documentation: 18 | // http://www.sbprojects.com/knowledge/ir/sharp.htm 19 | // 20 | // Here is the LIRC file I found that seems to match the remote codes from the 21 | // oscilloscope: 22 | // Sharp LCD TV: 23 | // http://lirc.sourceforge.net/remotes/sharp/GA538WJSA 24 | 25 | #define SHARP_BITS 15 26 | #define SHARP_BIT_MARK 245 27 | #define SHARP_ONE_SPACE 1805 28 | #define SHARP_ZERO_SPACE 795 29 | #define SHARP_GAP 600000 30 | #define SHARP_RPT_SPACE 3000 31 | 32 | #define SHARP_TOGGLE_MASK 0x3FF 33 | 34 | //+============================================================================= 35 | #if SEND_SHARP 36 | void IRsend::sendSharpRaw (unsigned long data, int nbits) 37 | { 38 | enableIROut(38); 39 | 40 | // Sending codes in bursts of 3 (normal, inverted, normal) makes transmission 41 | // much more reliable. That's the exact behaviour of CD-S6470 remote control. 42 | for (int n = 0; n < 3; n++) { 43 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 44 | if (data & mask) { 45 | mark(SHARP_BIT_MARK); 46 | space(SHARP_ONE_SPACE); 47 | } else { 48 | mark(SHARP_BIT_MARK); 49 | space(SHARP_ZERO_SPACE); 50 | } 51 | } 52 | 53 | mark(SHARP_BIT_MARK); 54 | space(SHARP_ZERO_SPACE); 55 | delay(40); 56 | 57 | data = data ^ SHARP_TOGGLE_MASK; 58 | } 59 | } 60 | #endif 61 | 62 | //+============================================================================= 63 | // Sharp send compatible with data obtained through decodeSharp() 64 | // ^^^^^^^^^^^^^ FUNCTION MISSING! 65 | // 66 | #if SEND_SHARP 67 | void IRsend::sendSharp (unsigned int address, unsigned int command) 68 | { 69 | sendSharpRaw((address << 10) | (command << 2) | 2, SHARP_BITS); 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Sony.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS OOO N N Y Y 6 | // S O O NN N Y Y 7 | // SSS O O N N N Y 8 | // S O O N NN Y 9 | // SSSS OOO N N Y 10 | //============================================================================== 11 | 12 | #define SONY_BITS 12 13 | #define SONY_HDR_MARK 2400 14 | #define SONY_HDR_SPACE 600 15 | #define SONY_ONE_MARK 1200 16 | #define SONY_ZERO_MARK 600 17 | #define SONY_RPT_LENGTH 45000 18 | #define SONY_DOUBLE_SPACE_USECS 500 // usually ssee 713 - not using ticks as get number wrapround 19 | 20 | //+============================================================================= 21 | #if SEND_SONY 22 | void IRsend::sendSony (unsigned long data, int nbits) 23 | { 24 | // Set IR carrier frequency 25 | enableIROut(40); 26 | 27 | // Header 28 | mark(SONY_HDR_MARK); 29 | space(SONY_HDR_SPACE); 30 | 31 | // Data 32 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 33 | if (data & mask) { 34 | mark(SONY_ONE_MARK); 35 | space(SONY_HDR_SPACE); 36 | } else { 37 | mark(SONY_ZERO_MARK); 38 | space(SONY_HDR_SPACE); 39 | } 40 | } 41 | 42 | // We will have ended with LED off 43 | } 44 | #endif 45 | 46 | //+============================================================================= 47 | #if DECODE_SONY 48 | bool IRrecv::decodeSony (decode_results *results) 49 | { 50 | long data = 0; 51 | int offset = 0; // Dont skip first space, check its size 52 | 53 | if (irparams.rawlen < (2 * SONY_BITS) + 2) return false ; 54 | 55 | // Some Sony's deliver repeats fast after first 56 | // unfortunately can't spot difference from of repeat from two fast clicks 57 | if (results->rawbuf[offset] < SONY_DOUBLE_SPACE_USECS) { 58 | // Serial.print("IR Gap found: "); 59 | results->bits = 0; 60 | results->value = REPEAT; 61 | 62 | # ifdef DECODE_SANYO 63 | results->decode_type = SANYO; 64 | # else 65 | results->decode_type = UNKNOWN; 66 | # endif 67 | 68 | return true; 69 | } 70 | offset++; 71 | 72 | // Initial mark 73 | if (!MATCH_MARK(results->rawbuf[offset++], SONY_HDR_MARK)) return false ; 74 | 75 | while (offset + 1 < irparams.rawlen) { 76 | if (!MATCH_SPACE(results->rawbuf[offset++], SONY_HDR_SPACE)) break ; 77 | 78 | if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) data = (data << 1) | 1 ; 79 | else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) data = (data << 1) | 0 ; 80 | else return false ; 81 | offset++; 82 | } 83 | 84 | // Success 85 | results->bits = (offset - 1) / 2; 86 | if (results->bits < 12) { 87 | results->bits = 0; 88 | return false; 89 | } 90 | results->value = data; 91 | results->decode_type = SONY; 92 | return true; 93 | } 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /libraries/IRremote/ir_Whynter.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // W W H H Y Y N N TTTTT EEEEE RRRRR 6 | // W W H H Y Y NN N T E R R 7 | // W W W HHHHH Y N N N T EEE RRRR 8 | // W W W H H Y N NN T E R R 9 | // WWW H H Y N N T EEEEE R R 10 | //============================================================================== 11 | 12 | #define WHYNTER_BITS 32 13 | #define WHYNTER_HDR_MARK 2850 14 | #define WHYNTER_HDR_SPACE 2850 15 | #define WHYNTER_BIT_MARK 750 16 | #define WHYNTER_ONE_MARK 750 17 | #define WHYNTER_ONE_SPACE 2150 18 | #define WHYNTER_ZERO_MARK 750 19 | #define WHYNTER_ZERO_SPACE 750 20 | 21 | //+============================================================================= 22 | #if SEND_WHYNTER 23 | void IRsend::sendWhynter (unsigned long data, int nbits) 24 | { 25 | // Set IR carrier frequency 26 | enableIROut(38); 27 | 28 | // Start 29 | mark(WHYNTER_ZERO_MARK); 30 | space(WHYNTER_ZERO_SPACE); 31 | 32 | // Header 33 | mark(WHYNTER_HDR_MARK); 34 | space(WHYNTER_HDR_SPACE); 35 | 36 | // Data 37 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 38 | if (data & mask) { 39 | mark(WHYNTER_ONE_MARK); 40 | space(WHYNTER_ONE_SPACE); 41 | } else { 42 | mark(WHYNTER_ZERO_MARK); 43 | space(WHYNTER_ZERO_SPACE); 44 | } 45 | } 46 | 47 | // Footer 48 | mark(WHYNTER_ZERO_MARK); 49 | space(WHYNTER_ZERO_SPACE); // Always end with the LED off 50 | } 51 | #endif 52 | 53 | //+============================================================================= 54 | #if DECODE_WHYNTER 55 | bool IRrecv::decodeWhynter (decode_results *results) 56 | { 57 | long data = 0; 58 | int offset = 1; // skip initial space 59 | 60 | // Check we have the right amount of data 61 | if (irparams.rawlen < (2 * WHYNTER_BITS) + 6) return false ; 62 | 63 | // Sequence begins with a bit mark and a zero space 64 | if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_BIT_MARK )) return false ; 65 | if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_ZERO_SPACE)) return false ; 66 | 67 | // header mark and space 68 | if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_HDR_MARK )) return false ; 69 | if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_HDR_SPACE)) return false ; 70 | 71 | // data bits 72 | for (int i = 0; i < WHYNTER_BITS; i++) { 73 | if (!MATCH_MARK(results->rawbuf[offset++], WHYNTER_BIT_MARK)) return false ; 74 | 75 | if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ONE_SPACE )) data = (data << 1) | 1 ; 76 | else if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ZERO_SPACE)) data = (data << 1) | 0 ; 77 | else return false ; 78 | offset++; 79 | } 80 | 81 | // trailing mark 82 | if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) return false ; 83 | 84 | // Success 85 | results->bits = WHYNTER_BITS; 86 | results->value = data; 87 | results->decode_type = WHYNTER; 88 | return true; 89 | } 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /libraries/IRremote/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For IRremote 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | decode_results KEYWORD1 10 | IRrecv KEYWORD1 11 | IRsend KEYWORD1 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | blink13 KEYWORD2 18 | decode KEYWORD2 19 | enableIRIn KEYWORD2 20 | resume KEYWORD2 21 | enableIROut KEYWORD2 22 | sendNEC KEYWORD2 23 | sendSony KEYWORD2 24 | sendSanyo KEYWORD2 25 | sendMitsubishi KEYWORD2 26 | sendRaw KEYWORD2 27 | sendRC5 KEYWORD2 28 | sendRC6 KEYWORD2 29 | sendDISH KEYWORD2 30 | sendSharp KEYWORD2 31 | sendSharpRaw KEYWORD2 32 | sendPanasonic KEYWORD2 33 | sendJVC KEYWORD2 34 | sendLG KEYWORD2 35 | 36 | ####################################### 37 | # Constants (LITERAL1) 38 | ####################################### 39 | 40 | NEC LITERAL1 41 | SONY LITERAL1 42 | SANYO LITERAL1 43 | MITSUBISHI LITERAL1 44 | RC5 LITERAL1 45 | RC6 LITERAL1 46 | DISH LITERAL1 47 | SHARP LITERAL1 48 | PANASONIC LITERAL1 49 | JVC LITERAL1 50 | LG LITERAL1 51 | AIWA_RC_T501 LITERAL1 52 | UNKNOWN LITERAL1 53 | REPEAT LITERAL1 54 | -------------------------------------------------------------------------------- /libraries/IRremote/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "IRremote", 3 | "keywords": "infrared, ir, remote", 4 | "description": "Send and receive infrared signals with multiple protocols", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/z3t0/Arduino-IRremote.git" 9 | }, 10 | "version": "2.3.3", 11 | "frameworks": "arduino", 12 | "platforms": "atmelavr", 13 | "authors" : 14 | [ 15 | { 16 | "name":"Rafi Khan", 17 | "email":"zetoslab@gmail.com" 18 | }, 19 | { 20 | "name":"Ken Shirriff", 21 | "email":"ken.shirriff@gmail.com" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /libraries/IRremote/library.properties: -------------------------------------------------------------------------------- 1 | name=IRremote 2 | version=2.2.3 3 | author=shirriff 4 | maintainer=shirriff 5 | sentence=Send and receive infrared signals with multiple protocols 6 | paragraph=Send and receive infrared signals with multiple protocols 7 | category=Signal Input/Output 8 | url=https://github.com/shirriff/Arduino-IRremote.git 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/IRremote/sam.cpp: -------------------------------------------------------------------------------- 1 | // Support routines for SAM processor boards 2 | 3 | #include "IRremote.h" 4 | #include "IRremoteInt.h" 5 | 6 | #if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) 7 | 8 | // "Idiot check" 9 | #ifdef USE_DEFAULT_ENABLE_IR_IN 10 | #error Must undef USE_DEFAULT_ENABLE_IR_IN 11 | #endif 12 | 13 | //+============================================================================= 14 | // ATSAMD Timer setup & IRQ functions 15 | // 16 | 17 | // following based on setup from GitHub jdneo/timerInterrupt.ino 18 | 19 | static void setTimerFrequency(int frequencyHz) 20 | { 21 | int compareValue = (SYSCLOCK / (TIMER_PRESCALER_DIV * frequencyHz)) - 1; 22 | //Serial.println(compareValue); 23 | TcCount16* TC = (TcCount16*) TC3; 24 | // Make sure the count is in a proportional position to where it was 25 | // to prevent any jitter or disconnect when changing the compare value. 26 | TC->COUNT.reg = map(TC->COUNT.reg, 0, TC->CC[0].reg, 0, compareValue); 27 | TC->CC[0].reg = compareValue; 28 | //Serial.print("COUNT.reg "); 29 | //Serial.println(TC->COUNT.reg); 30 | //Serial.print("CC[0].reg "); 31 | //Serial.println(TC->CC[0].reg); 32 | while (TC->STATUS.bit.SYNCBUSY == 1); 33 | } 34 | 35 | static void startTimer() 36 | { 37 | REG_GCLK_CLKCTRL = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID_TCC2_TC3); 38 | while (GCLK->STATUS.bit.SYNCBUSY == 1); // wait for sync 39 | 40 | TcCount16* TC = (TcCount16*) TC3; 41 | 42 | TC->CTRLA.reg &= ~TC_CTRLA_ENABLE; 43 | while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync 44 | 45 | // Use the 16-bit timer 46 | TC->CTRLA.reg |= TC_CTRLA_MODE_COUNT16; 47 | while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync 48 | 49 | // Use match mode so that the timer counter resets when the count matches the compare register 50 | TC->CTRLA.reg |= TC_CTRLA_WAVEGEN_MFRQ; 51 | while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync 52 | 53 | // Set prescaler to 1024 54 | //TC->CTRLA.reg |= TC_CTRLA_PRESCALER_DIV1024; 55 | TC->CTRLA.reg |= TC_CTRLA_PRESCALER_DIV64; 56 | while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync 57 | 58 | setTimerFrequency(1000000 / USECPERTICK); 59 | 60 | // Enable the compare interrupt 61 | TC->INTENSET.reg = 0; 62 | TC->INTENSET.bit.MC0 = 1; 63 | 64 | NVIC_EnableIRQ(TC3_IRQn); 65 | 66 | TC->CTRLA.reg |= TC_CTRLA_ENABLE; 67 | while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync 68 | } 69 | 70 | //+============================================================================= 71 | // initialization 72 | // 73 | 74 | void IRrecv::enableIRIn() 75 | { 76 | // Interrupt Service Routine - Fires every 50uS 77 | //Serial.println("Starting timer"); 78 | startTimer(); 79 | //Serial.println("Started timer"); 80 | 81 | // Initialize state machine variables 82 | irparams.rcvstate = STATE_IDLE; 83 | irparams.rawlen = 0; 84 | 85 | // Set pin modes 86 | pinMode(irparams.recvpin, INPUT); 87 | } 88 | 89 | void irs(); // Defined in IRRemote as ISR(TIMER_INTR_NAME) 90 | 91 | void TC3_Handler(void) 92 | { 93 | TcCount16* TC = (TcCount16*) TC3; 94 | // If this interrupt is due to the compare register matching the timer count 95 | // we toggle the LED. 96 | if (TC->INTFLAG.bit.MC0 == 1) { 97 | TC->INTFLAG.bit.MC0 = 1; 98 | irs(); 99 | } 100 | } 101 | 102 | #endif // defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) -------------------------------------------------------------------------------- /libraries/PubSubClient/CHANGES.txt: -------------------------------------------------------------------------------- 1 | 2.7 2 | * Fix remaining-length handling to prevent buffer overrun 3 | * Add large-payload API - beginPublish/write/publish/endPublish 4 | * Add yield call to improve reliability on ESP 5 | * Add Clean Session flag to connect options 6 | * Add ESP32 support for functional callback signature 7 | * Various other fixes 8 | 9 | 2.4 10 | * Add MQTT_SOCKET_TIMEOUT to prevent it blocking indefinitely 11 | whilst waiting for inbound data 12 | * Fixed return code when publishing >256 bytes 13 | 14 | 2.3 15 | * Add publish(topic,payload,retained) function 16 | 17 | 2.2 18 | * Change code layout to match Arduino Library reqs 19 | 20 | 2.1 21 | * Add MAX_TRANSFER_SIZE def to chunk messages if needed 22 | * Reject topic/payloads that exceed MQTT_MAX_PACKET_SIZE 23 | 24 | 2.0 25 | * Add (and default to) MQTT 3.1.1 support 26 | * Fix PROGMEM handling for Intel Galileo/ESP8266 27 | * Add overloaded constructors for convenience 28 | * Add chainable setters for server/callback/client/stream 29 | * Add state function to return connack return code 30 | 31 | 1.9 32 | * Do not split MQTT packets over multiple calls to _client->write() 33 | * API change: All constructors now require an instance of Client 34 | to be passed in. 35 | * Fixed example to match 1.8 api changes - dpslwk 36 | * Added username/password support - WilHall 37 | * Added publish_P - publishes messages from PROGMEM - jobytaffey 38 | 39 | 1.8 40 | * KeepAlive interval is configurable in PubSubClient.h 41 | * Maximum packet size is configurable in PubSubClient.h 42 | * API change: Return boolean rather than int from various functions 43 | * API change: Length parameter in message callback changed 44 | from int to unsigned int 45 | * Various internal tidy-ups around types 46 | 1.7 47 | * Improved keepalive handling 48 | * Updated to the Arduino-1.0 API 49 | 1.6 50 | * Added the ability to publish a retained message 51 | 52 | 1.5 53 | * Added default constructor 54 | * Fixed compile error when used with arduino-0021 or later 55 | 56 | 1.4 57 | * Fixed connection lost handling 58 | 59 | 1.3 60 | * Fixed packet reading bug in PubSubClient.readPacket 61 | 62 | 1.2 63 | * Fixed compile error when used with arduino-0016 or later 64 | 65 | 66 | 1.1 67 | * Reduced size of library 68 | * Added support for Will messages 69 | * Clarified licensing - see LICENSE.txt 70 | 71 | 72 | 1.0 73 | * Only Quality of Service (QOS) 0 messaging is supported 74 | * The maximum message size, including header, is 128 bytes 75 | * The keepalive interval is set to 30 seconds 76 | * No support for Will messages 77 | -------------------------------------------------------------------------------- /libraries/PubSubClient/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2015 Nicholas O'Leary 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /libraries/PubSubClient/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Client for MQTT 2 | 3 | This library provides a client for doing simple publish/subscribe messaging with 4 | a server that supports MQTT. 5 | 6 | ## Examples 7 | 8 | The library comes with a number of example sketches. See File > Examples > PubSubClient 9 | within the Arduino application. 10 | 11 | Full API documentation is available here: https://pubsubclient.knolleary.net 12 | 13 | ## Limitations 14 | 15 | - It can only publish QoS 0 messages. It can subscribe at QoS 0 or QoS 1. 16 | - The maximum message size, including header, is **128 bytes** by default. This 17 | is configurable via `MQTT_MAX_PACKET_SIZE` in `PubSubClient.h`. 18 | - The keepalive interval is set to 15 seconds by default. This is configurable 19 | via `MQTT_KEEPALIVE` in `PubSubClient.h`. 20 | - The client uses MQTT 3.1.1 by default. It can be changed to use MQTT 3.1 by 21 | changing value of `MQTT_VERSION` in `PubSubClient.h`. 22 | 23 | 24 | ## Compatible Hardware 25 | 26 | The library uses the Arduino Ethernet Client api for interacting with the 27 | underlying network hardware. This means it Just Works with a growing number of 28 | boards and shields, including: 29 | 30 | - Arduino Ethernet 31 | - Arduino Ethernet Shield 32 | - Arduino YUN – use the included `YunClient` in place of `EthernetClient`, and 33 | be sure to do a `Bridge.begin()` first 34 | - Arduino WiFi Shield - if you want to send packets > 90 bytes with this shield, 35 | enable the `MQTT_MAX_TRANSFER_SIZE` define in `PubSubClient.h`. 36 | - Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly) 37 | - TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library) 38 | - Intel Galileo/Edison 39 | - ESP8266 40 | - ESP32 41 | 42 | The library cannot currently be used with hardware based on the ENC28J60 chip – 43 | such as the Nanode or the Nuelectronics Ethernet Shield. For those, there is an 44 | [alternative library](https://github.com/njh/NanodeMQTT) available. 45 | 46 | ## License 47 | 48 | This code is released under the MIT License. 49 | -------------------------------------------------------------------------------- /libraries/PubSubClient/examples/mqtt_auth/mqtt_auth.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic MQTT example with Authentication 3 | 4 | - connects to an MQTT server, providing username 5 | and password 6 | - publishes "hello world" to the topic "outTopic" 7 | - subscribes to the topic "inTopic" 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | // Update these with values suitable for your network. 15 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 16 | IPAddress ip(172, 16, 0, 100); 17 | IPAddress server(172, 16, 0, 2); 18 | 19 | void callback(char* topic, byte* payload, unsigned int length) { 20 | // handle message arrived 21 | } 22 | 23 | EthernetClient ethClient; 24 | PubSubClient client(server, 1883, callback, ethClient); 25 | 26 | void setup() 27 | { 28 | Ethernet.begin(mac, ip); 29 | // Note - the default maximum packet size is 128 bytes. If the 30 | // combined length of clientId, username and password exceed this, 31 | // you will need to increase the value of MQTT_MAX_PACKET_SIZE in 32 | // PubSubClient.h 33 | 34 | if (client.connect("arduinoClient", "testuser", "testpass")) { 35 | client.publish("outTopic","hello world"); 36 | client.subscribe("inTopic"); 37 | } 38 | } 39 | 40 | void loop() 41 | { 42 | client.loop(); 43 | } 44 | -------------------------------------------------------------------------------- /libraries/PubSubClient/examples/mqtt_basic/mqtt_basic.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic MQTT example 3 | 4 | This sketch demonstrates the basic capabilities of the library. 5 | It connects to an MQTT server then: 6 | - publishes "hello world" to the topic "outTopic" 7 | - subscribes to the topic "inTopic", printing out any messages 8 | it receives. NB - it assumes the received payloads are strings not binary 9 | 10 | It will reconnect to the server if the connection is lost using a blocking 11 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 12 | achieve the same result without blocking the main loop. 13 | 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // Update these with values suitable for your network. 21 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 22 | IPAddress ip(172, 16, 0, 100); 23 | IPAddress server(172, 16, 0, 2); 24 | 25 | void callback(char* topic, byte* payload, unsigned int length) { 26 | Serial.print("Message arrived ["); 27 | Serial.print(topic); 28 | Serial.print("] "); 29 | for (int i=0;i Preferences -> Additional Boards Manager URLs": 20 | http://arduino.esp8266.com/stable/package_esp8266com_index.json 21 | - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266" 22 | - Select your ESP8266 in "Tools -> Board" 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | // Update these with values suitable for your network. 30 | 31 | const char* ssid = "........"; 32 | const char* password = "........"; 33 | const char* mqtt_server = "broker.mqtt-dashboard.com"; 34 | 35 | WiFiClient espClient; 36 | PubSubClient client(espClient); 37 | long lastMsg = 0; 38 | char msg[50]; 39 | int value = 0; 40 | 41 | void setup_wifi() { 42 | 43 | delay(10); 44 | // We start by connecting to a WiFi network 45 | Serial.println(); 46 | Serial.print("Connecting to "); 47 | Serial.println(ssid); 48 | 49 | WiFi.begin(ssid, password); 50 | 51 | while (WiFi.status() != WL_CONNECTED) { 52 | delay(500); 53 | Serial.print("."); 54 | } 55 | 56 | randomSeed(micros()); 57 | 58 | Serial.println(""); 59 | Serial.println("WiFi connected"); 60 | Serial.println("IP address: "); 61 | Serial.println(WiFi.localIP()); 62 | } 63 | 64 | void callback(char* topic, byte* payload, unsigned int length) { 65 | Serial.print("Message arrived ["); 66 | Serial.print(topic); 67 | Serial.print("] "); 68 | for (int i = 0; i < length; i++) { 69 | Serial.print((char)payload[i]); 70 | } 71 | Serial.println(); 72 | 73 | // Switch on the LED if an 1 was received as first character 74 | if ((char)payload[0] == '1') { 75 | digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level 76 | // but actually the LED is on; this is because 77 | // it is active low on the ESP-01) 78 | } else { 79 | digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH 80 | } 81 | 82 | } 83 | 84 | void reconnect() { 85 | // Loop until we're reconnected 86 | while (!client.connected()) { 87 | Serial.print("Attempting MQTT connection..."); 88 | // Create a random client ID 89 | String clientId = "ESP8266Client-"; 90 | clientId += String(random(0xffff), HEX); 91 | // Attempt to connect 92 | if (client.connect(clientId.c_str())) { 93 | Serial.println("connected"); 94 | // Once connected, publish an announcement... 95 | client.publish("outTopic", "hello world"); 96 | // ... and resubscribe 97 | client.subscribe("inTopic"); 98 | } else { 99 | Serial.print("failed, rc="); 100 | Serial.print(client.state()); 101 | Serial.println(" try again in 5 seconds"); 102 | // Wait 5 seconds before retrying 103 | delay(5000); 104 | } 105 | } 106 | } 107 | 108 | void setup() { 109 | pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output 110 | Serial.begin(115200); 111 | setup_wifi(); 112 | client.setServer(mqtt_server, 1883); 113 | client.setCallback(callback); 114 | } 115 | 116 | void loop() { 117 | 118 | if (!client.connected()) { 119 | reconnect(); 120 | } 121 | client.loop(); 122 | 123 | long now = millis(); 124 | if (now - lastMsg > 2000) { 125 | lastMsg = now; 126 | ++value; 127 | snprintf (msg, 50, "hello world #%ld", value); 128 | Serial.print("Publish message: "); 129 | Serial.println(msg); 130 | client.publish("outTopic", msg); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /libraries/PubSubClient/examples/mqtt_publish_in_callback/mqtt_publish_in_callback.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Publishing in the callback 3 | 4 | - connects to an MQTT server 5 | - subscribes to the topic "inTopic" 6 | - when a message is received, republishes it to "outTopic" 7 | 8 | This example shows how to publish messages within the 9 | callback function. The callback function header needs to 10 | be declared before the PubSubClient constructor and the 11 | actual callback defined afterwards. 12 | This ensures the client reference in the callback function 13 | is valid. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | // Update these with values suitable for your network. 22 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 23 | IPAddress ip(172, 16, 0, 100); 24 | IPAddress server(172, 16, 0, 2); 25 | 26 | // Callback function header 27 | void callback(char* topic, byte* payload, unsigned int length); 28 | 29 | EthernetClient ethClient; 30 | PubSubClient client(server, 1883, callback, ethClient); 31 | 32 | // Callback function 33 | void callback(char* topic, byte* payload, unsigned int length) { 34 | // In order to republish this payload, a copy must be made 35 | // as the orignal payload buffer will be overwritten whilst 36 | // constructing the PUBLISH packet. 37 | 38 | // Allocate the correct amount of memory for the payload copy 39 | byte* p = (byte*)malloc(length); 40 | // Copy the payload to the new buffer 41 | memcpy(p,payload,length); 42 | client.publish("outTopic", p, length); 43 | // Free the memory 44 | free(p); 45 | } 46 | 47 | void setup() 48 | { 49 | 50 | Ethernet.begin(mac, ip); 51 | if (client.connect("arduinoClient")) { 52 | client.publish("outTopic","hello world"); 53 | client.subscribe("inTopic"); 54 | } 55 | } 56 | 57 | void loop() 58 | { 59 | client.loop(); 60 | } 61 | -------------------------------------------------------------------------------- /libraries/PubSubClient/examples/mqtt_reconnect_nonblocking/mqtt_reconnect_nonblocking.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reconnecting MQTT example - non-blocking 3 | 4 | This sketch demonstrates how to keep the client connected 5 | using a non-blocking reconnect function. If the client loses 6 | its connection, it attempts to reconnect every 5 seconds 7 | without blocking the main loop. 8 | 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | // Update these with values suitable for your hardware/network. 16 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 17 | IPAddress ip(172, 16, 0, 100); 18 | IPAddress server(172, 16, 0, 2); 19 | 20 | void callback(char* topic, byte* payload, unsigned int length) { 21 | // handle message arrived 22 | } 23 | 24 | EthernetClient ethClient; 25 | PubSubClient client(ethClient); 26 | 27 | long lastReconnectAttempt = 0; 28 | 29 | boolean reconnect() { 30 | if (client.connect("arduinoClient")) { 31 | // Once connected, publish an announcement... 32 | client.publish("outTopic","hello world"); 33 | // ... and resubscribe 34 | client.subscribe("inTopic"); 35 | } 36 | return client.connected(); 37 | } 38 | 39 | void setup() 40 | { 41 | client.setServer(server, 1883); 42 | client.setCallback(callback); 43 | 44 | Ethernet.begin(mac, ip); 45 | delay(1500); 46 | lastReconnectAttempt = 0; 47 | } 48 | 49 | 50 | void loop() 51 | { 52 | if (!client.connected()) { 53 | long now = millis(); 54 | if (now - lastReconnectAttempt > 5000) { 55 | lastReconnectAttempt = now; 56 | // Attempt to reconnect 57 | if (reconnect()) { 58 | lastReconnectAttempt = 0; 59 | } 60 | } 61 | } else { 62 | // Client connected 63 | 64 | client.loop(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /libraries/PubSubClient/examples/mqtt_stream/mqtt_stream.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example of using a Stream object to store the message payload 3 | 4 | Uses SRAM library: https://github.com/ennui2342/arduino-sram 5 | but could use any Stream based class such as SD 6 | 7 | - connects to an MQTT server 8 | - publishes "hello world" to the topic "outTopic" 9 | - subscribes to the topic "inTopic" 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // Update these with values suitable for your network. 18 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 19 | IPAddress ip(172, 16, 0, 100); 20 | IPAddress server(172, 16, 0, 2); 21 | 22 | SRAM sram(4, SRAM_1024); 23 | 24 | void callback(char* topic, byte* payload, unsigned int length) { 25 | sram.seek(1); 26 | 27 | // do something with the message 28 | for(uint8_t i=0; i 4 | maintainer=Nick O'Leary 5 | sentence=A client library for MQTT messaging. 6 | paragraph=MQTT is a lightweight messaging protocol ideal for small devices. This library allows you to send and receive MQTT messages. It supports the latest MQTT 3.1.1 protocol and can be configured to use the older MQTT 3.1 if needed. It supports all Arduino Ethernet Client compatible hardware, including the Intel Galileo/Edison, ESP8266 and TI CC3000. 7 | category=Communication 8 | url=http://pubsubclient.knolleary.net 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/Makefile: -------------------------------------------------------------------------------- 1 | SRC_PATH=./src 2 | OUT_PATH=./bin 3 | TEST_SRC=$(wildcard ${SRC_PATH}/*_spec.cpp) 4 | TEST_BIN= $(TEST_SRC:${SRC_PATH}/%.cpp=${OUT_PATH}/%) 5 | VPATH=${SRC_PATH} 6 | SHIM_FILES=${SRC_PATH}/lib/*.cpp 7 | PSC_FILE=../src/PubSubClient.cpp 8 | CC=g++ 9 | CFLAGS=-I${SRC_PATH}/lib -I../src 10 | 11 | all: $(TEST_BIN) 12 | 13 | ${OUT_PATH}/%: ${SRC_PATH}/%.cpp ${PSC_FILE} ${SHIM_FILES} 14 | mkdir -p ${OUT_PATH} 15 | ${CC} ${CFLAGS} $^ -o $@ 16 | 17 | clean: 18 | @rm -rf ${OUT_PATH} 19 | 20 | test: 21 | @bin/connect_spec 22 | @bin/publish_spec 23 | @bin/receive_spec 24 | @bin/subscribe_spec 25 | @bin/keepalive_spec 26 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Client for MQTT Test Suite 2 | 3 | This is a regression test suite for the `PubSubClient` library. 4 | 5 | There are two parts: 6 | 7 | - Tests that can be compiled and run on any machine 8 | - Tests that build the example sketches using the Arduino IDE 9 | 10 | 11 | It is a work-in-progress and is subject to complete refactoring as the whim takes 12 | me. 13 | 14 | 15 | ## Local tests 16 | 17 | These are a set of executables that can be run to test specific areas of functionality. 18 | They do not require a real Arduino to be attached, nor the use of the Arduino IDE. 19 | 20 | The tests include a set of mock files to stub out the parts of the Arduino environment the library 21 | depends on. 22 | 23 | ### Dependencies 24 | 25 | - g++ 26 | 27 | ### Running 28 | 29 | Build the tests using the provided `Makefile`: 30 | 31 | $ make 32 | 33 | This will create a set of executables in `./bin/`. Run each of these executables to test the corresponding functionality. 34 | 35 | *Note:* the `connect_spec` and `keepalive_spec` tests involve testing keepalive timers so naturally take a few minutes to run through. 36 | 37 | ## Arduino tests 38 | 39 | *Note:* INO Tool doesn't currently play nicely with Arduino 1.5. This has broken this test suite. 40 | 41 | Without a suitable arduino plugged in, the test suite will only check the 42 | example sketches compile cleanly against the library. 43 | 44 | With an arduino plugged in, each sketch that has a corresponding python 45 | test case is built, uploaded and then the tests run. 46 | 47 | ### Dependencies 48 | 49 | - Python 2.7+ 50 | - [INO Tool](http://inotool.org/) - this provides command-line build/upload of Arduino sketches 51 | 52 | ### Running 53 | 54 | The test suite _does not_ run an MQTT server - it is assumed to be running already. 55 | 56 | $ python testsuite.py 57 | 58 | A summary of activity is printed to the console. More comprehensive logs are written 59 | to the `logs` directory. 60 | 61 | ### What it does 62 | 63 | For each sketch in the library's `examples` directory, e.g. `mqtt_basic.ino`, the suite looks for a matching test case 64 | `testcases/mqtt_basic.py`. 65 | 66 | The test case must follow these conventions: 67 | - sub-class `unittest.TestCase` 68 | - provide the class methods `setUpClass` and `tearDownClass` (TODO: make this optional) 69 | - all test method names begin with `test_` 70 | 71 | The suite will call the `setUpClass` method _before_ uploading the sketch. This 72 | allows any test setup to be performed before the sketch runs - such as connecting 73 | a client and subscribing to topics. 74 | 75 | 76 | ### Settings 77 | 78 | The file `testcases/settings.py` is used to config the test environment. 79 | 80 | - `server_ip` - the IP address of the broker the client should connect to (the broker port is assumed to be 1883). 81 | - `arduino_ip` - the IP address the arduino should use (when not testing DHCP). 82 | 83 | Before each sketch is compiled, these values are automatically substituted in. To 84 | do this, the suite looks for lines that _start_ with the following: 85 | 86 | byte server[] = { 87 | byte ip[] = { 88 | 89 | and replaces them with the appropriate values. 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/Arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Arduino_h 2 | #define Arduino_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Print.h" 9 | 10 | 11 | extern "C"{ 12 | typedef uint8_t byte ; 13 | typedef uint8_t boolean ; 14 | 15 | /* sketch */ 16 | extern void setup( void ) ; 17 | extern void loop( void ) ; 18 | uint32_t millis( void ); 19 | } 20 | 21 | #define PROGMEM 22 | #define pgm_read_byte_near(x) *(x) 23 | 24 | #define yield(x) {} 25 | 26 | #endif // Arduino_h 27 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/BDDTest.cpp: -------------------------------------------------------------------------------- 1 | #include "BDDTest.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int testCount = 0; 9 | int testPasses = 0; 10 | const char* testDescription; 11 | 12 | std::list failureList; 13 | 14 | void bddtest_suite(const char* name) { 15 | LOG(name << "\n"); 16 | } 17 | 18 | int bddtest_test(const char* file, int line, const char* assertion, int result) { 19 | if (!result) { 20 | LOG("✗\n"); 21 | std::ostringstream os; 22 | os << " ! "<::iterator it = failureList.begin(); it != failureList.end(); it++) { 40 | LOG("\n"); 41 | LOG(*it); 42 | LOG("\n"); 43 | } 44 | 45 | LOG(std::dec << testPasses << "/" << testCount << " tests passed\n\n"); 46 | if (testPasses == testCount) { 47 | return 0; 48 | } 49 | return 1; 50 | } 51 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/BDDTest.h: -------------------------------------------------------------------------------- 1 | #ifndef bddtest_h 2 | #define bddtest_h 3 | 4 | void bddtest_suite(const char* name); 5 | int bddtest_test(const char*, int, const char*, int); 6 | void bddtest_start(const char*); 7 | void bddtest_end(); 8 | int bddtest_summary(); 9 | 10 | #define SUITE(x) { bddtest_suite(x); } 11 | #define TEST(x) { if (!bddtest_test(__FILE__, __LINE__, #x, (x))) return false; } 12 | 13 | #define IT(x) { bddtest_start(x); } 14 | #define END_IT { bddtest_end();return true;} 15 | 16 | #define FINISH { return bddtest_summary(); } 17 | 18 | #define IS_TRUE(x) TEST(x) 19 | #define IS_FALSE(x) TEST(!(x)) 20 | #define IS_EQUAL(x,y) TEST(x==y) 21 | #define IS_NOT_EQUAL(x,y) TEST(x!=y) 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/Buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "Buffer.h" 2 | #include "Arduino.h" 3 | 4 | Buffer::Buffer() { 5 | this->pos = 0; 6 | this->length = 0; 7 | } 8 | 9 | Buffer::Buffer(uint8_t* buf, size_t size) { 10 | this->pos = 0; 11 | this->length = 0; 12 | this->add(buf,size); 13 | } 14 | bool Buffer::available() { 15 | return this->pos < this->length; 16 | } 17 | 18 | uint8_t Buffer::next() { 19 | if (this->available()) { 20 | return this->buffer[this->pos++]; 21 | } 22 | return 0; 23 | } 24 | 25 | void Buffer::reset() { 26 | this->pos = 0; 27 | } 28 | 29 | void Buffer::add(uint8_t* buf, size_t size) { 30 | uint16_t i = 0; 31 | for (;ibuffer[this->length++] = buf[i]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/Buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef buffer_h 2 | #define buffer_h 3 | 4 | #include "Arduino.h" 5 | 6 | class Buffer { 7 | private: 8 | uint8_t buffer[1024]; 9 | uint16_t pos; 10 | uint16_t length; 11 | 12 | public: 13 | Buffer(); 14 | Buffer(uint8_t* buf, size_t size); 15 | 16 | virtual bool available(); 17 | virtual uint8_t next(); 18 | virtual void reset(); 19 | 20 | virtual void add(uint8_t* buf, size_t size); 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/Client.h: -------------------------------------------------------------------------------- 1 | #ifndef client_h 2 | #define client_h 3 | #include "IPAddress.h" 4 | 5 | class Client { 6 | public: 7 | virtual int connect(IPAddress ip, uint16_t port) =0; 8 | virtual int connect(const char *host, uint16_t port) =0; 9 | virtual size_t write(uint8_t) =0; 10 | virtual size_t write(const uint8_t *buf, size_t size) =0; 11 | virtual int available() = 0; 12 | virtual int read() = 0; 13 | virtual int read(uint8_t *buf, size_t size) = 0; 14 | virtual int peek() = 0; 15 | virtual void flush() = 0; 16 | virtual void stop() = 0; 17 | virtual uint8_t connected() = 0; 18 | virtual operator bool() = 0; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | IPAddress::IPAddress() 6 | { 7 | memset(_address, 0, sizeof(_address)); 8 | } 9 | 10 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 11 | { 12 | _address[0] = first_octet; 13 | _address[1] = second_octet; 14 | _address[2] = third_octet; 15 | _address[3] = fourth_octet; 16 | } 17 | 18 | IPAddress::IPAddress(uint32_t address) 19 | { 20 | memcpy(_address, &address, sizeof(_address)); 21 | } 22 | 23 | IPAddress::IPAddress(const uint8_t *address) 24 | { 25 | memcpy(_address, address, sizeof(_address)); 26 | } 27 | 28 | IPAddress& IPAddress::operator=(const uint8_t *address) 29 | { 30 | memcpy(_address, address, sizeof(_address)); 31 | return *this; 32 | } 33 | 34 | IPAddress& IPAddress::operator=(uint32_t address) 35 | { 36 | memcpy(_address, (const uint8_t *)&address, sizeof(_address)); 37 | return *this; 38 | } 39 | 40 | bool IPAddress::operator==(const uint8_t* addr) 41 | { 42 | return memcmp(addr, _address, sizeof(_address)) == 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MIT License: 4 | * Copyright (c) 2011 Adrian McEwen 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | * 23 | * adrianm@mcqn.com 1/1/2011 24 | */ 25 | 26 | #ifndef IPAddress_h 27 | #define IPAddress_h 28 | 29 | 30 | // A class to make it easier to handle and pass around IP addresses 31 | 32 | class IPAddress { 33 | private: 34 | uint8_t _address[4]; // IPv4 address 35 | // Access the raw byte array containing the address. Because this returns a pointer 36 | // to the internal structure rather than a copy of the address this function should only 37 | // be used when you know that the usage of the returned uint8_t* will be transient and not 38 | // stored. 39 | uint8_t* raw_address() { return _address; }; 40 | 41 | public: 42 | // Constructors 43 | IPAddress(); 44 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 45 | IPAddress(uint32_t address); 46 | IPAddress(const uint8_t *address); 47 | 48 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 49 | // to a four-byte uint8_t array is expected 50 | operator uint32_t() { return *((uint32_t*)_address); }; 51 | bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; 52 | bool operator==(const uint8_t* addr); 53 | 54 | // Overloaded index operator to allow getting and setting individual octets of the address 55 | uint8_t operator[](int index) const { return _address[index]; }; 56 | uint8_t& operator[](int index) { return _address[index]; }; 57 | 58 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 59 | IPAddress& operator=(const uint8_t *address); 60 | IPAddress& operator=(uint32_t address); 61 | 62 | 63 | friend class EthernetClass; 64 | friend class UDP; 65 | friend class Client; 66 | friend class Server; 67 | friend class DhcpClass; 68 | friend class DNSClient; 69 | }; 70 | 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | class Print { 24 | public: 25 | virtual size_t write(uint8_t) = 0; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/ShimClient.cpp: -------------------------------------------------------------------------------- 1 | #include "ShimClient.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | #include 6 | 7 | extern "C" { 8 | uint32_t millis(void) { 9 | return time(0)*1000; 10 | } 11 | } 12 | 13 | ShimClient::ShimClient() { 14 | this->responseBuffer = new Buffer(); 15 | this->expectBuffer = new Buffer(); 16 | this->_allowConnect = true; 17 | this->_connected = false; 18 | this->_error = false; 19 | this->expectAnything = true; 20 | this->_received = 0; 21 | this->_expectedPort = 0; 22 | } 23 | 24 | int ShimClient::connect(IPAddress ip, uint16_t port) { 25 | if (this->_allowConnect) { 26 | this->_connected = true; 27 | } 28 | if (this->_expectedPort !=0) { 29 | // if (memcmp(ip,this->_expectedIP,4) != 0) { 30 | // TRACE( "ip mismatch\n"); 31 | // this->_error = true; 32 | // } 33 | if (port != this->_expectedPort) { 34 | TRACE( "port mismatch\n"); 35 | this->_error = true; 36 | } 37 | } 38 | return this->_connected; 39 | } 40 | int ShimClient::connect(const char *host, uint16_t port) { 41 | if (this->_allowConnect) { 42 | this->_connected = true; 43 | } 44 | if (this->_expectedPort !=0) { 45 | if (strcmp(host,this->_expectedHost) != 0) { 46 | TRACE( "host mismatch\n"); 47 | this->_error = true; 48 | } 49 | if (port != this->_expectedPort) { 50 | TRACE( "port mismatch\n"); 51 | this->_error = true; 52 | } 53 | 54 | } 55 | return this->_connected; 56 | } 57 | size_t ShimClient::write(uint8_t b) { 58 | this->_received += 1; 59 | TRACE(std::hex << (unsigned int)b); 60 | if (!this->expectAnything) { 61 | if (this->expectBuffer->available()) { 62 | uint8_t expected = this->expectBuffer->next(); 63 | if (expected != b) { 64 | this->_error = true; 65 | TRACE("!=" << (unsigned int)expected); 66 | } 67 | } else { 68 | this->_error = true; 69 | } 70 | } 71 | TRACE("\n"<< std::dec); 72 | return 1; 73 | } 74 | size_t ShimClient::write(const uint8_t *buf, size_t size) { 75 | this->_received += size; 76 | TRACE( "[" << std::dec << (unsigned int)(size) << "] "); 77 | uint16_t i=0; 78 | for (;i0) { 80 | TRACE(":"); 81 | } 82 | TRACE(std::hex << (unsigned int)(buf[i])); 83 | 84 | if (!this->expectAnything) { 85 | if (this->expectBuffer->available()) { 86 | uint8_t expected = this->expectBuffer->next(); 87 | if (expected != buf[i]) { 88 | this->_error = true; 89 | TRACE("!=" << (unsigned int)expected); 90 | } 91 | } else { 92 | this->_error = true; 93 | } 94 | } 95 | } 96 | TRACE("\n"<responseBuffer->available(); 101 | } 102 | int ShimClient::read() { return this->responseBuffer->next(); } 103 | int ShimClient::read(uint8_t *buf, size_t size) { 104 | uint16_t i = 0; 105 | for (;iread(); 107 | } 108 | return size; 109 | } 110 | int ShimClient::peek() { return 0; } 111 | void ShimClient::flush() {} 112 | void ShimClient::stop() { 113 | this->setConnected(false); 114 | } 115 | uint8_t ShimClient::connected() { return this->_connected; } 116 | ShimClient::operator bool() { return true; } 117 | 118 | 119 | ShimClient* ShimClient::respond(uint8_t *buf, size_t size) { 120 | this->responseBuffer->add(buf,size); 121 | return this; 122 | } 123 | 124 | ShimClient* ShimClient::expect(uint8_t *buf, size_t size) { 125 | this->expectAnything = false; 126 | this->expectBuffer->add(buf,size); 127 | return this; 128 | } 129 | 130 | void ShimClient::setConnected(bool b) { 131 | this->_connected = b; 132 | } 133 | void ShimClient::setAllowConnect(bool b) { 134 | this->_allowConnect = b; 135 | } 136 | 137 | bool ShimClient::error() { 138 | return this->_error; 139 | } 140 | 141 | uint16_t ShimClient::received() { 142 | return this->_received; 143 | } 144 | 145 | void ShimClient::expectConnect(IPAddress ip, uint16_t port) { 146 | this->_expectedIP = ip; 147 | this->_expectedPort = port; 148 | } 149 | 150 | void ShimClient::expectConnect(const char *host, uint16_t port) { 151 | this->_expectedHost = host; 152 | this->_expectedPort = port; 153 | } 154 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/ShimClient.h: -------------------------------------------------------------------------------- 1 | #ifndef shimclient_h 2 | #define shimclient_h 3 | 4 | #include "Arduino.h" 5 | #include "Client.h" 6 | #include "IPAddress.h" 7 | #include "Buffer.h" 8 | 9 | 10 | class ShimClient : public Client { 11 | private: 12 | Buffer* responseBuffer; 13 | Buffer* expectBuffer; 14 | bool _allowConnect; 15 | bool _connected; 16 | bool expectAnything; 17 | bool _error; 18 | uint16_t _received; 19 | IPAddress _expectedIP; 20 | uint16_t _expectedPort; 21 | const char* _expectedHost; 22 | 23 | public: 24 | ShimClient(); 25 | virtual int connect(IPAddress ip, uint16_t port); 26 | virtual int connect(const char *host, uint16_t port); 27 | virtual size_t write(uint8_t); 28 | virtual size_t write(const uint8_t *buf, size_t size); 29 | virtual int available(); 30 | virtual int read(); 31 | virtual int read(uint8_t *buf, size_t size); 32 | virtual int peek(); 33 | virtual void flush(); 34 | virtual void stop(); 35 | virtual uint8_t connected(); 36 | virtual operator bool(); 37 | 38 | virtual ShimClient* respond(uint8_t *buf, size_t size); 39 | virtual ShimClient* expect(uint8_t *buf, size_t size); 40 | 41 | virtual void expectConnect(IPAddress ip, uint16_t port); 42 | virtual void expectConnect(const char *host, uint16_t port); 43 | 44 | virtual uint16_t received(); 45 | virtual bool error(); 46 | 47 | virtual void setAllowConnect(bool b); 48 | virtual void setConnected(bool b); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/Stream.cpp: -------------------------------------------------------------------------------- 1 | #include "Stream.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | 6 | Stream::Stream() { 7 | this->expectBuffer = new Buffer(); 8 | this->_error = false; 9 | this->_written = 0; 10 | } 11 | 12 | size_t Stream::write(uint8_t b) { 13 | this->_written++; 14 | TRACE(std::hex << (unsigned int)b); 15 | if (this->expectBuffer->available()) { 16 | uint8_t expected = this->expectBuffer->next(); 17 | if (expected != b) { 18 | this->_error = true; 19 | TRACE("!=" << (unsigned int)expected); 20 | } 21 | } else { 22 | this->_error = true; 23 | } 24 | TRACE("\n"<< std::dec); 25 | return 1; 26 | } 27 | 28 | 29 | bool Stream::error() { 30 | return this->_error; 31 | } 32 | 33 | void Stream::expect(uint8_t *buf, size_t size) { 34 | this->expectBuffer->add(buf,size); 35 | } 36 | 37 | uint16_t Stream::length() { 38 | return this->_written; 39 | } 40 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/Stream.h: -------------------------------------------------------------------------------- 1 | #ifndef Stream_h 2 | #define Stream_h 3 | 4 | #include "Arduino.h" 5 | #include "Buffer.h" 6 | 7 | class Stream { 8 | private: 9 | Buffer* expectBuffer; 10 | bool _error; 11 | uint16_t _written; 12 | 13 | public: 14 | Stream(); 15 | virtual size_t write(uint8_t); 16 | 17 | virtual bool error(); 18 | virtual void expect(uint8_t *buf, size_t size); 19 | virtual uint16_t length(); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/src/lib/trace.h: -------------------------------------------------------------------------------- 1 | #ifndef trace_h 2 | #define trace_h 3 | #include 4 | 5 | #include 6 | 7 | #define LOG(x) {std::cout << x << std::flush; } 8 | #define TRACE(x) {if (getenv("TRACE")) { std::cout << x << std::flush; }} 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/testcases/mqtt_basic.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import settings 3 | import time 4 | import mosquitto 5 | 6 | 7 | def on_message(mosq, obj, msg): 8 | obj.message_queue.append(msg) 9 | 10 | 11 | class mqtt_basic(unittest.TestCase): 12 | 13 | message_queue = [] 14 | 15 | @classmethod 16 | def setUpClass(self): 17 | self.client = mosquitto.Mosquitto("pubsubclient_ut", clean_session=True, obj=self) 18 | self.client.connect(settings.server_ip) 19 | self.client.on_message = on_message 20 | self.client.subscribe("outTopic", 0) 21 | 22 | @classmethod 23 | def tearDownClass(self): 24 | self.client.disconnect() 25 | 26 | def test_one(self): 27 | i = 30 28 | while len(self.message_queue) == 0 and i > 0: 29 | self.client.loop() 30 | time.sleep(0.5) 31 | i -= 1 32 | self.assertTrue(i > 0, "message receive timed-out") 33 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 34 | msg = self.message_queue[0] 35 | self.assertEqual(msg.mid, 0, "message id not 0") 36 | self.assertEqual(msg.topic, "outTopic", "message topic incorrect") 37 | self.assertEqual(msg.payload, "hello world") 38 | self.assertEqual(msg.qos, 0, "message qos not 0") 39 | self.assertEqual(msg.retain, False, "message retain flag incorrect") 40 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/testcases/mqtt_publish_in_callback.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import settings 3 | import time 4 | import mosquitto 5 | 6 | 7 | def on_message(mosq, obj, msg): 8 | obj.message_queue.append(msg) 9 | 10 | 11 | class mqtt_publish_in_callback(unittest.TestCase): 12 | 13 | message_queue = [] 14 | 15 | @classmethod 16 | def setUpClass(self): 17 | self.client = mosquitto.Mosquitto("pubsubclient_ut", clean_session=True, obj=self) 18 | self.client.connect(settings.server_ip) 19 | self.client.on_message = on_message 20 | self.client.subscribe("outTopic", 0) 21 | 22 | @classmethod 23 | def tearDownClass(self): 24 | self.client.disconnect() 25 | 26 | def test_connect(self): 27 | i = 30 28 | while len(self.message_queue) == 0 and i > 0: 29 | self.client.loop() 30 | time.sleep(0.5) 31 | i -= 1 32 | self.assertTrue(i > 0, "message receive timed-out") 33 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 34 | msg = self.message_queue.pop(0) 35 | self.assertEqual(msg.mid, 0, "message id not 0") 36 | self.assertEqual(msg.topic, "outTopic", "message topic incorrect") 37 | self.assertEqual(msg.payload, "hello world") 38 | self.assertEqual(msg.qos, 0, "message qos not 0") 39 | self.assertEqual(msg.retain, False, "message retain flag incorrect") 40 | 41 | def test_publish(self): 42 | self.assertEqual(len(self.message_queue), 0, "message queue not empty") 43 | payload = "abcdefghij" 44 | self.client.publish("inTopic", payload) 45 | 46 | i = 30 47 | while len(self.message_queue) == 0 and i > 0: 48 | self.client.loop() 49 | time.sleep(0.5) 50 | i -= 1 51 | 52 | self.assertTrue(i > 0, "message receive timed-out") 53 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 54 | msg = self.message_queue.pop(0) 55 | self.assertEqual(msg.mid, 0, "message id not 0") 56 | self.assertEqual(msg.topic, "outTopic", "message topic incorrect") 57 | self.assertEqual(msg.payload, payload) 58 | self.assertEqual(msg.qos, 0, "message qos not 0") 59 | self.assertEqual(msg.retain, False, "message retain flag incorrect") 60 | -------------------------------------------------------------------------------- /libraries/PubSubClient/tests/testcases/settings.py: -------------------------------------------------------------------------------- 1 | server_ip = "172.16.0.2" 2 | arduino_ip = "172.16.0.100" 3 | -------------------------------------------------------------------------------- /libraries/readme.md: -------------------------------------------------------------------------------- 1 | 如果有下载不下里的库 2 | 可以参考这里 3 | -------------------------------------------------------------------------------- /多模式氛围灯/RGBLED/RGBLED.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | // Which pin on the ESP8266 is connected to the NeoPixels? 6 | #define PIN 2 7 | 8 | // How many NeoPixels are attached to the ESP8266? 9 | #define NUMPIXELS 16 10 | 11 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 12 | 13 | int delayval = 500; // delay for half a second 14 | 15 | void setup() { 16 | // put your setup code here, to run once: 17 | pixels.begin(); // This initializes the NeoPixel library. 18 | } 19 | 20 | void loop() { 21 | // put your main code here, to run repeatedly: 22 | for(int i=0;i 5 | #ifdef __AVR__ 6 | #include 7 | #endif 8 | 9 | // Which pin on the Arduino is connected to the NeoPixels? 10 | // On a Trinket or Gemma we suggest changing this to 1 11 | #define PIN 6 12 | 13 | // How many NeoPixels are attached to the Arduino? 14 | #define NUMPIXELS 16 15 | 16 | // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. 17 | // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest 18 | // example for more information on possible values. 19 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 20 | 21 | int delayval = 500; // delay for half a second 22 | 23 | void setup() { 24 | // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket 25 | #if defined (__AVR_ATtiny85__) 26 | if (F_CPU == 16000000) clock_prescale_set(clock_div_1); 27 | #endif 28 | // End of trinket special code 29 | 30 | pixels.begin(); // This initializes the NeoPixel library. 31 | } 32 | 33 | void loop() { 34 | 35 | // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. 36 | 37 | for(int i=0;i 4 | #ifdef __AVR__ 5 | #include 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #define PIN 2 12 | #define NUM_LEDS 8 13 | #define BRIGHTNESS 50 14 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);// RGBW 与RGB在创建灯带时不一样 15 | const char* ssid = "niehen_pc"; 16 | const char* password = "*"; 17 | const char* mqtt_server = "*"; 18 | WiFiClient espClient; 19 | PubSubClient client(espClient); 20 | long lastMsg = 0; 21 | char msg[50]; 22 | int value = 1; 23 | String tmpTopic; 24 | String strplayload; 25 | int bright = 0; 26 | void setup_wifi() { 27 | delay(10); 28 | // We start by connecting to a WiFi network 29 | Serial.println(); 30 | Serial.print("Connecting to "); 31 | Serial.println(ssid); 32 | 33 | WiFi.begin(ssid, password); 34 | while (WiFi.status() != WL_CONNECTED) { 35 | delay(500); 36 | Serial.print("."); 37 | } 38 | 39 | randomSeed(micros()); 40 | Serial.println(WiFi.localIP()); 41 | } 42 | void callback(char* topic, byte* payload, unsigned int length) { 43 | 44 | tmpTopic = String((char *)topic); 45 | payload[length] = '\0'; 46 | strplayload = String((char*)payload); 47 | 48 | 49 | client.publish("led_color/status", "get older "); 50 | if (strplayload == "off") { // 判断是否是off 关闭指令 51 | value = 0; 52 | client.publish("led_color/status", "led_play stop"); 53 | }else { 54 | int isint = 0;// 如果有字母 就为1 全数字就为0 55 | for (int i=0; i< strplayload.length();i++) // 检测接收到的命令里面是否含有 非数字的字符 56 | { 57 | if (!isDigit(strplayload[i])) 58 | { 59 | isint = 1; 60 | break; 61 | } 62 | } 63 | if(isint == 0){ 64 | int older_led = strplayload.toInt() ; // 转换为 int类型 65 | if(older_led >=0 && older_led<=2){ 66 | value = older_led; 67 | char* pub_status = "led_play is running"; 68 | pub_status[19] = '0' + value; 69 | client.publish("led_color/status",pub_status); 70 | 71 | } 72 | } 73 | } 74 | 75 | } 76 | void reconnect() { 77 | // Loop until we're reconnected 78 | while (!client.connected()) { 79 | Serial.print("Attempting MQTT connection..."); 80 | String clientId = "ESP8266Client-"; 81 | clientId += String(random(0xffff), HEX); 82 | if (client.connect(clientId.c_str())) { 83 | Serial.println("connected"); 84 | 85 | client.publish("led_color/status", "init..."); 86 | // ... and resubscribe 87 | client.subscribe("led_color/transform/older"); 88 | } else { 89 | Serial.print("failed, rc="); 90 | Serial.print(client.state()); 91 | Serial.println(" try again in 5 seconds"); 92 | // Wait 5 seconds before retrying 93 | delay(5000); 94 | } 95 | } 96 | } 97 | 98 | void setup() { 99 | Serial.begin(115200); 100 | setup_wifi(); 101 | 102 | client.setServer(mqtt_server, 1883); 103 | client.setCallback(callback); 104 | #if defined (__AVR_ATtiny85__) 105 | if (F_CPU == 16000000) clock_prescale_set(clock_div_1); 106 | #endif 107 | pixels.setBrightness(BRIGHTNESS); 108 | pixels.begin(); 109 | pulseWhite(1,5); 110 | delay(10); 111 | pulseWhite(0,5);// 出现bug 开灯后 有一个灯亮 这是解决办法 112 | } 113 | 114 | void loop() { 115 | if (value == 0){ 116 | pulseWhite(0,20); 117 | }else if(value == 1) 118 | rainbow(20); 119 | else if(value == 2) 120 | rainbowCycle(20); 121 | 122 | if (!client.connected()) { 123 | reconnect(); 124 | } 125 | client.loop(); 126 | 127 | } 128 | 129 | void pulseWhite(uint8_t result,uint8_t wait) { // 第一个参数为要变为的亮度值 第二个参数为变化间隔的时间单位为毫秒 130 | for(uint16_t i=0; i 4 | #include 5 | #include 6 | #include 7 | 8 | // Update these with values suitable for your network. 9 | const char* ssid = "niehen_pc"; 10 | const char* password = "#"; 11 | const char* mqtt_server = "*"; 12 | WiFiClient espClient; 13 | PubSubClient client(espClient); 14 | long lastMsg = 0; 15 | char msg[50]; 16 | int value = 0; 17 | String tmpTopic; 18 | String strplayload; 19 | 20 | #define IR_LED 4 // ESP8266 GPIO pin to use. Recommended: 4 (D2). 21 | 22 | IRsend irsend(IR_LED); // Set the GPIO to be used to sending the message. 23 | char* order_infor[] ={"on","off","tema","tems","warm","cold","winda","winds"}; // 控制的温度 24 | long enc[] ={0xFF30CF,0xFF18E7,0xFF7A85,0xFF10EF,0xFF38C7,0xFF5AA5,0xFF42BD,0xFF4AB5};//发射的红外 十六进制值 自定的 实际需要去获取到要遥控器的发送信号 25 | 26 | void setup() { 27 | //pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output 28 | Serial.begin(115200); 29 | setup_wifi(); 30 | client.setServer(mqtt_server, 1883); 31 | client.setCallback(callback); 32 | 33 | irsend.begin(); 34 | // Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY); 35 | } 36 | 37 | void setup_wifi() { 38 | delay(10); 39 | // We start by connecting to a WiFi network 40 | Serial.println(); 41 | Serial.print("Connecting to "); 42 | Serial.println(ssid); 43 | 44 | WiFi.begin(ssid, password); 45 | 46 | while (WiFi.status() != WL_CONNECTED) { 47 | delay(500); 48 | Serial.print("."); 49 | } 50 | 51 | Serial.println(""); 52 | Serial.println("WiFi connected"); 53 | Serial.println("IP address: "); 54 | Serial.println(WiFi.localIP()); 55 | } 56 | 57 | 58 | 59 | void callback(char* topic, byte* payload, unsigned int length) { 60 | 61 | tmpTopic = String((char *)topic); 62 | payload[length] = '\0'; 63 | strplayload = String((char*)payload); 64 | 65 | client.publish("mp3player/status", "get older "); 66 | 67 | int isint = 0;// 如果有字母 就为1 全数字就为0 68 | for (int i=0; i< strplayload.length();i++) // 检测接收到的命令里面是否含有 非数字的字符 69 | { 70 | if (!isDigit(strplayload[i])) 71 | { 72 | isint = 1; 73 | break; 74 | } 75 | } 76 | if(isint == 0){ 77 | int older_air = strplayload.toInt() ; // 转换为 int类型 78 | if(older_air >=1 && older_air<=8){ 79 | irsend.sendSony(enc[older_air - 1], 12); 80 | client.publish("air_cond/status", "IR remote is running"); 81 | client.publish("air_cond/status", order_infor[older_air -1]); 82 | } 83 | } 84 | 85 | } 86 | 87 | void reconnect() { 88 | // Loop until we're reconnected 89 | while (!client.connected()) { 90 | Serial.print("Attempting MQTT connection..."); 91 | String clientId = "ESP8266Client-"; 92 | clientId += String(random(0xffff), HEX); 93 | if (client.connect(clientId.c_str())) { 94 | Serial.println("connected"); 95 | 96 | client.publish("air_cond/status", "init..."); 97 | // ... and resubscribe 98 | client.subscribe("air_cond/older"); 99 | } else { 100 | Serial.print("failed, rc="); 101 | Serial.print(client.state()); 102 | Serial.println(" try again in 5 seconds"); 103 | // Wait 5 seconds before retrying 104 | delay(5000); 105 | } 106 | } 107 | } 108 | 109 | void loop() { 110 | if (!client.connected()) { 111 | reconnect(); 112 | } 113 | client.loop(); 114 | } 115 | 116 | -------------------------------------------------------------------------------- /智能多级照明灯/RGBLED/RGBLED.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | // Which pin on the ESP8266 is connected to the NeoPixels? 6 | #define PIN 2 7 | 8 | // How many NeoPixels are attached to the ESP8266? 9 | #define NUMPIXELS 16 10 | 11 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 12 | 13 | int delayval = 500; // delay for half a second 14 | 15 | void setup() { 16 | // put your setup code here, to run once: 17 | pixels.begin(); // This initializes the NeoPixel library. 18 | } 19 | 20 | void loop() { 21 | // put your main code here, to run repeatedly: 22 | for(int i=0;i 5 | #ifdef __AVR__ 6 | #include 7 | #endif 8 | 9 | // Which pin on the Arduino is connected to the NeoPixels? 10 | // On a Trinket or Gemma we suggest changing this to 1 11 | #define PIN 6 12 | 13 | // How many NeoPixels are attached to the Arduino? 14 | #define NUMPIXELS 16 15 | 16 | // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. 17 | // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest 18 | // example for more information on possible values. 19 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 20 | 21 | int delayval = 500; // delay for half a second 22 | 23 | void setup() { 24 | // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket 25 | #if defined (__AVR_ATtiny85__) 26 | if (F_CPU == 16000000) clock_prescale_set(clock_div_1); 27 | #endif 28 | // End of trinket special code 29 | 30 | pixels.begin(); // This initializes the NeoPixel library. 31 | } 32 | 33 | void loop() { 34 | 35 | // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. 36 | 37 | for(int i=0;i 4 | #ifdef __AVR__ 5 | #include 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #define PIN 2 12 | #define NUM_LEDS 8 13 | #define BRIGHTNESS 50 14 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);// RGBW 与RGB在创建灯带时不一样 15 | const char* ssid = "niehen_pc"; 16 | const char* password = "*"; 17 | const char* mqtt_server = "*"; 18 | WiFiClient espClient; 19 | PubSubClient client(espClient); 20 | long lastMsg = 0; 21 | char msg[50]; 22 | int value = 0; 23 | String tmpTopic; 24 | String strplayload; 25 | int bright = 0; 26 | 27 | void setup_wifi() { 28 | delay(10); 29 | WiFi.begin(ssid, password); 30 | while (WiFi.status() != WL_CONNECTED) { 31 | delay(500); 32 | Serial.print("."); 33 | } 34 | 35 | randomSeed(micros()); 36 | Serial.println(WiFi.localIP()); 37 | } 38 | void callback(char* topic, byte* payload, unsigned int length) { 39 | 40 | tmpTopic = String((char *)topic); 41 | payload[length] = '\0'; 42 | strplayload = String((char*)payload); 43 | 44 | 45 | client.publish("led_light/status", "get older "); 46 | if (strplayload == "off") { // 判断是否是off 关闭指令 47 | value = 0; 48 | client.publish("led_light/status", "led_light stop"); 49 | }else { 50 | int isint = 0;// 如果有字母 就为1 全数字就为0 51 | for (int i=0; i< strplayload.length();i++) // 检测接收到的命令里面是否含有 非数字的字符 52 | { 53 | if (!isDigit(strplayload[i])) 54 | { 55 | isint = 1; 56 | break; 57 | } 58 | } 59 | if(isint == 0){ 60 | int older_led = strplayload.toInt() ; // 转换为 int类型 61 | if(older_led >=0 && older_led<=5){ 62 | value = older_led; 63 | client.publish("led_light/status","led_light is running"); 64 | } 65 | } 66 | } 67 | 68 | } 69 | void reconnect() { 70 | 71 | while (!client.connected()) { 72 | Serial.print("Attempting MQTT connection..."); 73 | String clientId = "ESP8266Client-"; 74 | clientId += String(random(0xffff), HEX); 75 | if (client.connect(clientId.c_str())) { 76 | Serial.println("connected"); 77 | 78 | client.publish("led_light/status", "init..."); 79 | 80 | client.subscribe("led_light/older"); 81 | } else { 82 | Serial.print("failed, rc="); 83 | Serial.print(client.state()); 84 | Serial.println(" try again in 5 seconds"); 85 | delay(5000); 86 | } 87 | } 88 | } 89 | 90 | void setup() { 91 | Serial.begin(115200); 92 | setup_wifi(); 93 | client.setServer(mqtt_server, 1883); 94 | client.setCallback(callback); 95 | #if defined (__AVR_ATtiny85__) 96 | if (F_CPU == 16000000) clock_prescale_set(clock_div_1); 97 | #endif 98 | pixels.setBrightness(BRIGHTNESS); 99 | pixels.begin(); 100 | pulseWhite(1,5); 101 | delay(10); 102 | pulseWhite(0,5);// 出现bug 开灯后 有一个灯亮 这是解决办法 103 | } 104 | 105 | void loop() { 106 | 107 | if (value == 0){ 108 | pulseWhite(0,20); 109 | }else { 110 | pulseWhite(value*51,20); // 5个等级 111 | 112 | } 113 | if (!client.connected()) { 114 | reconnect(); 115 | } 116 | client.loop(); 117 | } 118 | void pulseWhite(uint8_t result,uint8_t wait) { // 第一个参数为要变为的亮度值 第二个参数为变化间隔的时间单位为毫秒 119 | if (bright < result){ 120 | for(int j = bright; j < result ; j++){ 121 | for(uint16_t i=0; i result){ 129 | for(int j = bright; j >= result ; j--){ 130 | for(uint16_t i=0; i 4 | #include 5 | #include 6 | 7 | const int STEPS_PER_ROTOR_REV = 32; 8 | const int GEAR_REDUCTION = 64; 9 | const float STEPS_PER_OUT_REV = 400;// 电机外部输出轴旋转一周步数 (2048) 10 | const int stepsPerRevolution = 200; 11 | //Stepper steppermotor(STEPS_PER_OUT_REV, D1, D2, D5, D6); 12 | Stepper steppermotor(STEPS_PER_OUT_REV, 5, 4, 14, 12); 13 | 14 | const char* ssid = "niehen_pc"; 15 | const char* password = "*"; 16 | const char* mqtt_server = "*"; 17 | 18 | WiFiClient espClient; 19 | PubSubClient client(espClient); 20 | long lastMsg = 0; 21 | char msg[50]; 22 | int value = 0; 23 | String tmpTopic; 24 | String strplayload; 25 | bool start_on = false; 26 | 27 | void setup_wifi() { 28 | delay(10); 29 | // We start by connecting to a WiFi network 30 | Serial.println(); 31 | Serial.print("Connecting to "); 32 | Serial.println(ssid); 33 | 34 | WiFi.begin(ssid, password); 35 | while (WiFi.status() != WL_CONNECTED) { 36 | delay(500); 37 | Serial.print("."); 38 | } 39 | 40 | randomSeed(micros()); 41 | Serial.println(WiFi.localIP()); 42 | } 43 | void callback(char* topic, byte* payload, unsigned int length) { 44 | 45 | 46 | tmpTopic = String((char *)topic); 47 | payload[length] = '\0'; 48 | strplayload = String((char*)payload); 49 | int isint = 0; 50 | String inString = ""; 51 | int older_circle = 0; 52 | client.publish("curtain/status", "curtain get the older"); 53 | 54 | for (int i=1; i< strplayload.length();i++) // 检测接收到的命令是否符合 55 | { 56 | if (strplayload[0] == '-') { 57 | inString += strplayload[i]; 58 | } 59 | if (!isDigit(strplayload[i])) 60 | { 61 | isint = 1; 62 | break; 63 | } 64 | } 65 | if(isint == 0){ 66 | if (strplayload[0] == '-') { 67 | // 反转 68 | older_circle = inString.toInt(); 69 | value = (-1) * older_circle; 70 | start_on = true; 71 | }else{ 72 | // 正转 73 | older_circle = strplayload.toInt(); 74 | value = older_circle; 75 | start_on = true; 76 | } 77 | 78 | } 79 | } 80 | void reconnect() { 81 | // Loop until we're reconnected 82 | while (!client.connected()) { 83 | Serial.print("Attempting MQTT connection..."); 84 | String clientId = "ESP8266Client-"; 85 | clientId += String(random(0xffff), HEX); 86 | if (client.connect(clientId.c_str())) { 87 | Serial.println("connected"); 88 | 89 | client.publish("curtain/status", "init..."); 90 | // ... and resubscribe 91 | client.subscribe("curtain/older"); 92 | } else { 93 | Serial.print("failed, rc="); 94 | Serial.print(client.state()); 95 | Serial.println(" try again in 5 seconds"); 96 | // Wait 5 seconds before retrying 97 | delay(5000); 98 | } 99 | } 100 | } 101 | 102 | void setup() { 103 | Serial.begin(115200); 104 | setup_wifi(); 105 | 106 | client.setServer(mqtt_server, 1883); 107 | client.setCallback(callback); 108 | steppermotor.setSpeed(80); 109 | } 110 | 111 | void loop() 112 | { 113 | if (!client.connected()) { 114 | reconnect(); 115 | } 116 | client.loop(); 117 | if(start_on ){ 118 | 119 | if(value >0) 120 | { 121 | steppermotor.step((value)*STEPS_PER_OUT_REV); 122 | client.publish("curtain/status", "curtain runing"); 123 | }else if(value <0){ 124 | steppermotor.step((value)*STEPS_PER_OUT_REV); 125 | client.publish("curtain/status", "curtain runing"); 126 | } 127 | start_on = false; 128 | } 129 | } 130 | 131 | --------------------------------------------------------------------------------