本期任务

使用LoRaUNO采集SHT30温湿度数据通过是sx1278 LoRa模组发送到ESPLoRa单项网关,ESPLoRa单项网关获取到温湿度数据上传到点灯科技平台进行展示。可通过点灯科技平台进行数据下发开关指令控制电机和风扇,电机和风扇连接在ESPLoRa单项网关上,从而实现控制。

视频

点击查看【bilibili】

框架

image.png

ESPLoRa接收端

  1. #define BLINKER_WIFI
  2. #define TEXTE_1 "TextKey"
  3. #include <Blinker.h>
  4. #include <U8g2lib.h>
  5. #include <LoRa.h>
  6. #include <SPI.h>
  7. char auth[] = "点灯科技KEY";
  8. char ssid[] = "wifi名称";
  9. char pswd[] = "wifi密码";
  10. U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, /* reset=*/U8X8_PIN_NONE, /* clock=*/22, /* data=*/21); // ESP32使用SCL:D22 SDA:D21
  11. //开机画面---显示ESPLoRa图片
  12. const unsigned char bmp1[] U8X8_PROGMEM = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x80,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x0f,0xff,0x3f,0xff,0x3f,0xf0,0x01,0xc0,0x18,0xfe,0x7f,0x00,0x00,0x00,0x00,0xff,0x8f,0xff,0x3f,0xff,0x7f,0xf0,0x01,0x00,0x00,0xfe,0xff,0x00,0x00,0x00,0x80,0xff,0xcf,0xff,0x3f,0xff,0xff,0xf0,0x01,0x00,0x00,0xfe,0xff,0x01,0x00,0x00,0x80,0x1f,0xc0,0x0f,0x00,0x1f,0xf8,0xf0,0x01,0x00,0x00,0x3e,0xf0,0x03,0x00,0x00,0xc0,0x07,0xc0,0x03,0x00,0x1f,0xf0,0xf0,0x01,0xe0,0x0f,0x3e,0xe0,0x03,0x00,0x00,0xc0,0x07,0xc0,0x03,0x00,0x1f,0xf0,0xf1,0x01,0xf0,0x3f,0x3e,0xe0,0xe3,0x7f,0x00,0xc0,0x03,0xc0,0x03,0x00,0x1f,0xf0,0xf1,0x01,0xf8,0x3e,0x3e,0xf0,0xe1,0xff,0x00,0xc0,0xff,0xcf,0x0f,0x00,0x1f,0xf8,0xf0,0x01,0x3c,0x78,0xfe,0xff,0x01,0xf0,0x01,0xe0,0xff,0x8f,0xff,0x0f,0xff,0xff,0xf0,0x01,0x3c,0x78,0xfe,0xff,0x00,0xe0,0x01,0xc0,0xff,0x0f,0xff,0x1f,0xff,0x7f,0xf0,0x01,0x3c,0x78,0xfe,0xff,0x00,0xe0,0x01,0xc0,0x07,0x00,0x00,0x3f,0xff,0x3f,0xf0,0x01,0x3c,0xf8,0x3e,0xfc,0xe0,0xff,0x01,0xc0,0x07,0x00,0x00,0x3c,0x1f,0x00,0xf0,0x01,0x3c,0x78,0x3e,0xf0,0xf1,0xff,0x01,0xc0,0x07,0x00,0x00,0x7c,0x1f,0x00,0xf0,0x01,0x3c,0x78,0x3e,0xf0,0xf1,0xe0,0x01,0x80,0x3f,0x00,0x00,0x3f,0x1f,0x00,0xe0,0x07,0x3c,0x78,0x3e,0xe0,0xf3,0xe0,0x01,0x80,0xff,0xcf,0xff,0x3f,0x1f,0x00,0xe0,0xff,0xf9,0x3e,0x3e,0xe0,0xf3,0xe0,0x01,0x00,0xff,0xcf,0xff,0x1f,0x1f,0x00,0xc0,0xff,0xf9,0x3f,0x3e,0xe0,0xf3,0xff,0x01,0x00,0xfc,0xcf,0xff,0x0f,0x1f,0x00,0x80,0xff,0xe1,0x0f,0x3e,0xe0,0xe3,0xff,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x80,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  13. // 水泵开关
  14. BlinkerButton Button1("button");
  15. BlinkerButton Button2("fan");
  16. BlinkerText Text1("text1");
  17. BlinkerText Text2("text2");
  18. //传感器数据
  19. BlinkerNumber TEMP("temp");
  20. BlinkerNumber HUM("hum");
  21. BlinkerNumber RSS("rssi");
  22. //Lora初始化
  23. #define SS 5
  24. #define RST 14
  25. #define DI0 2
  26. #define BAND 433E6
  27. //传感器初始化
  28. String temperature;
  29. String humidity;
  30. String RSSI;
  31. float temp = 0, hum = 0, rssi = 0;
  32. void setup()
  33. {
  34. Serial.begin(9600);
  35. u8g2.begin();
  36. check_lora(); //检查lora
  37. showStart(); //显示启动界面
  38. pinMode(27, OUTPUT);
  39. pinMode(17, OUTPUT);
  40. pinMode(15, OUTPUT);
  41. digitalWrite(27, LOW);
  42. Blinker.begin(auth, ssid, pswd);
  43. LoRa.setSyncWord(0xA5); //可以设置信道(范围从0到0xFF)。
  44. LoRa.setTxPower(20);
  45. Serial.println("LoRa Initializing OK!");
  46. Button1.attach(button1_callback);
  47. Button2.attach(button2_callback);
  48. Blinker.attachHeartbeat(LORAMESSAGEDATA);//注册一个心跳包
  49. BLINKER_DEBUG.stream(Serial);
  50. Blinker.attachDataStorage(dataStorage);
  51. }
  52. void loop()
  53. {
  54. Blinker.run();
  55. Lora_packet(); //接收lora数据包
  56. u8g2.setFont(u8g2_font_t0_17_tr);
  57. u8g2.clearBuffer();
  58. u8g2.drawStr(0,14,"ESPLora Getway");//LORA---具体显示内容
  59. u8g2.drawLine(1,18,126,18); //画一条平面直线
  60. u8g2.drawStr(15,34,"Temp:");
  61. u8g2.setCursor(63, 34);//
  62. u8g2.print(temp);
  63. u8g2.drawStr(15,54,"Humi:");
  64. u8g2.setCursor(63, 54);
  65. u8g2.print(hum);
  66. u8g2.sendBuffer();
  67. }
  68. void dataStorage(){
  69. Blinker.dataStorage("temp", temp);
  70. Blinker.dataStorage("hum", hum);
  71. Blinker.dataStorage("rssi", rssi);
  72. }
  73. // 水泵
  74. void button1_callback(const String & state) {
  75. BLINKER_LOG("get button state: ", state);
  76. if (state=="on") {
  77. digitalWrite(27, HIGH);
  78. digitalWrite(17, HIGH);
  79. Text1.print("已打开"); // 反馈开关状态
  80. Button1.print("on");
  81. } else if(state=="off"){
  82. digitalWrite(27, LOW);
  83. digitalWrite(17, LOW);
  84. Text1.print("已关闭"); // 反馈开关状态
  85. Button1.print("off");
  86. }
  87. }
  88. //风扇
  89. void button2_callback(const String & state) {
  90. BLINKER_LOG("get button2 state: ", state);
  91. if (state=="on") {
  92. digitalWrite(15, HIGH);
  93. Text2.print("已打开"); // 反馈开关状态
  94. Button2.print("on");
  95. } else if(state=="off"){
  96. digitalWrite(15, LOW);
  97. Text2.print("已关闭"); // 反馈开关状态
  98. Button2.print("off");
  99. }
  100. }
  101. // 心跳包函数
  102. void LORAMESSAGEDATA() {
  103. TEMP.print(temp);
  104. HUM.print(hum);
  105. RSS.print(rssi);
  106. }
  107. //显示启动动画
  108. void showStart() {
  109. u8g2.clearBuffer();
  110. u8g2.drawXBMP(0,0, 128, 64, bmp1);
  111. u8g2.sendBuffer();
  112. delay(3000);
  113. }
  114. // 尝试解析数据包
  115. void Lora_packet(){
  116. int pos1;
  117. int packetSize = LoRa.parsePacket();
  118. if (packetSize) {
  119. // 如果收到包
  120. String LoRaData = LoRa.readString();
  121. //Serial.print(LoRaData);
  122. //读取数据包
  123. while (LoRa.available()) {
  124. Serial.print((char)LoRa.read());
  125. }
  126. //读取后开始拆包
  127. pos1 = LoRaData.indexOf('/');
  128. //解析后赋值变量
  129. temperature = LoRaData.substring(0, pos1);
  130. humidity = LoRaData.substring(pos1 + 1, LoRaData.length());
  131. RSSI = LoRa.packetRssi();
  132. temp = temperature.toFloat();
  133. hum = humidity.toFloat();
  134. rssi = RSSI.toFloat();
  135. TEMP.print(temp);
  136. HUM.print(hum);
  137. RSS.print(rssi);
  138. BLINKER_LOG(temperature);
  139. BLINKER_LOG(humidity);
  140. BLINKER_LOG(RSSI);
  141. }
  142. }
  143. //检查lora连接是否成功
  144. void check_lora(){
  145. while (!Serial);
  146. Serial.println("LoRa Receiver");
  147. LoRa.setPins(SS, RST, DI0);
  148. if (!LoRa.begin(BAND)) {
  149. Serial.println("Starting LoRa failed!");
  150. while (1);
  151. }
  152. }

