0

Is it possible to have an Arduino Uno + WiFi 101 recognize when the USB cable has been connected and prompt a user to enter a network name and password?

Can this be stored on the Arduino itself or does it need to be something run locally on the user's PC?

asked Mar 22, 2016 at 7:14
2
  • Prompt the user where? The serial monitor? What do you want to be stored on the Arduino? Commented Mar 22, 2016 at 22:28
  • Good questions. I'd like a window with a few text fields to open. The user will input the network name and network password and press a submit button. The submission will amend the sketch and replace the old name/pass with the new. The file that opens the window would be stored on the Arduino (or is that unwise/not possible?). A clean-ish ui would be better than the terminal but the terminal would work I suppose. A user should not have to download and install the IDE. Think parents and non-tech friends Commented Mar 22, 2016 at 22:36

1 Answer 1

1

To render a UI, you need a PC program. It would handle presenting an interface as well as communicating the user's input to the Arduino over UART. I would recommend writing your own program as it would give you a lot of freedom in the UI design. Processing and Python are good options. To avoid using the IDE, you'll need a USB-TTL adapter cable. If you use the default USB connection, you need the drivers which only ship with the installer AFAIK. To detect the COM port, you can either have the user check the Device Manager or make your program auto-detect it, though this isnt very reliable. This link shows some Python code on detecting the Arduino's port or at least, displaying a list of open ports and allowing the user to choose. You can set the baud rate and other stuff permanently in your code; the COM port is the only variable. Also all handshaking b/w the Arduino and PC can be done without the knowledge of the user.

That said, there are already existing programs (for most common OSes) that can provide minimal functionality. If you dont need a fancy GUI, then putty (on Windows) can serve to read input from a user and pass it on to the listening Arduino. You can use putty's default baud rate (9600) in your Arduino sketch so that the user doesnt have to set this. Again, the COM port must be known. Device Manager is the only real option.

With this second approach, you could make a user enter some string (or even a char) in putty to prompt the Arduino to ask for the SSID and password. Once the Arduino is powered, it does nothing but wait for that input string and once it receives it, it sends something like: Enter SSID: , the user complies (and presses the Return key to terminate) and this is repeated for the password. The Arduino sketch would look like this:

#define MAX_LEN 20 //max length of name or password
char PROMPT[] = "ready\r" //the initial string input from a user
char SSID[MAX_LEN]; // buffers for the ssid and pwd
char PWD[MAX_LEN];
init_done = 0; // this var is set when an ssid and pwd have been received
void setup(){
 Serial.begin(9600);
 //anything else
}
void loop(){
 if (!init_done)
 continue;
 // your other code
}
void get_data(){
 Serial.print("Enter Network SSID: \r\n");
 while (Serial.available() == 0); // wait for input
 // no timeouts used here; wait till user presses return key
 int i = 0;
 char c;
 while (i < MAX_LEN - 1){ // read chars till the buffer is almost full
 c = Serial.read();
 if (c == '\r') // means end of input
 break;
 SSID[i++] = c;
 while (Serial.available() == 0); // wait for next char
 }
 SSID[i] = 0; // null terminate
 while (Serial.read() != -1); // flush serial buffer 
 Serial.print("Enter password: \r\n"); //same as before
 while (Serial.available() == 0); 
 i = 0;
 while (i < MAX_LEN - 1){
 c = Serial.read();
 if (c == '\r') // end of input
 break;
 PWD[i++] = c;
 while (Serial.available());
 }
 PWD[i] = 0;
 while (Serial.read() != -1); 
 //Serial.print("Done.");
 init_done = 1;
}
void serialEvent(){
 if (!init_done){
 while (Serial.peek() != PROMPT[0]) // read off any garbage
 Serial.read(); 
 int i = 0;
 while (1){
 if (Serial.peek() == PROMPT[i++]) // compare received chars to PROMPT
 Serial.read();
 else
 return
 if (i == sizeof(PROMPT)){ // read enough chars
 while (Serial.read() != -1); // flush the buffer 
 get_data(); // get ssid and so on
 }
 }
 }
answered Mar 23, 2016 at 1:19

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.