Node

Jeg har prøvet forskellige forsøg med en Node opsætning, og på nuværende tidspunkt tester jeg


Transciever RFM95W  

Arduino Pro Mini ATmega328P 3,3 volt 8MHz

Sensor DS18B20

3,6 Volt LiOn Battery

Charge og controller til Solar panel

//Arduino Code 1.8.8



/* TX LoRa Pro Mini RFM95W Green board

*/

#include "LowPower.h"

#include <LoRa.h>      

#include <OneWire.h>

#include <DallasTemperature.h>

// Data wire is plugged into port 9 on the Pro Mini

#define ONE_WIRE_BUS 9

// Setup a oneWire instance to communicate with any OneWire devices

OneWire oneWire(ONE_WIRE_BUS);

#define TEMPERATURE_PRECISION 12

// Pass our oneWire reference to Dallas Temperature.

DallasTemperature sensors(&oneWire);

// arrays to hold device address

DeviceAddress DS18B20_1;

 

// SPI LoRa Radio Pro Mini

const int LORA_SCK = 13;      

const int LORA_MISO = 12;   

const int LORA_MOSI = 11;   

const int LORA_CS = 10;    

const int LORA_RST = 5;   //????  LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ)

const int LORA_IRQ = 32 ;  //????? LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ)

 

//void(* resetFunc) (void) = 0; //declare reset function @ address 0

 

//int counter = 0;

uint8_t Node;

float Temp;

#define R1 1500000L

#define R2 420000L

 

/*void Resetarduino()

{

  Serial.println("resetting");

  resetFunc(); //call

  delay(1000);

}*/

 

void setup() {

  analogReference(INTERNAL);// use the 1.1 V internal reference for battery level measuring PRO MINI

  if (!sensors.getAddress( DS18B20_1, 0)) Serial.println("Unable to find address for Device 0");

    sensors.setResolution(DS18B20_1, TEMPERATURE_PRECISION);

  pinMode(ONE_WIRE_BUS,INPUT_PULLUP); 

  //Serial.begin(115200);

  //while (!Serial);

  //Serial.println("LoRa TX");

  LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);        

  if (!LoRa.begin(866E6)) {

    //Serial.println("Starting LoRa failed!");

    while (1);

  }

  // The larger the spreading factor the greater the range but slower data rate

  // Send and receive radios need to be set the same

  LoRa.setSpreadingFactor(12); // ranges from 6-12, default 7 see API docs

      // Change the transmit power of the radio

    // Default is LoRa.setTxPower(17, PA_OUTPUT_PA_BOOST_PIN);

    // Most modules have the PA output pin connected to PA_BOOST, gain 2-17

    // TTGO and some modules are connected to RFO_HF, gain 0-14

    // If your receiver RSSI is very weak and little affected by a better antenna, change this!

  //LoRa.setTxPower(17, PA_OUTPUT_RFO_PIN);

  LoRa.setTxPower(17, PA_OUTPUT_PA_BOOST_PIN);

}

float battery()

{

  int raw = analogRead(A0);

  float val = raw/1024.0; 

  return val * (R1 + R2)/R2;

 }

void GetdataTemperature()

{

  LoRa.idle(); 

  sensors.requestTemperatures(); // Send the command to get temperatures

  Temp = sensors.getTempC(DS18B20_1); 

  Node = DS18B20_1[2];

  delay(50);

/*  Serial.print("Reading: ");

  Serial.print("Temp.: ");

  Serial.print(Temp);

  Serial.print(" Node: ");

  Serial.print(Node);       

 

       switch (Node)

         {

        case 89:

            Serial.println(" 5p6mj node 1");

        break;

       case 201:

            Serial.println(" 5p6mj node 2");

        break;

        default:

            Serial.println(" new one");

        break;        

        }8*/

  senddata();

  LoRa.sleep();   

}

 

void senddata() {

    //counter++;

    float voltage = battery();

   // Serial.print("Sending packet: ");

   // Serial.println(counter);

    // send packet

    LoRa.beginPacket();

    LoRa.print(voltage);

    LoRa.print("c");

    LoRa.print(Temp);

    LoRa.print("t");

    LoRa.print(Node);

    LoRa.print("n");

    LoRa.endPacket();

    delay(50);

}

 

void loop() {

  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

  GetdataTemperature();

  delay(10);   

}