Hi everyone,
Is it possible to run this sketch (DHCPadressprinter) from the example list, in an other program, so it automaticly update my IP adress if it change?
Code to run every time my arduino power-up:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
Can someone write down a bit of code I should use to take the output of DHCPadress printer and place it in the IP adress section of this code?: (At about 1/3 of the code)
#include <SPI.h>
#include <Ethernet.h>
int number=0;
int time_1, time_2, time=0;
double up_time1, up_time2, up_time,upv;
// Adress variable
int four = 23, four_d = 23;
int three = 25, three_d = 25;
int two = 27,two_d = 27;
int one = 29, one_d = 29;
int adress, adress_2;
// END adress variable
//Sensors variable
float temp_bedroom=20.25;
float temp_kitchen=20.25;
float temp_washroom=20.25;
float temp_living=20.25;
//END sensors variable
// System status variable
int status_led = 22;
int sys_status=0;
// END System status variable
// Command over ethernet variable
boolean incoming = 0;
// END Command over ethernet variable
// Spam_block variable
int command;
int array[31];
int task=0;
int task_result =0;
// END Spam_block variable
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(208,92,17,141); //<<< ENTER YOUR IP ADDRESS HERE!!! //////////TO REPLACE THIS IP ADRESSS!!!!/////////////////////////////////////////////////////////////
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup()
{
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(status_led, OUTPUT);
pinMode(four, INPUT);
pinMode(three, INPUT);
pinMode(two, INPUT);
pinMode(one, INPUT);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
up_time1 = millis();
}
void loop()
{
command_over_ethernet();
led_status();
delay(1);
}
void command_over_ethernet()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
//reads URL string from $ to first blank space
if(incoming && c == ' '){
incoming = 0;
}
if(c == '
For lenght reason, I didnt put all my functions
So, As the last function is called show_ip_adress, how to I update the IP at the beginnning of my code?
THANKS){
incoming = 1;
}
//Checks for the URL string $1 or $2
if(incoming == 1){
char c = client.read();
//-------------------------------------------------------//
//Receive second code------------------------------------//
//-------------------------------------------------------//
if(c == '2'){
//Serial.println("ON");
//digitalWrite(2, LOW);
char c = client.read();
//-------------------------------------------------------//
//Send sensors status------------------------------------//
//-------------------------------------------------------//
if(c == '0'){
}
//-------------------------------------------------------//
//Fermer le néon des plante------------------------------//
//-------------------------------------------------------//
if(c == '1'){
}
}
if(c == '2'){
}
//-------------------------------------------------------//
if(c == '3'){
}
if(c == '4'){
}
if(c == '5'){
}
if(c == '6'){
}
if(c == '7'){
}
if(c == '8'){
}
if(c == '9'){
}
break;
}
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void show_IP_ADRESS(){
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
}
For lenght reason, I didnt put all my functions
So, As the last function is called show_ip_adress, how to I update the IP at the beginnning of my code?
THANKS