6 changed files with 17 additions and 258 deletions
@ -1,70 +0,0 @@ |
|||||
#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 anemometerPin = 6; |
|
||||
int anemometerVal = 0; |
|
||||
int anemometerState = 0; |
|
||||
unsigned long anemometerDuration = 0; |
|
||||
unsigned long startime = 0; |
|
||||
unsigned long timer = 0; |
|
||||
int windSpeed = 0; |
|
||||
|
|
||||
float temperature = 0; |
|
||||
float humidity = 0; |
|
||||
float pressure = 0; |
|
||||
|
|
||||
int northPin = 4; |
|
||||
int eastPin = 5; |
|
||||
int southPin = 2; |
|
||||
int westPin = 3; |
|
||||
|
|
||||
int timerLimit = 10000;//300000; // 5 minutes
|
|
||||
String windDirection = ""; |
|
||||
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(); |
|
||||
|
|
||||
} |
|
@ -1,36 +0,0 @@ |
|||||
|
|
||||
void getWind() { |
|
||||
|
|
||||
windDirection = ""; |
|
||||
anemometerVal = digitalRead(anemometerPin); |
|
||||
|
|
||||
if ((anemometerState == 1) && (anemometerVal == 0)) { |
|
||||
anemometerDuration = millis() - startime; |
|
||||
startime = millis(); |
|
||||
windSpeed = 2500.0/anemometerDuration; |
|
||||
} |
|
||||
|
|
||||
anemometerState = anemometerVal; |
|
||||
|
|
||||
if(millis() >= timer) { |
|
||||
|
|
||||
Serial.println("--------------------------"); |
|
||||
timer = millis() + timerLimit; |
|
||||
|
|
||||
if(digitalRead(northPin)) {windDirection = windDirection + "N";} |
|
||||
if(digitalRead(southPin)) {windDirection = windDirection + "S";} |
|
||||
if(digitalRead(eastPin)) {windDirection = windDirection + "E";} |
|
||||
if(digitalRead(westPin)) {windDirection = windDirection + "W";} |
|
||||
|
|
||||
if(printSensorsData) { |
|
||||
Serial.print("Wind speed:\t"); |
|
||||
Serial.print(windSpeed); |
|
||||
Serial.println("Km/h"); |
|
||||
|
|
||||
Serial.print("Wind direction:\t"); |
|
||||
Serial.println(windDirection); |
|
||||
|
|
||||
} |
|
||||
//sendRequest();
|
|
||||
} |
|
||||
} |
|
@ -1,14 +0,0 @@ |
|||||
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; |
|
||||
|
|
||||
} |
|
@ -1,80 +0,0 @@ |
|||||
|
|
||||
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; |
|
||||
} |
|
@ -1,58 +0,0 @@ |
|||||
|
|
||||
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