What's new

Help Captive portal for Esp8266

redyw

Eternal Poster
Established
Joined
Jul 23, 2012
Posts
692
Reaction
55
Points
305
Mga papss baka may marunong sa arduino code dito,,
Patulong naman po,,

Pano po yung captive portal na may voucher code
 
// WIFI Vendo... Mikrotik
// try nyo po ito kng gagana sa inyo
// feedback lng po kayo sa akin.. :unsure::unsure::coffee::coffee::coffee::):):););)

//ARDUINO using NODEMCU ESP8266
//kayo na po bahala mag debug... hope na makuha nyo.. pls help me din kng paano to maayos..

#include <SPI.h>
#include <Wire.h>
#include <Entropy.h>
#include <Ethernet.h>
#include <TelnetClient.h>
#include <LiquidCrystal_I2C.h>

#define randomSeed(s) srandom(s)

unsigned int mins = 0;
unsigned int hours = 0;
unsigned int days = 0;
unsigned int newminuntes = 0;
unsigned int newhourly = 0;
int buttonPress = 0;
int ledState = LOW;
int gates = 0;
int intervals = 0;
int start = 0;

const int ledpin = 5;
const int coinpin = 2;
const int buttonpin = 3;
const int disablepin = 4;

volatile int coins = 0;

unsigned long startMillis = 0;
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;

String script;

uint32_t seed_value;

char letters[36] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};

LiquidCrystal_I2C lcd(0x27, 20, 4);

EthernetClient client;
telnetClient tc(client);

//client IP here
byte clientMAC[] = { 0xAB, 0xBC, 0xCD, 0xDE, 0xEF, 0xFA };
IPAddress clientIp (0, 0, 0, 0);

//put here your router's IP address
IPAddress mikrotikRouterIp (0, 0, 0, 0);


void setup() {

pinMode(buttonpin, INPUT);
pinMode(ledpin, OUTPUT);
pinMode(disablepin, OUTPUT);

lcd.begin();
lcd.backlight();

lcd.clear();
lcd.setCursor(0, 0);
lcd.print("initializing....");
lcd.setCursor(0, 2);
lcd.print(" by asantos1");

delay(3000);

digitalWrite(disablepin, HIGH);

Serial.begin(9600);

while (!Serial) {
;
}

Entropy.initialize();

pinMode(buttonpin, INPUT);
pinMode(ledpin, OUTPUT);
pinMode(disablepin, OUTPUT);

lcd.clear();

attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);

}
void coinInterrupt() {

coins ++;
startMillis = millis();

}
void blinker() {

unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {

previousMillis = currentMillis;

if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}

digitalWrite(ledpin, ledState);
}
}

void loop() {

if (gate == 0) {

digitalWrite(disablepin, LOW);

lcd.setCursor(0, 1);
lcd.print(" Press Button ");
lcd.setCursor(0, 2);
lcd.print(" to Start ");

while (digitalRead(buttonpin) == LOW) {

interval = 1000;
blinker();
}

gate = 1;
coins = 0;

}

if ((gate == 1) && (start == 0)) {

digitalWrite(disablepin, HIGH);
digitalWrite(ledpin, LOW);

lcd.setCursor(0, 1);
lcd.print(" Insert Coin ");
lcd.setCursor(0, 2);
lcd.print(" ");

start = 1;
startMillis = millis();
}

currentMillis = millis();

if ((start == 1) && (coins < 1) && (currentMillis - startMillis >= 15000)) {

gate = 0;
start = 0;

}

if ((start == 1) && (coins > 0) && (currentMillis - startMillis >= 100)) {

// ADJUST RATES HERE
if (coins < 5) {
mins = coins * 10; // 15min/peso
}
if (coins >= 5 && coins < 10) {
mins = coins * 20; // 20min/peso
}
if (coins >= 10 && coins < 15) {
mins = coins * 30; // 30min/peso
}
if (coins >= 15) {
mins = coins * 45; // 45min/peso
}
hours = floor(mins / 60);
days = floor(hours / 24);
newhours = hours - (days * 24);
newmins = mins - (hours * 60);

Serial.println(coins);
Serial.println(days);
Serial.println(newhours);
Serial.println(newmins);

lcd.setCursor(0, 0);
lcd.print(" Credit: ");
lcd.print(coins, 0);
lcd.print(".00 ");

lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(days);
lcd.print(" day ");
lcd.print(newhours);
lcd.print(" hr ");
lcd.print(newmins);
lcd.print(" min");



}

currentMillis = millis();

if ((coins > 0) && (currentMillis - startMillis >= 10000)) {

lcd.setCursor(0, 2);
lcd.print(" Press Button to");
lcd.setCursor(0, 3);
lcd.print(" Generate Code");

}

currentMillis = millis();

if ((coins > 0) && (currentMillis - startMillis >= 11000)) {

digitalWrite(disablepin, LOW);

while (digitalRead(buttonpin) == LOW) {
interval = 150;
blinker();

}
digitalWrite(ledpin, LOW);

seed_value = Entropy.random();

randomSeed(seed_value);

char c[2] = {letters[random(36)]};
char o[2] = {letters[random(36)]};
char d[2] = {letters[random(36)]};
char e[2] = {letters[random(36)]};

lcd.setCursor(0, 0);
lcd.print(" CODE GENERATED ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.print(c);
lcd.print(" ");
lcd.print(o);
lcd.print(" ");
lcd.print(d);
lcd.print(" ");
lcd.print(e);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");

script = "ip hotspot user add name=";
script += c;
script += o;
script += d;
script += e;
script += " limit-uptime=";
script += mins;
script += "m profile=hotspot";
int script_len = script.length() + 1;
char mscript[script_len];
script.toCharArray(mscript, script_len);

Ethernet.begin (clientMAC);

//want to use dhcp?
if (!Ethernet.begin (clientMAC)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("DCHP error ");
lcd.setCursor(0, 1);
lcd.print(coins);

while (1);

}

tc.setPromptChar('>');

//CHANGE HERE YOUR USERNAME/PASSWORD
if (tc.login(mikrotikRouterIp, "@admin@", "@@password@@")) {

delay(1000);

tc.sendCommand(mscript);

delay(5000);

tc.disconnect();

lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(c);
lcd.print(" ");
lcd.print(o);
lcd.print(" ");
lcd.print(d);
lcd.print(" ");
lcd.print(e);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" THANK YOU ");

delay(10000);

lcd.clear();
coins = 0;
gate = 0;
start = 0;
}
}
 
Last edited:
Mikrotek pa rin kailangan nito,,

Ganito sana magiging setup
Di na dadaan sa mikrotek

PLDT Fibr >> esp8266 >> voucher code client
 
Wala ehh,, kunti lang alam ko sa pagcode,,

Ano gamit mo microcontroller paps,
 
Parang ganito

PLDT fibr >> nodemcu/esp8266 >> client phone

Voucher type mangyayari through captive portal nang nodemcu/esp8266
 
bali trabaho lang ni esp gumawa ng user account na may limit. if yung pldt mo pwede magcreate ng user na my limit ang time pwede yan.. ndi c esp ang magcut jan.. trabaho lang nyan taga gawa ng user account mali po kc ata pagkakaintindi nyu sir sa trabaho ni esp kay mikrotik.
 
kung naka mikrotik kayo mga lods si Mikhmon gamiton nyo para taga create ng account at taga gawa ng vouchers ng maramihan.
 

Similar threads

Back
Top