I have looked through the forum posts and just need some clarification for my specific project. This question is similar to the one here. I am also fairly inexperienced configuring these projects to different types of networks and will try to explain as much as possible.
I am trying to use the ESP8266 module in our high school robotics course as an IOT platform with Blynk. I have had great success on my home network which did not require a username. At our school we have a WPA2 network requiring a username and password. It seems as though Blynk.config()
may be a way to solve this problem but I am not sure how to implement it.
Below is a sketch that remotely controls a two wheeled with the Blynk phone app. It works on my home network. How would I alter this code below to add a username?
/*Sketch designed for the ESP8266
* Receives commands form Blynk
* Sends motor control commands to Arduino via serial for control of a 2-wheeled robot
*
* Joystick conversion formula is based on explanations at http://home.kendra.com/mauser/joystick.html
*
* by Steve Cline on 24 July 2018
*/
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetLCD lcd(V2);
// variables to store virtual pin values from Blynk app
int pinV0 = 0;
int pinV1 = 0;
int pinV3 = 0;
//variables to store speed and direction values for motors
int Rspeed = 0;
int Lspeed = 0;
int fastVal = 0;
int stopVal = 0;
int reverseVal = 0;
float V = 0;
float W = 0;
int i;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "37d92a576bc943158959ecb03f2c5dbe";
// WiFi credentials.
char ssid[] = "Network_name";
char pass[] = "Network_pass";
void setup(){
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}
void loop(){
Blynk.run();
speedChk();
speedCalc();
checkSpeeds();
sendLCD();
controlSend();
}
BLYNK_WRITE(V1){
pinV1 = param.asInt(); // assigns incoming value from y axis to pinV1 variable
}
BLYNK_WRITE(V0){
pinV0 = param.asInt(); // assigns incoming value from x axis to pinV0 variable
}
BLYNK_WRITE(V3){
pinV3 = param.asInt(); // assigns incoming value from speed button to pinV3 variable
}
void speedChk(){
if (pinV3 == 1){
fastVal = 1;
}
else {
fastVal = 0;
}
}
void controlSend(){
Serial.write("<");
Serial.write(stopVal);
Serial.write(reverseVal);
Serial.write(fastVal);
Serial.write(Rspeed);
Serial.write(Lspeed);
Serial.write(">");
}
void speedCalc(){
if (pinV1 > 0){
stopVal = 0;
reverseVal = 0;
if (pinV0 > 0){
Lspeed = pinV1;
Rspeed = pinV1 - pinV0;
}
else if (pinV0 < 0) {
Lspeed = pinV1 - abs(pinV0);
Rspeed = pinV1;
}
}
else if (pinV1 < 0){
stopVal = 0;
reverseVal = 1;
if (pinV0 > 0) {
Lspeed = abs(pinV1);
Rspeed = abs(pinV1) - pinV0;
}
else if (pinV0 < 0){
Lspeed = abs(pinV1) - abs(pinV0);
Rspeed = abs(pinV1);
}
}
else {
stopVal = 1;
Lspeed = 0;
Rspeed = 0;
}
}
void checkSpeeds(){
if (Lspeed <=0){
Lspeed = 0;
}
else if (Rspeed <= 0){
Rspeed = 0;
}
}
void sendLCD(){
if (stopVal == 1){
lcd.clear();
lcd.print(3, 0, "ROBOT STOPPED");
}
else if (fastVal == 1){
lcd.clear();
lcd.print(0,0, "LEFT RIGHT");
lcd.print(1,1, Lspeed);
lcd.print(8,1, Rspeed);
lcd.print(12,1, "HIGH");
}
else {
lcd.clear();
lcd.print(0,0, "LEFT RIGHT");
lcd.print(1,1, Lspeed);
lcd.print(8,1, Rspeed);
lcd.print(12,1, "LOW");
}
}