Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- // On LinkIt 7697, the RX pin must be one of the EINT pins, such as P2 and P3.
- // There are no limitations on TX pin.
- //SoftwareSerial mySerial(3, 11); // RX, TX
- #include "DHT.h"
- #define DHTPIN 2 // what digital pin we're connected to
- #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
- SoftwareSerial mySerial(5, 4);
- DHT dht(DHTPIN, DHTTYPE);
- void setup() {
- Serial.begin(115200);
- while (!Serial) {
- ;
- }
- Serial.println("DHTxx test!");
- mySerial.begin(115200);
- while (!mySerial) {
- ;
- }
- dht.begin();
- pinMode(12, OUTPUT); //for rest EK-S76SXB
- digitalWrite(12, LOW); //for rest EK-S76SXB
- delay(100); // wait for 0.1 second
- pinMode(12, INPUT); //for rest EK-S76SXB
- delay(2000);
- mySerial.print("mac join abp"); //reset the board
- Serial.println("mac join abp");
- delay(5000);
- mySerial.print("mac tx ucnf 2 8888888888"); //reset the board
- Serial.println("mac tx ucnf 2 8888888888"); //just for test
- delay(5000);
- }
- int val_h; //humidity int part
- int val_hp; //humidity point part
- int val_t; //add 溫度
- int val_tp; //add 溫度 point part
- String lora_string; //string for TX
- void loop() {
- float h = dht.readHumidity(); // Read temperature as Celsius (the default)
- float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true)
- float f = dht.readTemperature(true);
- if (isnan(h) || isnan(t) || isnan(f)) { //如果讀不到值就代表沒讀到sensor
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- float hif = dht.computeHeatIndex(f, h);
- float hic = dht.computeHeatIndex(t, h, false);
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t");
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.print(" *C ");
- Serial.print(f);
- Serial.print(" *F\t");
- Serial.print("Heat index: ");
- Serial.print(hic);
- Serial.print(" *C ");
- Serial.print(hif);
- Serial.println(" *F");
- ////////////next for LoRa tx ////////////////////////////////////////////////////////////
- //hum 以下處理濕度
- val_h = (int) h;
- val_hp=int ((h-val_h)*100);
- lora_string="mac tx ucnf 2 01"; //for tx header
- if (val_h<10) lora_string+="0"; //for hex format
- lora_string+=val_h;
- if (val_hp<10) lora_string+="0";
- lora_string+=val_hp;
- //temperture 以下處理溫度
- val_t = (int) t;
- val_tp=int ((t-val_t)*100);
- if (val_t<10) lora_string+="0";
- lora_string+=val_t;
- if (val_tp<10) lora_string+="0";
- lora_string+=val_tp;
- mySerial.print(lora_string);
- delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement