diff --git a/Arduino/Arduino_/Arduino.ino b/Arduino/Arduino_/Arduino.ino deleted file mode 100644 index 455c61c..0000000 --- a/Arduino/Arduino_/Arduino.ino +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include "SIM800L.h" -#include - -#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(); - -} diff --git a/Arduino/Arduino_/GetData.ino b/Arduino/Arduino_/GetData.ino deleted file mode 100644 index cf67748..0000000 --- a/Arduino/Arduino_/GetData.ino +++ /dev/null @@ -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(); - } -} diff --git a/Arduino/Arduino_/GetSensor.ino b/Arduino/Arduino_/GetSensor.ino deleted file mode 100644 index 46bf012..0000000 --- a/Arduino/Arduino_/GetSensor.ino +++ /dev/null @@ -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; - -} diff --git a/Arduino/Arduino_/Request.ino b/Arduino/Arduino_/Request.ino deleted file mode 100644 index 6f37e34..0000000 --- a/Arduino/Arduino_/Request.ino +++ /dev/null @@ -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; -} diff --git a/Arduino/Arduino_/Setup.ino b/Arduino/Arduino_/Setup.ino deleted file mode 100644 index 7f29c6a..0000000 --- a/Arduino/Arduino_/Setup.ino +++ /dev/null @@ -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!"); - } -} diff --git a/Arduino/Sensors/Sensors.ino b/Arduino/Sensors/Sensors.ino index 3d1dd7c..833b9a2 100644 --- a/Arduino/Sensors/Sensors.ino +++ b/Arduino/Sensors/Sensors.ino @@ -27,6 +27,13 @@ void setup() { Serial.begin(9600); while(!Serial); + // Initialize a Wire + Wire.begin(); + while(!bme.begin()){ + Serial.println("Could not find BME280 sensor!"); + delay(1000); + } + // Initialize a SoftwareSerial sensor.begin(4800); delay(500); @@ -36,10 +43,20 @@ void setup() { } void loop() { + getWind(); Serial.print("Direction: "); Serial.println(windDirection); Serial.print("Speed: "); Serial.println(windSpeed); + + + getBME280Data(); + Serial.print("Temp: "); + Serial.println(temperature); + Serial.print("Hum: "); + Serial.println(humidity); + Serial.print("Pres: "); + Serial.println(pressure); delay(5000); }