Commit d7644ca4 authored by Perera H.M.D's avatar Perera H.M.D

Upload New File

parent 525d0b66
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <EEPROM.h>
#include "TimeLib.h"
#include "timestamp32bits.h"
const char* ssid_sta = "Test";
const char* password_sta = "Test123";
ESP8266WebServer flow_server(80);
ESP8266HTTPUpdateServer flow_updater;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "lk.pool.ntp.org", 19800, 3600000);
time_t NTPunixTime;
timestamp32bits tstamp = timestamp32bits();
unsigned long NTPtime = 0;
unsigned long rstart_interval = 1000 * 60 * 60 * 24 * 30; //miliseconds per 30 days
int web_page_refresh_interval = 1000 * 10; //10 seconds
const char* admin_username = "admin";
const char* admin_password = "admin";
const char* svr = "api.thingspeak.com";
String apiKey = "QIFMFT4LJ12XZ4AW";
const char* www_realm = "Login Required";
String authFailResponse = "Login Failed. Please retry.";
bool logged_out;
#define TSENSOR_PIN D6
#define BSENSOR_PIN D7
#define valve_pin D4
unsigned long previousMillis = 0;
unsigned long sendtime;
unsigned long send_interval = 10000;
int interval = 1000;
float calibrationFactor = 4.5;
volatile byte pulseCount;
volatile byte pulseCount2;
byte tpulse1Sec = 0;
float tflowRate;
unsigned long tflowMilliLitres;
unsigned int ttotalMilliLitres;
float tflowLitres;
float ttotalLitres;
byte bpulse1Sec = 0;
float bflowRate;
unsigned long bflowMilliLitres;
unsigned int btotalMilliLitres;
float bflowLitres;
float btotalLitres;
bool valve_stat = false;
WiFiClient svrv;
void IRAM_ATTR pulseCounter()
{
pulseCount++;
}
void IRAM_ATTR pulseCounter2()
{
pulseCount2++;
}
void setup() {
Serial.begin(115200);
wifi_init();
server_init();
eeprom_init();
time_init();
pinMode(valve_pin, OUTPUT);
pinMode(TSENSOR_PIN, INPUT_PULLUP);
pinMode(BSENSOR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(TSENSOR_PIN), pulseCounter, FALLING);
attachInterrupt(digitalPinToInterrupt(BSENSOR_PIN), pulseCounter2, FALLING);
delay(100);
Serial.println("");
Serial.println("Ready...");
}
void loop() {
time_run();
sensor_run();
flow_server.handleClient();
rstart();
}
void rstart() {
if (millis() > rstart_interval) {
Serial.println("Restarting...");
ESP.restart();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment