Tag Archive | Sensors

Arduino Sensors – Sender

Arduino Sensors – Test Sender

NewImage

IMG 3224

This is the code for the test devices based on Arduino UNO.

The Duemilanove has hard coded values while the UNO a sensor.

This is the code for 1 (Duemilanove with no sensors).  As the sensors come in will be adding to the sketch and simply un commenting the required calls for the target device.

The posted data log like this,

http://Jupiter/processIoT.php?data={“id”:2,”t”:24.3,”h”:59,”b”:1007.5,”d”:0,”gps”:[-37.691,144.009]}&rssi=-86&size=65

Again, I want the same code for the Arduino and the ESP based boards.  

 

#include "DHT.h"
#include <SPI.h>
#include <LoRa.h> 
#include <ArduinoJson.h>
 
#define DHTTYPE DHT11
const int DHTPin = 8;
DHT dht(DHTPin, DHTTYPE);
 
int counter = 0;
 
void setup() {
 
  Serial.begin(9600);
  Serial.println("LoRa JSON Sender");
  
  // DT11 Sensor
  pinMode(DHTPin, INPUT);
  dht.begin();
  
  //RA02 Module
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }else{
    Serial.println("Starting LoRa Success!");
  }
}
 
void loop() {
 
  // Setup 
  StaticJsonDocument<128> doc;  
 
//  float h = dht.readHumidity();
//  float t = dht.readTemperature();
 
  float t = 21.5;
  float h = 75;
  float b = 1000;
  
  // ID. Match to DeviceInfo table
  // 1 = Duemilanove no sensors
  // 2 = UNO with DF11
  doc["id"] = 1;
 
  // Sensors or preset 
  doc["t"] = t;
  doc["h"] = h;
  doc["b"] = b;
  doc["d"] = -1; 
  
  JsonArray data = doc.createNestedArray("gps");
  data.add( -37.691);
  data.add(144.009);
 
  String output;
  serializeJson(doc, output);
  
  LoRa.beginPacket();  
  LoRa.print(output);
  LoRa.endPacket();
 
  if (1){  // Check what was sent
    // Decode JSON and print serial 
    serializeJsonPretty(doc, Serial);
    Serial.println();
  }
 
  delay(150000);
}