0% found this document useful (0 votes)
60 views5 pages

Cod

This document contains code for an Arduino project that generates random WiFi hotspot access codes. It includes code to read inputs from buttons and coins, display information on an LCD screen, generate random codes using an entropy source and letters array, and send the codes to a Mikrotik router via telnet to configure new hotspot users. Variables and constants are declared to store coin amounts, time values, the script for the telnet command, and to control pins for buttons, LEDs, and an LCD screen.

Uploaded by

Joel Moore
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
60 views5 pages

Cod

This document contains code for an Arduino project that generates random WiFi hotspot access codes. It includes code to read inputs from buttons and coins, display information on an LCD screen, generate random codes using an entropy source and letters array, and send the codes to a Mikrotik router via telnet to configure new hotspot users. Variables and constants are declared to store coin amounts, time values, the script for the telnet command, and to control pins for buttons, LEDs, and an LCD screen.

Uploaded by

Joel Moore
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 5

#include <SPI.

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

#define randomSeed(s) srandom(s)

int i = 0;
int days = 0;
int mins = 0;
int hours = 0;
int newmins = 0;
int newhours = 0;
int buttonPress = 0;

const int ledpin = 5;


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

volatile float coins = 0;

unsigned long startMillis = 0;


unsigned long currentMillis = 0;

uint32_t seed_value;

char letters[37] = {'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'};

char script[56] = {'/', 'i', 'p', ' ', 'h', 'o', 't', 's', 'p', 'o', 't', ' ', 'u',
's', 'e', 'r', ' ', 'a', 'd', 'd', ' ', 'n', 'a', 'm', 'e', '=', '0', '0', '0',
'0', ' ', 'l', 'i', 'm', 'i', 't', '-', 'u', 'p', 't', 'i', 'm', 'e', '=', '0',
'0', 'd', '0', '0', ':', '0', '0', ':', '0', '0'};

LiquidCrystal_I2C lcd(0x27, 20, 4);

EthernetClient client;
telnetClient tc(client);

byte clientMAC[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };


IPAddress clientIp (192, 168, 88, 2);

//put here your router's ip address


IPAddress mikrotikRouterIp (192, 168, 88, 1);

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) {
; // wait for serial port to connect
}

Entropy.initialize();

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

}
void coinInterrupt() {

coins = coins + 1;

startMillis = millis(); //initial start time


}

void loop() {

if (coins < 1) {

//Serial.println("Please Insert Coin");

lcd.setCursor(0, 0);
lcd.print(" ");

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

lcd.setCursor(0, 2);
lcd.print(" ");

lcd.setCursor(0, 3);
lcd.print(" ");
}

currentMillis = millis(); //get the current time

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

if (coins < 5) {
mins = coins * 15;
}
if (coins >= 5 && coins < 10) {
mins = coins * 30;
}
if (coins >= 10 && coins < 15) {
mins = coins * 45;
}
if (coins >= 15) {
mins = coins * 60;
}

hours = mins / 60;


days = hours / 24;
newhours = hours - (days * 24);
newmins = mins - (hours * 60);

script[44] = '0' + ((days / 10) % 10); // tens digit


script[45] = '0' + (days % 10); // ones digit
script[47] = '0' + ((newhours / 10) % 10); // tens digit
script[48] = '0' + (newhours % 10); // ones digit
script[50] = '0' + ((newmins / 10) % 10); // tens digit
script[51] = '0' + (newmins % 10); // ones digit

//Serial.println(coins);
//Serial.println(days);
//Serial.println(hours);
//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(hours);
lcd.print(" hrs ");
lcd.print(newmins);
lcd.print(" min ");
}

currentMillis = millis(); //get the current time

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(); //get the current time

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

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

while (digitalRead(buttonpin) == LOW) {

//do nothing

digitalWrite(ledpin, LOW);
seed_value = Entropy.random();

//Serial.println(seed_value);

randomSeed(seed_value);

script[26] = letters[random(0, 36)];


script[27] = letters[random(0, 36)];
script[28] = letters[random(0, 36)];
script[29] = letters[random(0, 36)];
script[56] = '\r';

//Serial.print(&script[26]);

lcd.setCursor(0, 0);
lcd.print(" CODE GENERATED ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.print(script[26]);
lcd.print(" ");
lcd.print(script[27]);
lcd.print(" ");
lcd.print(script[28]);
lcd.print(" ");
lcd.print(script[29]);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");

Ethernet.begin (clientMAC);

//want to use dhcp?


if (!Ethernet.begin (clientMAC)) {
Serial.println("\r\nDHCP error");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("DCHP error");
while (1);

tc.setPromptChar('>');

//PUT HERE YOUR USERNAME/PASSWORD


if (tc.login(mikrotikRouterIp, "admin", "")) {

//tc.login(mikrotikRouterIp, "admin", "", 1234) if you want to specify a port


different than 23

delay(1000);

tc.sendCommand(script);

delay(5000);

tc.disconnect();
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(script[26]);
lcd.print(" ");
lcd.print(script[27]);
lcd.print(" ");
lcd.print(script[28]);
lcd.print(" ");
lcd.print(script[29]);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" THANK YOU ");

delay(5000);

coins = 0;
digitalWrite(disablepin, HIGH);

}
}
}

You might also like