基于点灯科技的LoRa应用分享-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 405|回复: 0

[分享] 基于点灯科技的LoRa应用分享

[复制链接]
发表于 2022-9-28 10:55 | 显示全部楼层 |阅读模式
本帖最后由 888123123 于 2022-9-28 11:05 编辑

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

程序框图

image.png


硬件框图
Snipaste_2022-09-28_10-58-44 (1).png

接收端代码
#define BLINKER_WIFI
#define TEXTE_1 "TextKey"

#include <Blinker.h>
#include <U8g2lib.h>
#include <LoRa.h>
#include <SPI.h>

char auth[] = "点灯科技KEY";
char ssid[] = "wifi名称";
char pswd[] = "wifi密码";

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, /* reset=*/U8X8_PIN_NONE, /* clock=*/22, /* data=*/21); // ESP32使用SCL22 SDA21

//开机画面---显示ESPLoRa图片
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 };

// 水泵开关
BlinkerButton Button1("button");
BlinkerButton Button2("fan");
BlinkerText Text1("text1");
BlinkerText Text2("text2");
//传感器数据
BlinkerNumber TEMP("temp");
BlinkerNumber HUM("hum");
BlinkerNumber RSS("rssi");

//Lora初始化
#define SS 5
#define RST 14
#define DI0 2
#define BAND 433E6

//传感器初始化
String temperature;
String humidity;
String RSSI;

float temp = 0, hum = 0, rssi = 0;


void setup()
{
    Serial.begin(9600);
    u8g2.begin();
    check_lora();    //检查lora
    showStart();    //显示启动界面
    pinMode(27, OUTPUT);
    pinMode(17, OUTPUT);
    pinMode(15, OUTPUT);
    digitalWrite(27, LOW);

    Blinker.begin(auth, ssid, pswd);

    LoRa.setSyncWord(0xA5);    //可以设置信道(范围从0到0xFF)。
    LoRa.setTxPower(20);  
    Serial.println("LoRa Initializing OK!");
    Button1.attach(button1_callback);   
    Button2.attach(button2_callback);
    Blinker.attachHeartbeat(LORAMESSAGEDATA);//注册一个心跳包
    BLINKER_DEBUG.stream(Serial);
    Blinker.attachDataStorage(dataStorage);
}

void loop()
{  
    Blinker.run();

    Lora_packet();   //接收lora数据包

    u8g2.setFont(u8g2_font_t0_17_tr);
    u8g2.clearBuffer();
    u8g2.drawStr(0,14,"ESPLora Getway");//LORA---具体显示内容

    u8g2.drawLine(1,18,126,18);     //画一条平面直线

    u8g2.drawStr(15,34,"Temp:");
    u8g2.setCursor(63, 34);//
    u8g2.print(temp);

    u8g2.drawStr(15,54,"Humi:");
    u8g2.setCursor(63, 54);
    u8g2.print(hum);
    u8g2.sendBuffer();

}

void dataStorage(){
   Blinker.dataStorage("temp", temp);
   Blinker.dataStorage("hum", hum);
   Blinker.dataStorage("rssi", rssi);
}

// 水泵
void button1_callback(const String & state) {
    BLINKER_LOG("get button state: ", state);
    if (state=="on") {
        digitalWrite(27, HIGH);
        digitalWrite(17, HIGH);
        Text1.print("已打开");        // 反馈开关状态
        Button1.print("on");        
    } else if(state=="off"){
        digitalWrite(27, LOW);
        digitalWrite(17, LOW);
        Text1.print("已关闭");        // 反馈开关状态
        Button1.print("off");        
    }
}
//风扇
void button2_callback(const String & state) {
    BLINKER_LOG("get button2 state: ", state);
    if (state=="on") {
        digitalWrite(15, HIGH);
        Text2.print("已打开");        // 反馈开关状态
        Button2.print("on");        
    } else if(state=="off"){
        digitalWrite(15, LOW);
        Text2.print("已关闭");        // 反馈开关状态
        Button2.print("off");      
    }
}

// 心跳包函数
void LORAMESSAGEDATA() {

     TEMP.print(temp);
     HUM.print(hum);
     RSS.print(rssi);
}

//显示启动动画
void showStart() {
  u8g2.clearBuffer();
  u8g2.drawXBMP(0,0, 128, 64, bmp1);
  u8g2.sendBuffer();
  delay(3000);
}