LoRaUNO发送端

  1. /* oled屏幕声明
  2. 屏幕分辨率
  3. 修改分辨率需要到Adafruit_SSD1306.h库中修改
  4. */
  5. #include <LoRa.h>
  6. #include <SPI.h>
  7. #include <Arduino.h>
  8. #include <Wire.h>
  9. #include <Adafruit_GFX.h>
  10. #include <Adafruit_SSD1306.h>
  11. #include <Adafruit_SHT31.h>
  12. //lora模块声明
  13. #define BAND 433E6//Lora信号
  14. String LoRaMessage = "";//声明发送信息
  15. #define OLED_RESET -1 // 定义显示复位引脚
  16. Adafruit_SSD1306 display(OLED_RESET); //初始化Adafruit显示库
  17. // //启动界面
  18. static const uint8_t PROGMEM Starbmp[] = {
  19. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  20. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  21. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  22. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  23. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  24. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  25. 0x00,0x00,0x03,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  26. 0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  27. 0x00,0x00,0x3F,0xC7,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  28. 0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  29. 0x00,0x01,0xF0,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30. 0x00,0x03,0xC0,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x00,0x03,0x80,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x03,0x01,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33. 0x00,0x00,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  34. 0x00,0x00,0x0F,0x83,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x00,0x3E,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  36. 0x00,0x00,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  37. 0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  38. 0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  40. 0x00,0x00,0x01,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  41. 0x01,0xF0,0x03,0xC7,0x87,0xFF,0xC0,0x00,0x03,0xE0,0x3E,0x7E,0x07,0x80,0xFE,0x00,
  42. 0x01,0xF0,0x01,0x01,0x07,0xFF,0xF0,0x00,0x03,0xE0,0x3E,0x7E,0x07,0x83,0xFF,0x80,
  43. 0x01,0xF0,0x00,0x00,0x07,0xFF,0xF0,0x00,0x03,0xE0,0x3E,0x7F,0x07,0x87,0xFF,0xC0,
  44. 0x01,0xF0,0x00,0x00,0x07,0xFF,0xF8,0x00,0x03,0xE0,0x3E,0x7F,0x07,0x8F,0xFF,0xE0,
  45. 0x01,0xF0,0x00,0x00,0x07,0xFF,0xF8,0x00,0x03,0xE0,0x3E,0x7F,0x87,0x8F,0xC7,0xF0,
  46. 0x01,0xF0,0x00,0x3C,0x07,0x80,0xF9,0xFF,0x83,0xE0,0x3E,0x7F,0x87,0x9F,0x83,0xF0,
  47. 0x01,0xF0,0x00,0xFF,0x07,0x80,0xF9,0xFF,0xC3,0xE0,0x3E,0x7F,0xC7,0x9F,0x01,0xF0,
  48. 0x01,0xF0,0x03,0xFF,0x87,0x80,0xF9,0xFF,0xE3,0xE0,0x3E,0x7F,0xC7,0x9F,0x01,0xF0,
  49. 0x01,0xF0,0x03,0xFF,0xC7,0x81,0xF9,0xFF,0xF3,0xE0,0x3E,0x7F,0xC7,0x9F,0x01,0xF8,
  50. 0x01,0xF0,0x07,0xFF,0xC7,0xFF,0xF9,0xFF,0xF3,0xE0,0x3E,0x7F,0xE7,0xBF,0x01,0xF8,
  51. 0x01,0xF0,0x07,0xC3,0xE7,0xFF,0xF0,0x00,0xF3,0xE0,0x3E,0x7D,0xE7,0xBF,0x01,0xF8,
  52. 0x01,0xF0,0x07,0x83,0xE7,0xFF,0xE0,0x7F,0xF3,0xE0,0x3E,0x7D,0xF7,0xBF,0x01,0xF8,
  53. 0x01,0xF0,0x0F,0x83,0xE7,0xFF,0xE0,0xFF,0xF3,0xE0,0x3E,0x7C,0xF7,0x9F,0x01,0xF8,
  54. 0x01,0xF0,0x0F,0x83,0xE7,0xFF,0xF1,0xFF,0xF3,0xE0,0x3E,0x7C,0xFF,0x9F,0x01,0xF8,
  55. 0x01,0xF0,0x0F,0x83,0xE7,0x81,0xF9,0xFF,0xF1,0xE0,0x3E,0x7C,0x7F,0x9F,0x01,0xF0,
  56. 0x01,0xF8,0x07,0x83,0xE7,0x80,0xFB,0xE0,0xF1,0xF0,0x3C,0x7C,0x7F,0x9F,0x81,0xF0,
  57. 0x00,0xFF,0xF7,0xC7,0xE7,0x80,0xFB,0xE0,0xF1,0xF8,0xFC,0x7C,0x3F,0x8F,0xC7,0xF0,
  58. 0x00,0xFF,0xF7,0xFF,0xC7,0x80,0xFB,0xFF,0xF1,0xFF,0xFC,0x7C,0x3F,0x8F,0xFF,0xE0,
  59. 0x00,0x7F,0xF3,0xFF,0xC7,0x80,0xF9,0xFF,0xF0,0xFF,0xF8,0x7C,0x1F,0x87,0xFF,0xC0,
  60. 0x00,0x3F,0xF1,0xFF,0x87,0x80,0xF9,0xFF,0xF0,0x7F,0xF0,0x7C,0x1F,0x83,0xFF,0x80,
  61. 0x00,0x1F,0xF0,0xFE,0x07,0x80,0xFC,0x7F,0xF0,0x1F,0xC0,0x7C,0x1F,0x80,0x7E,0x00,
  62. 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  63. 0x00,0x00,0x03,0xC7,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  64. 0x00,0x00,0x01,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66. 0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67. 0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68. 0x00,0x00,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69. 0x00,0x00,0x3E,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70. 0x00,0x00,0x0F,0x83,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71. 0x00,0x00,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72. 0x00,0x03,0x01,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. 0x00,0x03,0x80,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x03,0xC0,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75. 0x00,0x01,0xF0,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  76. 0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  77. 0x00,0x00,0x3F,0xC7,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  78. 0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  79. 0x00,0x00,0x03,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  82. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  83. };
  84. //sht30地址声明
  85. Adafruit_SHT31 sht31 = Adafruit_SHT31();
  86. unsigned long previousMillis = 0; // will store last time LED was updated
  87. // constants won't change:
  88. const long interval = 3000; // interval at which to blink (milliseconds)
  89. void setup(void)
  90. {
  91. delay(500);
  92. Serial.begin(9600);//串口比特率
  93. pinMode(7, OUTPUT);
  94. Lora_begin();//输出lora模块
  95. //使用I2C地址= 0x3C
  96. //初始化SSD1306 OLED显示器
  97. display.begin(SSD1306_SWITCHCAPVCC, 0x3C);//需要提前声明地址
  98. //开启动画
  99. display.clearDisplay(); // clears the screen and buffer
  100. display.drawBitmap(0,0,Starbmp,128,64,WHITE);
  101. display.display();
  102. delay(2000);
  103. //初始化BMP180传感器
  104. if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
  105. Serial.println("Couldn't find SHT31");
  106. while (1) delay(1);
  107. }
  108. display.clearDisplay();
  109. display.setTextSize(1);
  110. display.setTextColor(WHITE, BLACK);
  111. display.setCursor(35, 0);
  112. display.print("LoRa Node");
  113. display.display();
  114. display.setCursor(10, 10);
  115. display.print("Tem:");
  116. display.drawCircle(72, 10, 1, WHITE);
  117. display.setCursor(74, 10);
  118. display.print("C");
  119. display.setCursor(10, 20);
  120. display.print("Hum:");
  121. display.setCursor(74, 20);
  122. display.print("%");
  123. display.setCursor(10, 30);
  124. display.print("Message:");
  125. display.setCursor(60, 30);
  126. display.print("SHT30 ok!");
  127. display.setCursor(60, 40);
  128. display.print("LoRa ok!");
  129. }
  130. //初始化lora模块
  131. void Lora_begin()
  132. {
  133. //初始化Lora
  134. while (!Serial);
  135. Serial.println("LoRa Sender");
  136. //检查lora模块
  137. if (!LoRa.begin(BAND)) {
  138. Serial.println("Starting LoRa failed!");
  139. while (1);
  140. }
  141. //没有问题初始化lora发送通道
  142. LoRa.setSyncWord(0xA5);//可以设置同步字(范围从0到0xFF)。
  143. LoRa.setTxPower(20);//发射功率
  144. }
  145. void loop()
  146. {
  147. float t = sht31.readTemperature();
  148. float h = sht31.readHumidity();
  149. display.setCursor(38, 10);
  150. display.print(t);
  151. display.setCursor(38, 20);
  152. display.print(h);
  153. display.display();
  154. unsigned long currentMillis = millis();
  155. if (currentMillis - previousMillis >= interval) {
  156. // save the last time you blinked the LED
  157. previousMillis = currentMillis;
  158. digitalWrite(7,!digitalRead(7));
  159. LoRaMessage = String(t) + "/" + String(h);
  160. LoRa.beginPacket();//准备发送信息
  161. LoRa.print(LoRaMessage);//发送数据
  162. LoRa.endPacket();//发送完毕
  163. Serial.print(F("LoRaMessage Sender succ"));
  164. //温度信息
  165. Serial.print(F("Temp = "));
  166. Serial.print(t);
  167. Serial.println(F(" *C"));
  168. //气压信息
  169. Serial.print(F("HUM = "));
  170. Serial.print(h);
  171. Serial.println(F("%"));
  172. Serial.println();
  173. }
  174. }

界面配置

APP下载:https://www.diandeng.tech/dev

  1. version¨¨2.0.0¨¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨num¨¨t0¨¨温度¨¨ico¨¨fad fa-tachometer-alt-fast¨¨clr¨¨#FBA613¨¨min¨É¨max¨¢1c¨uni¨¨°C¨¨bg¨É¨cols¨Í¨rows¨Ë¨key¨¨temp¨´x´É´y´Ë¨speech¨|÷¨lstyle¨Ê}{ßCßDßE¨湿度¨ßGßHßI¨#076EEF¨ßKÉßLº0ßM´%´ßOÉßPÍßQËßR¨hum¨´x´Í´y´ËßT|÷ßUÊ}{ßC¨btn¨ßG¨fal fa-power-off¨¨mode¨ÊßE¨开启水泵¨¨t1¨¨文本2¨ßOÉßPËßQËßR¨button¨´x´É´y´ÍßT|÷ßUÊßIßW}{ßC¨tex¨ßE´´ßc¨水泵状态¨¨size¨¤EßOÉßG¨fad fa-faucet-drip¨ßPÍßQËßR¨text1¨´x´Ë´y´ÍßT|÷ßUÌßIßW}{ßC¨cha¨ßOɨsty¨¨line¨ßIßJ¨sty1¨ßm¨clr1¨ßW¨sty2¨ßm¨clr2¨¨#00A90C¨ßPÑßQÌßRßS´x´É´y´ÑßT|÷ßUÉßE¨温度趋势¨¨key0¨ßS¨key1¨´´ßc´´¨key2¨´´¨t2¨´´}{ßCßfßE¨基于EspLoRa温湿度检测¨ßc´´ßh¤EßOÉßG¨far fa-house¨ßPÑßQËßR¨tex-brb¨´x´É´y´ÉßT|÷ßUÏßI¨#EA0909¨}{ßCßfßE´正常´ßc¨工作状态¨ßh¤EßOÉßG¨fad fa-siren¨ßPËßQËßR¨tex-ad0¨´x´Ï´y´ÏßT|÷ßUËßIßr}{ßCßDßE¨RSSI¨ßG¨fad fa-signal¨ßI¨#6010E4¨ßKÉßLº0ßM´dB´ßOÉßPËßQËßR¨rssi¨´x´Ï´y´ÍßT|÷ßUÉ}{ßCßYßGßZßaÊßE¨排风扇¨ßcßdßOÉßPËßQËßR¨fan¨´x´É´y´ÏßT|÷ßUÊßIßr}{ßCßfßE´´ßc¨风扇状态¨ßh¤EßOÉßG¨fad fa-fan-table¨ßPÍßQËßR¨text2¨´x´Ë´y´ÏßT|÷ßUÌßIßr}{ßCßkßOÉßlßmßIßWßnßmßo¨#595959¨ßpßmßq¨#389BEE¨ßPÑßQÌßRßX´x´É´y´¤BßT|÷ßtßXßE¨湿度曲线¨ßUÉ}{ßC¨deb¨ßaÉßOÉßPÑßQÌßR¨debug¨´x´É´y´¤E}÷¨actions¨|÷¨triggers¨|¦¨range¨¨source¨¨source_zh¨¨unit¨‡|ɺ0÷ßSßF´℃´|ɺ0÷ßXßV´%´—{ß1Lßeß1M¨开关状态¨¨state¨|´on´¨off¨÷¨state_zh¨|´开启´´关闭´÷}÷´rt´|÷}

FE17B12B1EE0992B1EAD53EE19504B9E.jpg5CA67A15C5F705B5599D0442ADD14DC2.jpg

45E876F65D4BA02031AC9539A9903CA2.jpg

本章附件

下载地址: https://www.aliyundrive.com/s/Y1oQhQEAqXf