Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified WifiSerial to exclude <string> library #155

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#ifdef MANUAL_INPUT // initialise ssid string, pwd string, and serial_in object
// Initialise strings
std::string str_ssid, str_pass, str_key;
String str_ssid, str_pass, str_key;
// Create serial_in object
WifiSerial wifiSerial;
#endif
Expand Down Expand Up @@ -120,11 +120,14 @@ void setup() {
#endif
#else
char ssid_cust[str_ssid.length()+1];
char key_cust[str_key.length()+1];
char pass_cust[str_pass.length()+1];
strcpy(ssid_cust, str_ssid.c_str());
strcpy(key_cust, str_key.c_str());
strcpy(pass_cust, str_pass.c_str());
Serial.println(str_ssid.c_str());
status = WiFi.begin(ssid_cust,std::stoi( str_key ), pass_cust);
status = WiFi.begin(ssid_cust,atoi(key_cust), pass_cust);
str_ssid, str_key, str_pass = "";
#endif
// wait 10 seconds for connection:
delay(10000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include "WifiSerial.h"

// Set if user wants to key in ssid/pwd manually during operation
//#define MANUAL_INPUT
//#define MANUAL_INPUT

#ifdef MANUAL_INPUT // Initialise ssid string, pwd string, and serial_in object
// Initialise strings
std::string str_ssid, str_pass;
String str_ssid, str_pass;
// Create serial_in object
WifiSerial wifiSerial;
#endif
Expand Down Expand Up @@ -65,7 +65,7 @@ void setup() {
Serial.println("Enter your password");
while (str_pass.length() == 0) {
str_pass = wifiSerial.readInput();
if (str_pass.length() != 0) { // user has entered data
if (str_pass.length() != 0) { // user has entered data
if (str_pass.length() <8) { // to catch pwd<8 exception
Serial.println("Password cannot be less than 8 characters! Try again");
str_pass = ""; // clear entered pwd and try again
Expand All @@ -76,7 +76,7 @@ void setup() {
}
#endif
Serial.print("Attempting to connect to WPA SSID: ");

#ifndef MANUAL_INPUT
Serial.println(ssid);
// Connect to WPA/WPA2 network:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include "WifiSerial.h"

// Set if user wants to key in ssid/pwd manually during operation
//#define MANUAL_INPUT
//#define MANUAL_INPUT

#ifdef MANUAL_INPUT // Initialise ssid string, pwd string, and serial_in object
// Initialise strings
std::string str_ssid, str_pass;
String str_ssid, str_pass;
// Create serial_in object
WifiSerial wifiSerial;
#endif
Expand Down
4 changes: 2 additions & 2 deletions Arduino_package/hardware/libraries/WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef wificlient_h
#define wificlient_h
#ifndef WifiClient_h
#define WifiClient_h

#include "Print.h"
#include "Client.h"
Expand Down
4 changes: 2 additions & 2 deletions Arduino_package/hardware/libraries/WiFi/src/WiFiSSLClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef wifisslclient_h
#define wifisslclient_h
#ifndef WifiSSLClient_h
#define WifiSSLClient_h

#include "Print.h"
#include "Client.h"
Expand Down
4 changes: 2 additions & 2 deletions Arduino_package/hardware/libraries/WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef wifiserver_h
#define wifiserver_h
#ifndef WifiServer_h
#define WifiServer_h

#include "Server.h"
#include "server_drv.h"
Expand Down
4 changes: 2 additions & 2 deletions Arduino_package/hardware/libraries/WiFi/src/WiFiUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef wifiudp_h
#define wifiudp_h
#ifndef WifiUdp_h
#define WifiUdp_h

#include "IPAddress.h"
#include "IPv6Address.h"
Expand Down
11 changes: 4 additions & 7 deletions Arduino_package/hardware/libraries/WiFi/src/WifiSerial.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#include "WifiSerial.h"
#include <stdlib.h>
#include <Arduino.h>
#include <string>

WifiSerial::WifiSerial() {}//declaration


//Function: Reads Serial monitor input
//Output : std::string
std::string WifiSerial::readInput() {
const char* WifiSerial::readInput() {
currentInput = ""; //clear string output in preparation
String name;
while (Serial.available()) {
delay(2); //add a delay to buy time for bytes to enter buffer
char c = Serial.read();
name += c;
delay(2); //add a delay to buy time for bytes to enter buffer
char c = Serial.read();
name += c;
}
if (name.length() > 0) { //loop triggers when Serial data is received.
name.trim(); //removes trailing newline
Expand Down
11 changes: 7 additions & 4 deletions Arduino_package/hardware/libraries/WiFi/src/WifiSerial.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <string>
#ifndef WifiSerial_h
#define WifiSerial_h

class WifiSerial {
public:
WifiSerial();
std::string readInput();
WifiSerial();
const char* readInput();

private:
std::string currentInput;
const char* currentInput;
};

#endif