/*
this is not a finished code, pagtulungan natin mabuo,
ive taken parts of code from other sources and put this together
di ko pa mahuli kng pano mg send command to add/delete user sa mk
it gets the ip address of the router, then logs in to the mikrotik router
*/
#include <SPI.h>
#include <Ethernet.h>
#include <TelnetClient.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
EthernetClient client;
telnetClient tc(client);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection:
Serial.println("Communicating");
lcd.setCursor(0,0);
lcd.print("Communicating");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
lcd.setCursor(0,0);
lcd.print("Failed to configure Ethernet");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. ");
lcd.setCursor(0,0);
lcd.print("Ethernet shield was not found.");
} else if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
lcd.setCursor(0,0);
lcd.print("Ethernet cable is not connected.");
}
// no point in carrying on, so do nothing forevermore:
while (true) {
delay(1);
}
}
// print your local IP address:
//Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
lcd.setCursor(0,0);
lcd.print(Ethernet.localIP());
Serial.println(Ethernet.subnetMask());
lcd.setCursor(0,1);
lcd.print(Ethernet.subnetMask());
//Serial.println(Ethernet.gatewayIP());
Serial.println(Ethernet.dnsServerIP());
lcd.setCursor(0,2);
lcd.print(Ethernet.dnsServerIP());
Ethernet.begin (mac, Ethernet.localIP());
//how long the command sent may be long
const uint8_t MAX_OUT_BUFFER_LENGTH = 150;
IPAddress mikrotikRouterIp (Ethernet.dnsServerIP());
//want to use dhcp?
//if (!Ethernet.begin (clientMAC)){
//Serial.println("\r\nDHCP error");
//while(1);
//}
//WICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
tc.setPromptChar('>');
//this is to trigger manually the login
//since it could be a problem to attach the serial monitor while negotiating with the server (it cause the board reset)
//remove it or replace it with a delay/wait of a digital input in case you're not using the serial monitors
//char key = 0;
//Serial.println("\r\npress Enter to begin:");
//do{
// key = Serial.read();
//}while(key<=0);
delay(5000);
//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
tc.sendCommand("ip");
tc.sendCommand("address");
tc.sendCommand("print");
}
else{
Serial.println("login failed");
}
tc.disconnect();
}
void loop() {
switch (Ethernet.maintain()) {
case 1:
//renewed fail
Serial.println("Error: renewed fail");
break;
case 2:
//renewed success
Serial.println("Renewed success");
//print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
break;
case 3:
//rebind fail
Serial.println("Error: rebind fail");
break;
case 4:
//rebind success
Serial.println("Rebind success");
//print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
break;
default:
//nothing happened
break;
}
}
this is not a finished code, pagtulungan natin mabuo,
ive taken parts of code from other sources and put this together
di ko pa mahuli kng pano mg send command to add/delete user sa mk
it gets the ip address of the router, then logs in to the mikrotik router
*/
#include <SPI.h>
#include <Ethernet.h>
#include <TelnetClient.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
EthernetClient client;
telnetClient tc(client);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection:
Serial.println("Communicating");
lcd.setCursor(0,0);
lcd.print("Communicating");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
lcd.setCursor(0,0);
lcd.print("Failed to configure Ethernet");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. ");
lcd.setCursor(0,0);
lcd.print("Ethernet shield was not found.");
} else if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
lcd.setCursor(0,0);
lcd.print("Ethernet cable is not connected.");
}
// no point in carrying on, so do nothing forevermore:
while (true) {
delay(1);
}
}
// print your local IP address:
//Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
lcd.setCursor(0,0);
lcd.print(Ethernet.localIP());
Serial.println(Ethernet.subnetMask());
lcd.setCursor(0,1);
lcd.print(Ethernet.subnetMask());
//Serial.println(Ethernet.gatewayIP());
Serial.println(Ethernet.dnsServerIP());
lcd.setCursor(0,2);
lcd.print(Ethernet.dnsServerIP());
Ethernet.begin (mac, Ethernet.localIP());
//how long the command sent may be long
const uint8_t MAX_OUT_BUFFER_LENGTH = 150;
IPAddress mikrotikRouterIp (Ethernet.dnsServerIP());
//want to use dhcp?
//if (!Ethernet.begin (clientMAC)){
//Serial.println("\r\nDHCP error");
//while(1);
//}
//WICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
tc.setPromptChar('>');
//this is to trigger manually the login
//since it could be a problem to attach the serial monitor while negotiating with the server (it cause the board reset)
//remove it or replace it with a delay/wait of a digital input in case you're not using the serial monitors
//char key = 0;
//Serial.println("\r\npress Enter to begin:");
//do{
// key = Serial.read();
//}while(key<=0);
delay(5000);
//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
tc.sendCommand("ip");
tc.sendCommand("address");
tc.sendCommand("print");
}
else{
Serial.println("login failed");
}
tc.disconnect();
}
void loop() {
switch (Ethernet.maintain()) {
case 1:
//renewed fail
Serial.println("Error: renewed fail");
break;
case 2:
//renewed success
Serial.println("Renewed success");
//print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
break;
case 3:
//rebind fail
Serial.println("Error: rebind fail");
break;
case 4:
//rebind success
Serial.println("Rebind success");
//print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
break;
default:
//nothing happened
break;
}
}
Last edited: