15 changed files with 345 additions and 35 deletions
@ -0,0 +1,14 @@ |
|||||
|
void getBME280Data() { |
||||
|
|
||||
|
float temp(NAN), hum(NAN), pres(NAN); |
||||
|
|
||||
|
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); |
||||
|
BME280::PresUnit presUnit(BME280::PresUnit_Pa); |
||||
|
|
||||
|
bme.read(pres, temp, hum, tempUnit, presUnit); |
||||
|
|
||||
|
temperature = temp; |
||||
|
humidity = hum; |
||||
|
pressure = pres; |
||||
|
|
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
|
||||
|
void getWind() { |
||||
|
|
||||
|
int index = 0; |
||||
|
|
||||
|
digitalWrite(ENABLE_PIN1, HIGH); |
||||
|
digitalWrite(ENABLE_PIN2, LOW); |
||||
|
delay(10); |
||||
|
if(sensor.write(codes, sizeof(codes)) == 8) { |
||||
|
digitalWrite(ENABLE_PIN1, LOW); |
||||
|
for (byte i = 0; i < 11; i++) { |
||||
|
values[index][i] = sensor.read(); |
||||
|
} |
||||
|
} |
||||
|
windSpeed = values[index][4]; |
||||
|
|
||||
|
delay(500); |
||||
|
|
||||
|
index = 1; |
||||
|
|
||||
|
digitalWrite(ENABLE_PIN1, LOW); |
||||
|
digitalWrite(ENABLE_PIN2, HIGH); |
||||
|
delay(10); |
||||
|
if(sensor.write(codes, sizeof(codes)) == 8) { |
||||
|
digitalWrite(ENABLE_PIN2, LOW); |
||||
|
for (byte i = 0; i < 11; i++) { |
||||
|
values[index][i] = sensor.read(); |
||||
|
} |
||||
|
} |
||||
|
windDirection = values[index][4]; |
||||
|
|
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
#include <SoftwareSerial.h> |
||||
|
#include <Wire.h> |
||||
|
#include <BME280I2C.h> |
||||
|
|
||||
|
#define ENABLE_PIN1 8 // dir
|
||||
|
#define ENABLE_PIN2 9 // speed
|
||||
|
#define SERIAL_RO 10 |
||||
|
#define SERIAL_DI 11 |
||||
|
|
||||
|
BME280I2C bme; |
||||
|
|
||||
|
//const int enable[] = {ENABLE_PIN1, ENABLE_PIN1};
|
||||
|
const byte codes[] = {0x01 ,0x03 ,0x00 ,0x00 ,0x00 ,0x02 ,0xC4 ,0x0B}; |
||||
|
|
||||
|
byte values[2][20]; |
||||
|
SoftwareSerial sensor(SERIAL_RO, SERIAL_DI); |
||||
|
|
||||
|
int windSpeed = 0; |
||||
|
int windDirection = 0; |
||||
|
|
||||
|
float temperature = 0; |
||||
|
float humidity = 0; |
||||
|
float pressure = 0; |
||||
|
|
||||
|
void setup() { |
||||
|
// Initialize Serial Monitor for debugging
|
||||
|
Serial.begin(9600); |
||||
|
while(!Serial); |
||||
|
|
||||
|
// Initialize a SoftwareSerial
|
||||
|
sensor.begin(4800); |
||||
|
delay(500); |
||||
|
pinMode(ENABLE_PIN1, OUTPUT); |
||||
|
pinMode(ENABLE_PIN2, OUTPUT); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
getWind(); |
||||
|
Serial.print("Direction: "); |
||||
|
Serial.println(windDirection); |
||||
|
Serial.print("Speed: "); |
||||
|
Serial.println(windSpeed); |
||||
|
delay(5000); |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
|
||||
|
void setupBME280() { |
||||
|
Wire.begin(); |
||||
|
|
||||
|
while(!bme.begin()) { |
||||
|
Serial.println("Could not find BME280 sensor!"); |
||||
|
delay(1000); |
||||
|
} |
||||
|
|
||||
|
switch(bme.chipModel()) { |
||||
|
case BME280::ChipModel_BME280: |
||||
|
Serial.println("Found BME280 sensor! Success."); |
||||
|
break; |
||||
|
case BME280::ChipModel_BMP280: |
||||
|
Serial.println("Found BMP280 sensor! No Humidity available."); |
||||
|
break; |
||||
|
default: |
||||
|
Serial.println("Found UNKNOWN sensor! Error!"); |
||||
|
} |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
#include <SoftwareSerial.h> |
||||
|
#include <Wire.h> |
||||
|
#include "SIM800L.h" |
||||
|
#include <BME280I2C.h> |
||||
|
|
||||
|
#define SIM800_RX_PIN 10 |
||||
|
#define SIM800_TX_PIN 11 |
||||
|
#define SIM800_RST_PIN 7 |
||||
|
|
||||
|
SIM800L* sim800l; |
||||
|
BME280I2C bme; |
||||
|
|
||||
|
|
||||
|
const char APN[] = "TM"; |
||||
|
String BASE_URL = "http://2.238.194.8/index.php?"; |
||||
|
//String BASE_URL = "https://postman-echo.com/get?";
|
||||
|
|
||||
|
String s = ""; |
||||
|
char URL[100]; |
||||
|
|
||||
|
int windSpeed = 0; |
||||
|
int windDirection = 0; |
||||
|
|
||||
|
float temperature = 0; |
||||
|
float humidity = 0; |
||||
|
float pressure = 0; |
||||
|
|
||||
|
bool printSensorsData = true; |
||||
|
|
||||
|
void setup() { |
||||
|
// Initialize Serial Monitor for debugging
|
||||
|
Serial.begin(9600); |
||||
|
while(!Serial); |
||||
|
|
||||
|
pinMode(13, OUTPUT); |
||||
|
digitalWrite(13, HIGH); |
||||
|
|
||||
|
// Initialize a SoftwareSerial
|
||||
|
SoftwareSerial* serial = new SoftwareSerial(SIM800_RX_PIN, SIM800_TX_PIN); |
||||
|
serial->begin(9600); |
||||
|
delay(1000); |
||||
|
|
||||
|
// Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
|
||||
|
sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512); |
||||
|
|
||||
|
// Setup modules
|
||||
|
setupSIM800L(); |
||||
|
setupBME280(); |
||||
|
timer = millis() + timerLimit; |
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
|
||||
|
getWind(); |
||||
|
|
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
void getBME280Data() { |
||||
|
|
||||
|
float temp(NAN), hum(NAN), pres(NAN); |
||||
|
|
||||
|
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); |
||||
|
BME280::PresUnit presUnit(BME280::PresUnit_Pa); |
||||
|
|
||||
|
bme.read(pres, temp, hum, tempUnit, presUnit); |
||||
|
|
||||
|
temperature = temp; |
||||
|
humidity = hum; |
||||
|
pressure = pres; |
||||
|
|
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
void getWind() { |
||||
|
|
||||
|
windDirection = 0; |
||||
|
windSpeed = 0; |
||||
|
|
||||
|
} |
@ -0,0 +1,80 @@ |
|||||
|
|
||||
|
void sendRequest() { |
||||
|
|
||||
|
getBME280Data(); |
||||
|
|
||||
|
s = BASE_URL; |
||||
|
s.concat("windS="); |
||||
|
s.concat(windSpeed); |
||||
|
s.concat("&windD="); |
||||
|
s.concat(windDirection); |
||||
|
s.concat("&temp="); |
||||
|
s.concat(temperature); |
||||
|
s.concat("&pres="); |
||||
|
s.concat(pressure); |
||||
|
s.concat("&hum="); |
||||
|
s.concat(humidity); |
||||
|
s.toCharArray(URL, 100); |
||||
|
|
||||
|
Serial.println(URL); |
||||
|
|
||||
|
// Establish GPRS connectivity (5 trials)
|
||||
|
bool connected = false; |
||||
|
for(uint8_t i = 0; i < 5 && !connected; i++) { |
||||
|
delay(1000); |
||||
|
connected = sim800l->connectGPRS(); |
||||
|
} |
||||
|
|
||||
|
// Check if connected, if not reset the module and setup the config again
|
||||
|
if(connected) { |
||||
|
Serial.println(F("GPRS connected !")); |
||||
|
} else { |
||||
|
Serial.println(F("GPRS not connected !")); |
||||
|
Serial.println(F("Reset the module.")); |
||||
|
sim800l->reset(); |
||||
|
setupSIM800L(); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
Serial.println(F("Start HTTP GET...")); |
||||
|
Serial.println(URL); |
||||
|
|
||||
|
// Do HTTP GET communication with 10s for the timeout (read)
|
||||
|
uint16_t rc = sim800l->doGet(URL, 10000); |
||||
|
if(rc == 200) { |
||||
|
// Success, output the data received on the serial
|
||||
|
Serial.print(F("HTTP GET successful (")); |
||||
|
Serial.print(sim800l->getDataSizeReceived()); |
||||
|
Serial.println(F(" bytes)")); |
||||
|
Serial.print(F("Received : ")); |
||||
|
Serial.println(sim800l->getDataReceived()); |
||||
|
} else { |
||||
|
// Failed...
|
||||
|
Serial.print(F("HTTP GET error ")); |
||||
|
Serial.println(rc); |
||||
|
} |
||||
|
|
||||
|
// Close GPRS connectivity (5 trials)
|
||||
|
bool disconnected = sim800l->disconnectGPRS(); |
||||
|
for(uint8_t i = 0; i < 5 && !connected; i++) { |
||||
|
delay(1000); |
||||
|
disconnected = sim800l->disconnectGPRS(); |
||||
|
} |
||||
|
|
||||
|
if(disconnected) { |
||||
|
Serial.println(F("GPRS disconnected !")); |
||||
|
} else { |
||||
|
Serial.println(F("GPRS still connected !")); |
||||
|
} |
||||
|
|
||||
|
// Go into low power mode
|
||||
|
bool lowPowerMode = sim800l->setPowerMode(MINIMUM); |
||||
|
if(lowPowerMode) { |
||||
|
Serial.println(F("Module in low power mode")); |
||||
|
} else { |
||||
|
Serial.println(F("Failed to switch module to low power mode")); |
||||
|
} |
||||
|
|
||||
|
timer = millis() + timerLimit; |
||||
|
windSpeed = 0; |
||||
|
} |
@ -0,0 +1,58 @@ |
|||||
|
|
||||
|
void setupSIM800L() { |
||||
|
// Wait until the module is ready to accept AT commands
|
||||
|
while(!sim800l->isReady()) { |
||||
|
Serial.println(F("Problem to initialize AT command, retry in 1 sec")); |
||||
|
delay(1000); |
||||
|
} |
||||
|
Serial.println(F("Setup Complete!")); |
||||
|
|
||||
|
// Wait for the GSM signal
|
||||
|
uint8_t signal = sim800l->getSignal(); |
||||
|
while(signal <= 0) { |
||||
|
delay(1000); |
||||
|
signal = sim800l->getSignal(); |
||||
|
} |
||||
|
Serial.print(F("Signal OK (strenght: ")); |
||||
|
Serial.print(signal); |
||||
|
Serial.println(F(")")); |
||||
|
delay(1000); |
||||
|
|
||||
|
// Wait for operator network registration (national or roaming network)
|
||||
|
NetworkRegistration network = sim800l->getRegistrationStatus(); |
||||
|
while(network != REGISTERED_HOME && network != REGISTERED_ROAMING) { |
||||
|
delay(1000); |
||||
|
network = sim800l->getRegistrationStatus(); |
||||
|
} |
||||
|
Serial.println(F("Network registration OK")); |
||||
|
delay(1000); |
||||
|
|
||||
|
// Setup APN for GPRS configuration
|
||||
|
bool success = sim800l->setupGPRS(APN); |
||||
|
while(!success) { |
||||
|
success = sim800l->setupGPRS(APN); |
||||
|
delay(5000); |
||||
|
} |
||||
|
Serial.println(F("GPRS config OK")); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void setupBME280() { |
||||
|
Wire.begin(); |
||||
|
|
||||
|
while(!bme.begin()) { |
||||
|
Serial.println("Could not find BME280 sensor!"); |
||||
|
delay(1000); |
||||
|
} |
||||
|
|
||||
|
switch(bme.chipModel()) { |
||||
|
case BME280::ChipModel_BME280: |
||||
|
Serial.println("Found BME280 sensor! Success."); |
||||
|
break; |
||||
|
case BME280::ChipModel_BMP280: |
||||
|
Serial.println("Found BMP280 sensor! No Humidity available."); |
||||
|
break; |
||||
|
default: |
||||
|
Serial.println("Found UNKNOWN sensor! Error!"); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue