Cause now my app seems to connect, and read my sensor, but doesnt update the values on my app. I can see it connects, but no values change…maybe I should include my complete sketch?
> #include <DS3232RTC.h>
> #include <TimeLib.h>
> #include <LowPower.h>
> #include <Wire.h>
> #include <NewPing.h>
> #define BLYNK_PRINT Serial
> #define TINY_GSM_MODEM_SIM800
> #include <TinyGsmClient.h>
> #include <SoftwareSerial.h>
> #include <BlynkSimpleSIM800.h>
> #define SIM800_TX_PIN 5
> #define SIM800_RX_PIN 13
> #define uS_TO_m_FACTOR 60000000 // Conversion factor for micro seconds to minutes
> char auth[] = "a892d375ccccccc6670d5c086d6b1";
> char apn[] = "";
> char user[] = "";
> char pass[] = "";
> const int MAX_DISTANCE = 120; //max distance to measure
> const int Diameter1 = 110; //internal Diameter of tank 1 in cm
> const int Depth1 = 110; //total depth of tank 1 in cm , from sensor to base inside
> const unsigned int Period = 60000; //period between pings, in milliseconds. i.e 1 munute = 60,000. max 65535. Want longer? use unsigned long
> const int PingPin1 = 8; // GPIO5, D1
> const int EchoPin1 = 9; // GPIO4, D2
> const int Area1 = PI * ((Diameter1 / 2) * (Diameter1 / 2)); //area of base of tank 1
> int Litres1, Distance1, WaterDepth1, Decimal, Persentage, battLevel, csq, res, imei;
> int count = 1;
> String gsmTime;
> #include <SoftwareSerial.h>
> SoftwareSerial SerialAT(SIM800_TX_PIN, SIM800_RX_PIN);
> TinyGsm modem(SerialAT);
> BlynkTimer timer;
> NewPing sonar = NewPing(PingPin1, EchoPin1, MAX_DISTANCE);
>
> tmElements_t tm;
> const byte rtcAlarmPin = 3; // External interrupt on pin D3
>
> void setup()
> {
> pinMode(rtcAlarmPin, INPUT_PULLUP); // Set interrupt pin
> RTC.squareWave(SQWAVE_NONE); // Disable the default square wave of the SQW pin
>
> // setAlarm Syntax (RTC.setAlarm(alarmType, seconds, minutes, hours, dayOrDate);)
> //RTC.setAlarm(ALM1_MATCH_MINUTES, 0, 53, 0, 1);
> RTC.setAlarm(ALM1_MATCH_SECONDS, 10, 0, 0, 1);
>
> RTC.alarm(ALARM_1);
> RTC.alarmInterrupt(ALARM_1, true); // Enable alarm 1 interrupt A1IE
> }
>
> // Interrupt Service Routine (ISR) function
> void wake ()
> {
> detachInterrupt (digitalPinToInterrupt (3)); // Disable interrupts on D3
> count++;
> }
>
> void sleepNow ()
> {
> noInterrupts (); // Disable interrupts before entering sleep
> attachInterrupt (digitalPinToInterrupt(3), wake, FALLING); // Wake on falling edge of D3
> interrupts (); // Enable interrupts to ensure next instruction is executed
> LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
> }
> void sendWarning()
> {
> //modem.sendSMS("+27834079675", "Water level 30% or less, please check!");
> Serial.println();
> Serial.println("SMS sent...");
> }
>
> void GPRScheck() {
> if (!modem.isGprsConnected()) {
> modem.restart();
> Blynk.config(modem, auth);
> if (Blynk.connectNetwork(apn, user, pass)) {
> //String COP = modem.getOperator();
> //COP.remove(15);
> Blynk.connect();
> Serial.println("should connect now");
> }
> }
> }
>
> void myFunction()
> {
> Serial.begin(19200);
> delay(10);
> SerialAT.begin(9600);
> delay(3000);
> Serial.println("Initializing modem...");
> Blynk.config(modem, auth);
> GPRScheck();
> delay(3000);
> Distance1 = sonar.ping_cm(); //get distance to the top of the water tank 1
> if (Distance1 >= Depth1 || Distance1 == 0 ) Distance1 = Depth1; //check it does not go negative
> WaterDepth1 = Depth1 - Distance1; //calculate the depth of the water
> Litres1 = ((Depth1 * (PI * (sq(Diameter1 / 2)))) - (Distance1 * (PI * (sq(Diameter1 / 2))))) / 1000;
> Persentage = (Litres1 / 1000.00) * 100;
> battLevel = modem.getBattPercent();
> csq = modem.getSignalQuality();
> Blynk.virtualWrite(V1, WaterDepth1);
> Blynk.virtualWrite(V2, Litres1);
> Blynk.virtualWrite(V3, Litres1 / 10);
> Blynk.virtualWrite(V4, Persentage);
> Blynk.virtualWrite(V5, battLevel);
> Blynk.virtualWrite(V6, csq);
> Blynk.virtualWrite(V7, count);
> Serial.println();
> Serial.println();
> Serial.println("Water depth: " + String(WaterDepth1));
> Serial.println("Water distance: " + String(Distance1));
> Serial.println("Litres: " + String(Litres1));
> Serial.println("Percentage: " + String(Persentage));
> Serial.println("Battery: " + String(battLevel));
> Serial.println("Signal Qlty: " + String(csq));
> Serial.println();
> Serial.print(count);
> Serial.println();
> if (Persentage <= 30)
> sendWarning();
> delay(1000);
> }
>
> void loop()
> {
> Serial.println();
> Serial.println("Entering sleep");
> delay(100);
>
> sleepNow(); // Enter sleep
>
> Serial.println("Awake...");
> if (RTC.alarm(ALARM_1))
> {
> RTC.read(tm);
> RTC.setAlarm(ALM1_MATCH_SECONDS, 10, 0, 0, 1); // once a minute
> //RTC.setAlarm(ALM1_MATCH_MINUTES, 0, 53, 0, 1);
> //RTC.setAlarm(ALM1_MATCH_MINUTES, 0, 26, 0, 1); // once a hour
> TimeDateDisplay();
> powerON();
> myFunction();
> powerOFF();
> }
> }
>
> void powerON()
> {
> pinMode(2, OUTPUT);
> digitalWrite(2, HIGH);
> }
> void powerOFF()
> {
> pinMode(2, OUTPUT);
> digitalWrite(2, LOW);
> }
>
> void TimeDateDisplay()
> {
> RTC.read(tm);
> char dateBuffer[19];
> sprintf(dateBuffer, "%04u-%02u-%02u %02u:%02u:%02u", (tm.Year + 1970), tm.Month, tm.Day, tm.Hour, tm.Minute, tm.Second);
> Serial.println(dateBuffer);
> }
and my output looks like this:
> Awake...
> 2019-02-19 11:43:10
> Initializing modem...
> [470736]
> ___ __ __
> / _ )/ /_ _____ / /__
> / _ / / // / _ \/ '_/
> /____/_/\_, /_//_/_/\_\
> /___/ v0.6.0 on Arduino Pro
>
> [478949]
> ___ __ __
> / _ )/ /_ _____ / /__
> / _ / / // / _ \/ '_/
> /____/_/\_, /_//_/_/\_\
> /___/ v0.6.0 on Arduino Pro
>
> [478996] Modem init...
> [480251] Connecting to network...
> [484136] Network: Mobile Telephone Network
> [484136] Connecting to ...
> [489723] Connected to GPRS
> [489795] Connecting to blynk-cloud.com:80
> [491984] Ready (ping: 770ms).
> [498001] Connecting to blynk-cloud.com:80
> should connect now
>
>
> Water depth: 65
> Water distance: 45
> Litres: 617
> Percentage: 61
> Battery: 87
> Signal Qlty: 25
>
> 10
>
> Entering sleep