0

hi I am using Arduino transmitter and receiver it works properly with sending and receiving username and password but I would include to check the username if its true open the led , I added this in the code but it seems that the code ignoring it ( the last part) as well as I want it to take the password and username at the same time

this is the recover code

#include <RH_ASK.h>//include radioHead ASK library 
#include <SPI.h> // include dependant SPI libray
 RH_ASK rf_driver; // create ASK object
int ledon = 13;
String userid;
String password;
 //RH_ASK ID1; // create ASK object
//RH_ASK pass1; // create ASK object
void setup() {
 rf_driver.init(); //initialize ASK object 
 Serial.begin(9600); //setup serial monitor to 9600
 //if(!rf_driver.init())
 //Serial.print("init failed"); 
}
void loop() {
 // set buffer to size of expected message 
 uint8_t buf[9]; 
 uint8_t buflen =sizeof(buf);
 //check if recevied packet is correct size
 if (rf_driver.recv(buf,&buflen))
 {
 int i;
 // message received with valid checksum 
 Serial.print("id: ");
 Serial.println((char*)buf);
 userid =(char*)buf;
 Serial.println(userid);
 }
delay(5000);
 uint8_t buf2[8]; 
 uint8_t buflen2 = sizeof(buf2);
 if (rf_driver.recv(buf,&buflen))
 {
 int i;
 // message received with valid checksum 
 Serial.print("password: ");
 Serial.println((char*)buf);
 password = (char*)buf;
 Serial.println(password);
 }
 delay(5000);
while ( userid =="A00034732" && password == "123456789"){
digitalWrite(ledon, HIGH);
delay(2000);
digitalWrite(ledon, LOW);
}
}

transmitter code ----

//Include RadioHead Amplitidue shift keying library 
#include <RH_ASK.h>
// Include dependatnt ISP library 
#include <SPI.h>
//create Ampitude shift keying object 
RH_ASK rf_driver;
void setup() {
 // intialize ASK objct
rf_driver.init();
Serial.begin(9600);
 //if(!rf_driver.init())
 //Serial.print("init failed");
}
void loop() 
{
 const char *pass= "123456789";
rf_driver.send((uint8_t *)pass, strlen(pass));
rf_driver.waitPacketSent();
delay(5000);
const char *ID= "A00034732";
rf_driver.send((uint8_t *)ID, strlen(ID));
rf_driver.waitPacketSent();
delay(5000);
//const char *pass= "12345678";
//rf_driver.send((uint8_t *)pass, strlen(pass));
//rf_driver.waitPacketSent();
//delay(5000);
}
chrisl
16.6k2 gold badges18 silver badges27 bronze badges
asked Nov 28, 2019 at 15:36

1 Answer 1

1

You're not comparing strings - you're comparing addresses of strings. Use strcmp().

while ( 
 (strcmp(userid, "A00034732") == 0) && 
 (strcmp(password, "123456789") == 0)
) {
answered Nov 28, 2019 at 16:02
1
  • I want to convert it to integer Commented Nov 28, 2019 at 17:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.