Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //eeprom write
- //ep_write(epAddress, variableToWrite);
- //eeprom read
- //variableToRead = ep_read(eepAddress);
- #include <EEPROM.h>
- #define ep_limit 15 // change mo to para mataasan limit. 5 = (5 x 255) = 1275 (vouchers)
- //int epAddrPerPisoMin = 10;
- //int epAddrPromoOnePrice = 40;
- //int epAddrPromoOneHours = 80;
- //int epAddrPromoTwoPrice = 120;
- //int epAddrPromoTwoHours = 160;
- //int epAddrPromoThreePrice = 200;
- //int epAddrPromoThreeHours = 240;
- //int epAddrPromoFourPrice = 280;
- //int epAddrPromoFourHours = 320;
- //int epAddrPromoFivePrice = 360;
- //int epAddrPromoFiveHours = 400;
- //
- ////promo prices
- //int promo1 = 10;
- //int promo2 = 15;
- //int promo3 = 20;
- //int promo4 = 30;
- //int promo5 = 150;
- //
- ////promo hour
- //int promoOne = 1;
- //int promoTwo = 6;
- //int promoThree = 12;
- //int promoFour = 24;
- //int promoFive = 168;
- //eeprom set
- //per piso 4, promo1
- unsigned long temp;
- #include <ESP8266TelnetClient.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266WiFiMulti.h>
- IPAddress mikrotikRouterIp (192, 168, 22, 1);
- const char* user = "admin";
- const char* pwd = "Secreto#020202";
- const char* ssid = "MikroTik Wifi";
- const char* password = "Secreto#020202";
- String M_command;
- ESP8266WiFiMulti WiFiMulti;
- WiFiClient client;
- ESP8266telnetClient tc(client);
- //WITH Test1ISTOR ,
- //pinMode(buttonPin, INPUT);
- //digitalWrite(buttonPin, HIGH); //CLOSE
- //digitalWrite(buttonPin, LOW); //OPEN
- //
- //WITHOUT Test1ISTOR
- //pinMode(buttonPin, INPUT_PULLUP);
- //digitalWrite(buttonPin, LOW); //CLOSE
- //digitalWrite(buttonPin, HIGH); //OPEN
- unsigned long previousMillis = 0; // will store last time LED was updated
- const long interval = 10000;
- long lcdCoin = 0;
- unsigned long previousResetMillis = 0;
- bool resetNow = false;
- unsigned long startTime = 0;
- unsigned long checkTime = 0;
- bool displayCoinCount = false;
- int dummyCounter = 0;
- unsigned long debounceDelay = 0;
- bool activateButton = false;
- bool editMode = false;
- bool displayMainMessage = true;
- bool displayVouch = false;
- #define buttonPinTest1 D7
- int buttonStateTest1;
- int lastButtonStateTest1 = LOW;
- unsigned long lastDebounceTimeTest1 = 0;
- #define buttonPinTest2 D3
- int buttonStateTest2;
- int lastButtonStateTest2 = LOW;
- unsigned long lastDebounceTimeTest2 = 0;
- #define buttonPinTest3 D6
- int buttonStateTest3;
- int lastButtonStateTest3 = LOW;
- unsigned long lastDebounceTimeTest3 = 0;
- long userCode;
- int perPisoMin = 5; //ILANG MINUTES PER PISO, EDITABLE BY FUCKING EEPROM
- long computation = perPisoMin * 60L;
- long hourPromo = 3600UL;
- //promo prices
- int promo1 = 10;
- int promo2 = 15;
- int promo3 = 20;
- int promo4 = 30;
- int promo5 = 150;
- //promo hour
- int promoOne = 1;
- int promoTwo = 6;
- int promoThree = 12;
- int promoFour = 24;
- int promoFive = 168;
- int epAddrPerPisoMin = 0;
- int epAddrPromoOnePrice = 30;
- int epAddrPromoOneHours = 60;
- int epAddrPromoTwoPrice = 90;
- int epAddrPromoTwoHours = 120;
- int epAddrPromoThreePrice = 150;
- int epAddrPromoThreeHours = 180;
- int epAddrPromoFourPrice = 210;
- int epAddrPromoFourHours = 240;
- int epAddrPromoFivePrice = 270;
- int epAddrPromoFiveHours = 300;
- long promoComp;
- long promoHour = 3600UL;
- unsigned long promoTime;
- int counterMap = 0;
- #include <LiquidCrystal_I2C.h> //library
- #include <Wire.h>
- #define BACKLIGHT_PIN 13 //backlight pin
- LiquidCrystal_I2C lcd(0x27, 20, 4);
- int counter = 0;
- int counterChange = -1;
- #define coinSlotPin 2
- int coins = 0;
- int lastCoinCount = 0;
- long promoFinal;
- long inBet = 0;
- ICACHE_RAM_ATTR void coinInserted()
- {
- coins++;
- if (coins < promo1)
- {
- promoFinal = computation * coins;
- }
- else if (coins >= promo1 && coins < promo2)
- {
- promoTime = promoOne * promoHour;
- promoComp = coins - promo1;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo2 && coins < promo3)
- {
- promoTime = promoTwo * promoHour;
- promoComp = coins - promo2;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo3 && coins < promo4)
- {
- promoTime = promoThree * promoHour;
- promoComp = coins - promo3;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo4 && coins < promo5)
- {
- //promo4 = 30;
- //60 modulo
- promoTime = promoFour * promoHour;
- promoComp = coins - promo4;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo5)
- {
- promoTime = promoFive * promoHour;
- promoComp = coins - promo5;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- Serial.println(promoFinal);
- }
- void setup()
- {
- perPisoMin = ep_read(epAddrPerPisoMin);
- promo1 = ep_read(epAddrPromoOnePrice);
- promo2 = ep_read(epAddrPromoTwoPrice);
- promo3 = ep_read(epAddrPromoThreePrice);
- promo4 = ep_read(epAddrPromoFourPrice);
- promo5 = ep_read(epAddrPromoFivePrice);
- promoOne = ep_read(epAddrPromoOneHours);
- promoTwo = ep_read(epAddrPromoTwoHours);
- promoThree = ep_read(epAddrPromoThreeHours);
- promoFour = ep_read(epAddrPromoFourHours);
- promoFive = ep_read(epAddrPromoFiveHours);
- computation = perPisoMin * 60L;
- Serial.begin(9600);
- WiFi.mode(WIFI_STA);
- WiFiMulti.addAP(ssid, password);
- //coins = 60;
- pinMode(coinSlotPin, INPUT);
- attachInterrupt(D5, coinInserted, RISING);
- pinMode(buttonPinTest1, INPUT);
- pinMode(buttonPinTest2, INPUT);
- pinMode(buttonPinTest3, INPUT);
- lcd.begin();
- lcd.backlight();
- lcd.setCursor(5, 0);
- lcd.print(F("WELCOME TO"));
- lcd.setCursor(0, 1);
- lcd.print(F("JHUNDECK HOTSPOT"));
- digitalWrite(LED_BUILTIN, HIGH);
- delay(1000);
- Serial.println();
- Serial.println();
- Serial.println("Wait for WI-Fi...");
- while (WiFiMulti.run() != WL_CONNECTED)
- {
- Serial.print(".");
- delay(500);
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.print("IP Address : ");
- Serial.println(WiFi.localIP());
- Serial.println("Connecting....");
- tc.setPromptChar('>');
- //manual login pagka may problema
- char key = 0;
- Serial.println("\r\npress enter to begin:");
- do
- {
- key = Serial.read();
- Serial.println(key);
- }
- //automatic login
- while (key <= 0);
- tc.login(mikrotikRouterIp, user, pwd);
- }
- void loop() {
- editRates();
- readBtnTest1();
- readBtnTest2();
- readBtnTest3();
- //Serial.println(counter);
- editModeCheck();
- displayCheck();
- noNegative();
- // Serial.println(lcdCoin);
- displayCoin();
- displayVoucher();
- computation = perPisoMin * 60L;
- userCode = random(10000, 99999);
- //Serial.println(promoFinal);
- }
- void readBtnTest1() {
- int reading = digitalRead(buttonPinTest1);
- if (reading != lastButtonStateTest1) {
- lastDebounceTimeTest1 = millis();
- }
- if ((millis() - lastDebounceTimeTest1) > debounceDelay) {
- if (reading != buttonStateTest1) {
- buttonStateTest1 = reading;
- if (buttonStateTest1 == HIGH)
- {
- counter++;
- }
- }
- }
- lastButtonStateTest1 = reading;
- }
- void readBtnTest2() {
- int reading = digitalRead(buttonPinTest2);
- if (reading != lastButtonStateTest2) {
- lastDebounceTimeTest2 = millis();
- }
- if ((millis() - lastDebounceTimeTest2) > debounceDelay) {
- if (reading != buttonStateTest2) {
- buttonStateTest2 = reading;
- if (buttonStateTest2 == HIGH)
- {
- counter--;
- }
- }
- }
- lastButtonStateTest2 = reading;
- }
- void readBtnTest3() {
- int reading = digitalRead(buttonPinTest3);
- if (reading != lastButtonStateTest3) {
- lastDebounceTimeTest3 = millis();
- }
- if ((millis() - lastDebounceTimeTest3) > debounceDelay) {
- if (reading != buttonStateTest3) {
- buttonStateTest3 = reading;
- if (buttonStateTest3 == HIGH)
- {
- counterChange++;
- Serial.println(counterChange);
- }
- }
- }
- lastButtonStateTest3 = reading;
- }
- void booleanCheck()
- {
- if (counter == 5)
- {
- activateButton = true;
- }
- }
- void editModeCheck()
- {
- if (counterChange > 0 && displayMainMessage == true)
- {
- counterChange = 0;
- }
- if (coins > 0)
- {
- userCode = random(10000, 99999);
- displayMainMessage = false;
- displayCoinCount = true; //map
- if (counterChange == 1)
- {
- displayVouch = true;
- displayVoucher();
- displayVouch = true;
- displayCoinCount = false;
- resetCountStart();
- lcdCoin = coins;
- coins = 0;
- }
- }
- if (displayVouch == true)
- {
- counterMap = 1;
- displayVouch = false;
- Serial.println("Wait reset");
- }
- if (counterMap == 1 && displayVouch == false)
- {
- resetAfter(6);
- if (resetNow == true && displayCoinCount == false || counterChange == 2)
- {
- lcd.clear();
- Serial.println("Reset ");
- resetVariable();
- counterMap = 0;
- //map666
- }
- }
- }
- void editRates()
- {
- if (counter == 5 && activateButton == false && dummyCounter == 0)
- {
- booleanCheck();
- dummyCounter++;
- }
- else if (activateButton == true)
- {
- displayMainMessage = false;
- counter = 0;
- activateButton = false;
- editMode = true;
- }
- if (editMode == true)
- {
- displayEditMode();
- }
- }
- void resetAfter(int sec) {
- unsigned long currentResetMillis = millis();
- sec *= 1000;
- if (currentResetMillis - previousResetMillis >= sec && !resetNow) {
- previousResetMillis = currentResetMillis;
- resetNow = true;
- //Serial.println("Reset Now");
- }
- }
- void resetCountStart() {
- unsigned long currentResetMillis = millis();
- previousResetMillis = currentResetMillis;
- resetNow = false;
- }
- void displayCheck()
- {
- if (displayMainMessage == true)
- {
- lcdCoin = 0;
- editMode = false;
- lcd.setCursor(0, 0);
- lcd.print(F("Jhundeck Wi-Fi Vendo"));
- lcd.setCursor(0, 1);
- lcd.print(F(" "));
- }
- }
- void displayEditMode()
- {
- if (editMode == true)
- {
- //map420
- if (counterChange == 0)
- {
- lcd.setCursor(0, 0);
- lcd.print(F("EDIT MINUTE PER PISO"));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- perPisoMin = counter;
- ep_write(epAddrPerPisoMin, perPisoMin);
- }
- else if (counterChange == 1)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 1 PRICE "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promo1 = counter;
- ep_write(epAddrPromoOnePrice, promo1);
- }
- else if (counterChange == 2)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 1 HOURS "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promoOne = counter;
- ep_write(epAddrPromoOneHours, promoOne);
- }
- else if (counterChange == 3)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 2 PRICE "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promo2 = counter;
- ep_write(epAddrPromoTwoPrice, promo2);
- }
- else if (counterChange == 4)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 2 HOURS "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promoTwo = counter;
- ep_write(epAddrPromoTwoHours, promoTwo);
- }
- else if (counterChange == 5)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 3 PRICE "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promo3 = counter;
- ep_write(epAddrPromoThreePrice, promo3);
- }
- else if (counterChange == 6)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 3 HOURS "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promoThree = counter;
- ep_write(epAddrPromoThreeHours, promoThree);
- }
- else if (counterChange == 7)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 4 PRICE "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promo4 = counter;
- ep_write(epAddrPromoFourPrice, promo4);
- }
- else if (counterChange == 8)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 4 HOURS "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promoFour = counter;
- ep_write(epAddrPromoFourHours, promoFour);
- }
- else if (counterChange == 9)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 5 PRICE "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promo5 = counter;
- ep_write(epAddrPromoFivePrice, promo5);
- }
- else if (counterChange == 10)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" EDIT PROMO 5 HOURS "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- promoFive = counter;
- ep_write(epAddrPromoFiveHours, promoFive);
- }
- else if (counterChange == 11)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" PROMO 1 TO 5 PRICE "));
- lcd.setCursor(0, 1);
- lcd.print(F("AND HOURS ARE SAVED!"));
- lcd.setCursor(0, 2);
- lcd.print(F("PLEASE WAIT........."));
- lcd.setCursor(0, 3);
- lcd.print(F(" "));
- counterChange = 0;
- delay(3000);
- lcd.clear();
- resetVariable();
- displayMainMessage = true;
- editMode = false;
- }
- }
- }
- void noNegative()
- {
- if (counter < 0)
- {
- counter = 0;
- }
- }
- void displayVoucher()
- {
- if (displayVouch)
- {
- M_command += "/ip hotspot user add name=";
- M_command += userCode;
- M_command += " limit-uptime=";
- M_command += promoFinal;
- int command_len = M_command.length() + 1;
- char M_F_command[command_len];
- M_command.toCharArray(M_F_command, command_len);
- tc.sendCommand(M_F_command);
- lcd.setCursor(0, 0);
- lcd.print(F("Your voucher code is"));
- lcd.setCursor(0, 1);
- lcd.print(F(" <<"));
- lcd.print(userCode);
- lcd.print(F(">> "));
- //map320
- //
- // lcd.setCursor(0, 1);
- // lcd.print(promoFinal);
- format(promoFinal);
- M_command = "";
- memset(M_F_command , 0, sizeof(M_F_command ));
- }
- }
- void resetVariable()
- {
- counterChange = 0;
- displayVouch = false;
- editMode = false;
- displayMainMessage = true;
- counter = 0;
- dummyCounter = 0;
- displayCoinCount = false;
- coins = 0;
- }
- void displayCoin()
- {
- if (displayCoinCount)
- {
- lcd.setCursor(0, 0);
- lcd.print(F("Coins Inserted : "));
- lcd.setCursor(0, 1);
- lcd.print(coins);
- lcd.print(F(" "));
- lcdCoin = coins;
- // lcd.setCursor(4, 0);
- // // checkPromo();
- //
- // lcd.print(promoFinal);
- temp = promoFinal;
- format(promoFinal);
- }
- }
- void checkPromo()
- {
- // if (lcdCoin < promo1)
- // {
- // promoFinal = computation * lcdCoin;
- // }
- // else if (lcdCoin >= promo1 && lcdCoin < promo2)
- // {
- // promoTime = promoOne * promoHour;
- // promoComp = lcdCoin % promo1; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoFinal = inBetween + promoTime;
- // }
- // else if (lcdCoin >= promo2 && lcdCoin < promo3)
- // {
- // promoTime = promoTwo * promoHour;
- // promoComp = lcdCoin % promo2; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoFinal = inBetween + promoTime;
- //
- // }
- // else if (lcdCoin >= promo3 && lcdCoin < promo4)
- // {
- // promoComp = lcdCoin % promo3; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoTime = promoThree * promoHour;
- // promoFinal = inBetween + promoTime; //FINAL SHIT
- // }
- // else if (lcdCoin == promo4)
- // {
- // promoTime = promoFour * promoHour;
- // promoFinal = inBetween + promoTime;
- // }
- // else if (lcdCoin >= promo4 && lcdCoin < promo5)
- // {
- // promoComp = lcdCoin % promo4;
- // inBetween = promoComp * computation;
- // promoTime = promoFour * promoHour;
- // promoFinal = inBetween + promoTime;
- // }
- // else if (lcdCoin >= promo5)
- // {
- // promoComp = lcdCoin % promo5; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoTime = promoFive * promoHour;
- // promoFinal = inBetween + promoTime; //FINAL SHIT
- // }
- }
- void format( long seconds) {
- long W = seconds / 604800;
- seconds = seconds % 604800;
- long D = seconds / 86400;
- seconds = seconds % 86400; //map999
- long H = seconds / 3600;
- seconds = seconds % 3600;
- long M = seconds / 60;
- long S = seconds % 60;
- lcd.setCursor(0, 2);
- lcd.print(F("Voucher Duration : "));
- lcd.setCursor(0, 3);
- lcd.print(W);
- lcd.print(F("W"));
- lcd.print(F("-"));
- lcd.print(D);
- lcd.print(F("D"));
- lcd.print(F("-"));
- lcd.print(H);
- lcd.print(F("H"));
- lcd.print(F(":"));
- lcd.print(M);
- lcd.print(F("M"));
- lcd.print(F(" "));
- }
- void ep_write(int add, const int val)
- {
- int v = val;
- unsigned int i;
- for (i = 0; i < ep_limit; i++) {
- if (255 < v) {
- v = v - 255;
- EEPROM.write(add, 255);
- }
- else {
- EEPROM.write(add, v);
- v = 0;
- }
- add++;
- }
- }
- int ep_read(int add)
- {
- unsigned int v = 0;
- unsigned int i;
- for (i = 0; i < ep_limit; i++)
- {
- v = v + EEPROM.read(add);
- add++;
- }
- return v;
- }
Add Comment
Please, Sign In to add comment