Saving

I was wondering how you can save two messages from the server in two different variables on the arduino?

THANKS!

You seem to be missing quite a lot of information from your question. Care to try again?

My question was this!

#include <SPI.h>
#include <Ethernet.h>

byte mac = { 0x90, 0xA2, 0xDA, 0x0F, 0x50, 0x35 };

IPAddress arduino(192,168,0,12);
IPAddress server(192,168,0,15);

EthernetClient client;

String username = {“Admin”,“Skut”,“Arbek”,“Kubda”};
String password = {“12344”,“stra”,“124ssgra”,"!#¤%"};

void setup() {
Serial.begin(9600);
Ethernet.begin(mac,arduino);
Serial.println(“Connecting…”);
if (client.connect(server, 8888)){
Serial.println(“Connected to Server”);
} else {
Serial.println(“Connecting failed”);
}
}

boolean verify(){
for(int i = 0; i < 4 ; i++){
if((username == “Admein”) && (password == “12344”)){
* return true;*
* }*
* }*
* return false;*
}
void loop(){
* if (client.available()){*
* char c[2];*
* for(int i = 0; i < 2 ; i++){*
_ c = client.read();
* Serial.print(c[1]);
//Serial.print(c[2]);
}
}*_

if (!client.connected()){
* Serial.println();*
* client.stop();*

* while(true);*
}
}
The question is! How can you save a username and a password sent from the server in two different variables o the arduino?

THis bit of "code" you posted :

if((username == "Admein") && (password == "12344")){
return true;

will not work. But you probably wrote

    if((username[i] == "Admein") && (password[i] == "12344")){
     return true;

which is why you MUST USE THE [code] [/code] tags around code so [i] shows instead of turning on italics.

until then it is too hard to read your code.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x50, 0x35 };

IPAddress arduino(192,168,0,12);
IPAddress server(192,168,0,15);

EthernetClient client;

String username[] = {"Admin","Skut","Arbek","Kubda"};
String password[] = {"12344","stra","124ssgra","!#¤%"};

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac,arduino);
  Serial.println("Connecting...");
  if (client.connect(server, 8888)){
   Serial.println("Connected to Server");
  } else {
    Serial.println("Connecting failed");
  }
}

boolean verify(){
  for(int i = 0; i < 4 ; i++){
    if((username == "Admein") && (password == "12344")){
     return true;
    }
  }
  return false;
}

void loop(){
  if (client.available()){
    char c[2];
    for(int i = 0; i < 2 ; i++){
      c = client.read();
      Serial.print(c[1]);
      //Serial.print(c[2]);
  }
 }
 
 if (!client.connected()){
   Serial.println();
   client.stop();
   
   while(true);
 }
}

Could you go through the steps of what your program is doing? The logic of it? I personally don't understand the for loop.

Hello!

This is the new code! Hope you understand it this time!

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x50, 0x35 };

IPAddress arduino(192,168,0,50);
IPAddress server(192,168,0,15);

EthernetClient client;

String username[] = {"Admin","Skut","Arbek","Kubda"};
String password[] = {"12344","stra","124ssgra","!#¤%"};

String readString;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac,arduino);
  Serial.println("Connecting...");
  if (client.connect(server, 8888)){
   Serial.println("Connected to Server");
  } else {
    Serial.println("Connecting failed");
  }
}

void clientRead() { 
  while (client.available()) {
  //delay(10);  
    if (client.available() >0) {
      char c = client.read();
      readString += c;
    }
}
}

boolean verify(String firstText, String secondText){
  for(int i = 0; i <= 3 ; i++){
    if((firstText.equals(username[i])) && (secondText.equals(password[i]))){ 
      return true; 
    }
  }
    return false;
   }

void loop(){
  if (client.available() > 0){
    readString = "";
    clientRead();
    int n = readString.length();
    int commaIndex = readString.indexOf(';');
    int lastIndex = readString.lastIndexOf(n);
    String firstText = readString.substring(0, commaIndex);
    String secondText = readString.substring(commaIndex + 1 , lastIndex);
    Serial.println(firstText);
    Serial.println(secondText);
    Serial.println(verify(firstText, secondText));
  }

 if (!client.connected()){
   Serial.println("Server disconnected!");
   client.stop();
   client.flush();
   while(true);
 }
}

dannable:
Could you go through the steps of what your program is doing? The logic of it? I personally don't understand the for loop.

+1

Describing the detailed steps of the program in plain language (rather than computer code) is a great way to discover errors and uncertainties in the logic.

...R