Setting up Blynk for EXP8266 with WPA2

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"); 
  }
}

Do you mean this bit, that’s already there in your code?

Pete.

1 Like

Everything i ever read about the esp8266 and 802.1x auth (or in this case, wpa2 enterprise), always turned out to be a dead end. The security needed for the library made the size out of reach for most arduino projects.

Two options i can think of. Use your phone as a hotspot for the device. OR ask the net admin for a pre shared key network (we all have them, but we like to hide them, so we shut off broadcasting). There is probably an old pre shared key network out there because really old equipment needs it. Air Handlers, Gas meters. Industrial style building maintenance gear.

I also need to add a username since this is WPA2 enterprise.

This sounds more like a portal based access (I think that is the term). Blynk needs direct access to the Cloud server, so unless your school’s IT department allows such (including port forwarding) you will not get it to work that way.

You could look at using your phone to setup a internet hotspot that your device connects through, or creating a portable Local Server with AP, then connecting your phone and device to it. A bit of an advanced process, but up to you to chose to learn how.

If you are only using the server in the classroom you could bring your own blynk server.