// 尝试解析数据包
void Lora_packet(){
  int pos1;
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // 如果收到包
    String LoRaData = LoRa.readString();
    //Serial.print(LoRaData);
    //读取数据包
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
    //读取后开始拆包
    pos1 = LoRaData.indexOf('/');
    //解析后赋值变量

    temperature = LoRaData.substring(0, pos1);
    humidity = LoRaData.substring(pos1 + 1, LoRaData.length());
    RSSI = LoRa.packetRssi();

    temp = temperature.toFloat();
    hum  = humidity.toFloat();
    rssi = RSSI.toFloat();
    TEMP.print(temp);
    HUM.print(hum);
    RSS.print(rssi);
    BLINKER_LOG(temperature);
    BLINKER_LOG(humidity);
    BLINKER_LOG(RSSI);  
  }

}

//检查lora连接是否成功
void check_lora(){
  while (!Serial);
  Serial.println("LoRa Receiver");
  LoRa.setPins(SS, RST, DI0);  
  if (!LoRa.begin(BAND)) {
  Serial.println("Starting LoRa failed!");
    while (1);
  }
}

节点端代码/* oled屏幕声明
屏幕分辨率
修改分辨率需要到Adafruit_SSD1306.h库中修改
*/

#include <LoRa.h>
#include <SPI.h>
#include <Arduino.h>
#include <Wire.h>            
#include <Adafruit_GFX.h>      
#include <Adafruit_SSD1306.h>  
#include <Adafruit_SHT31.h>
//lora模块声明
#define BAND 433E6//Lora信号
String LoRaMessage = "";//声明发送信息

#define OLED_RESET  -1    // 定义显示复位引脚
Adafruit_SSD1306 display(OLED_RESET);  //初始化Adafruit显示库

// //启动界面
static const uint8_t PROGMEM Starbmp[] = {
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,0x03,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xC7,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0xF0,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0xC0,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x80,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x01,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0x83,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xF0,0x03,0xC7,0x87,0xFF,0xC0,0x00,0x03,0xE0,0x3E,0x7E,0x07,0x80,0xFE,0x00,
0x01,0xF0,0x01,0x01,0x07,0xFF,0xF0,0x00,0x03,0xE0,0x3E,0x7E,0x07,0x83,0xFF,0x80,
0x01,0xF0,0x00,0x00,0x07,0xFF,0xF0,0x00,0x03,0xE0,0x3E,0x7F,0x07,0x87,0xFF,0xC0,
0x01,0xF0,0x00,0x00,0x07,0xFF,0xF8,0x00,0x03,0xE0,0x3E,0x7F,0x07,0x8F,0xFF,0xE0,
0x01,0xF0,0x00,0x00,0x07,0xFF,0xF8,0x00,0x03,0xE0,0x3E,0x7F,0x87,0x8F,0xC7,0xF0,
0x01,0xF0,0x00,0x3C,0x07,0x80,0xF9,0xFF,0x83,0xE0,0x3E,0x7F,0x87,0x9F,0x83,0xF0,
0x01,0xF0,0x00,0xFF,0x07,0x80,0xF9,0xFF,0xC3,0xE0,0x3E,0x7F,0xC7,0x9F,0x01,0xF0,
0x01,0xF0,0x03,0xFF,0x87,0x80,0xF9,0xFF,0xE3,0xE0,0x3E,0x7F,0xC7,0x9F,0x01,0xF0,
0x01,0xF0,0x03,0xFF,0xC7,0x81,0xF9,0xFF,0xF3,0xE0,0x3E,0x7F,0xC7,0x9F,0x01,0xF8,
0x01,0xF0,0x07,0xFF,0xC7,0xFF,0xF9,0xFF,0xF3,0xE0,0x3E,0x7F,0xE7,0xBF,0x01,0xF8,
0x01,0xF0,0x07,0xC3,0xE7,0xFF,0xF0,0x00,0xF3,0xE0,0x3E,0x7D,0xE7,0xBF,0x01,0xF8,
0x01,0xF0,0x07,0x83,0xE7,0xFF,0xE0,0x7F,0xF3,0xE0,0x3E,0x7D,0xF7,0xBF,0x01,0xF8,
0x01,0xF0,0x0F,0x83,0xE7,0xFF,0xE0,0xFF,0xF3,0xE0,0x3E,0x7C,0xF7,0x9F,0x01,0xF8,
0x01,0xF0,0x0F,0x83,0xE7,0xFF,0xF1,0xFF,0xF3,0xE0,0x3E,0x7C,0xFF,0x9F,0x01,0xF8,
0x01,0xF0,0x0F,0x83,0xE7,0x81,0xF9,0xFF,0xF1,0xE0,0x3E,0x7C,0x7F,0x9F,0x01,0xF0,
0x01,0xF8,0x07,0x83,0xE7,0x80,0xFB,0xE0,0xF1,0xF0,0x3C,0x7C,0x7F,0x9F,0x81,0xF0,
0x00,0xFF,0xF7,0xC7,0xE7,0x80,0xFB,0xE0,0xF1,0xF8,0xFC,0x7C,0x3F,0x8F,0xC7,0xF0,
0x00,0xFF,0xF7,0xFF,0xC7,0x80,0xFB,0xFF,0xF1,0xFF,0xFC,0x7C,0x3F,0x8F,0xFF,0xE0,
0x00,0x7F,0xF3,0xFF,0xC7,0x80,0xF9,0xFF,0xF0,0xFF,0xF8,0x7C,0x1F,0x87,0xFF,0xC0,
0x00,0x3F,0xF1,0xFF,0x87,0x80,0xF9,0xFF,0xF0,0x7F,0xF0,0x7C,0x1F,0x83,0xFF,0x80,
0x00,0x1F,0xF0,0xFE,0x07,0x80,0xFC,0x7F,0xF0,0x1F,0xC0,0x7C,0x1F,0x80,0x7E,0x00,
0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0xC7,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0x83,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x01,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x80,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0xC0,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0xF0,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xC7,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0xFF,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,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

};

//sht30地址声明
Adafruit_SHT31 sht31 = Adafruit_SHT31();

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 3000;           // interval at which to blink (milliseconds)

void setup(void)
{   
    delay(500);
    Serial.begin(9600);//串口比特率
    pinMode(7, OUTPUT);
    Lora_begin();//输出lora模块
    //使用I2C地址= 0x3C
    //初始化SSD1306 OLED显示器
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);//需要提前声明地址

   //开启动画
  display.clearDisplay();   // clears the screen and buffer
  display.drawBitmap(0,0,Starbmp,128,64,WHITE);
  display.display();
  delay(2000);




    //初始化BMP180传感器
  if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }


    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(35, 0);           
    display.print("LoRa Node");
    display.display();

    display.setCursor(10, 10);
    display.print("Tem:");

    display.drawCircle(72, 10, 1, WHITE);
    display.setCursor(74, 10);
    display.print("C");  

    display.setCursor(10, 20);
    display.print("Hum:");

    display.setCursor(74, 20);
    display.print("%");

    display.setCursor(10, 30);
    display.print("Message:");
    display.setCursor(60, 30);
    display.print("SHT30  ok!");
    display.setCursor(60, 40);
    display.print("LoRa   ok!");


}

//初始化lora模块
void Lora_begin()
{
    //初始化Lora
    while (!Serial);
    Serial.println("LoRa Sender");

    //检查lora模块
    if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1);
    }
    //没有问题初始化lora发送通道
    LoRa.setSyncWord(0xA5);//可以设置同步字(范围从0到0xFF)。
    LoRa.setTxPower(20);//发射功率
}


void loop()
{
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();
  display.setCursor(38, 10);
  display.print(t);
  display.setCursor(38, 20);
  display.print(h);
  display.display();
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    digitalWrite(7,!digitalRead(7));
    LoRaMessage = String(t) + "/" + String(h);
    LoRa.beginPacket();//准备发送信息
    LoRa.print(LoRaMessage);//发送数据
    LoRa.endPacket();//发送完毕
    Serial.print(F("LoRaMessage Sender  succ"));
    //温度信息
    Serial.print(F("Temp = "));
    Serial.print(t);
    Serial.println(F(" *C"));
    //气压信息  
    Serial.print(F("HUM = "));
    Serial.print(h);
    Serial.println(F("%"));
    Serial.println();
  }


}


导入界面配置:
{¨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.jpg 45E876F65D4BA02031AC9539A9903CA2.jpg


B站视频演示:https://www.bilibili.com/video/BV1ee4y197V4/?spm_id_from=333.999.0.0&vd_source=446f9a5257a45be18ced68a9c54da1ad

blink_wifi.zip (50.22 KB, 下载次数: 2)

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 09:36 , Processed in 0.077114 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表