Reading input pin in arduino using esp8266ex via blynk

{
  buttonState = digitalRead(buttonPin);
  if(buttonState == LOW){
    digitalWrite(buttonpin,HIGH);
    digitalWrite(ledpin,HIGH);
  }
  else{
    digitalWrite(buttonpin,LOW);
    digitalWrite(ledpin,LOW);
    }
  }

I’m getting the following errors in my sketch

C:\Users\TV\Desktop\mbeva\ESP8266_Standalone_version_1_morena_2_with_button_pressed\ESP8266_Standalone_version_1_morena_2_with_button_pressed.ino: In function ‘void loop()’:

ESP8266_Standalone_version_1_morena_2_with_button_pressed:55:15: error: expected primary-expression before ‘=’ token

buttonState = digitalRead(buttonPin);

           ^

ESP8266_Standalone_version_1_morena_2_with_button_pressed:55:29: error: ‘buttonPin’ was not declared in this scope

buttonState = digitalRead(buttonPin);

                         ^

ESP8266_Standalone_version_1_morena_2_with_button_pressed:56:18: error: expected primary-expression before ‘==’ token

if(buttonState == LOW){

              ^

exit status 1
expected primary-expression before ‘=’ token

I tried google to find for solution but I cant solve them

Code snippets don’t help, especially with issues about variable scope. You need to post your full sketch.

Pete.

#define BLYNK_PRINT Serial
#define buttonpin 8
#define ledpin 10
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define buttonState
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = " eCSiYtVdVgVC1V6sifdJxpwcPMG5kT9Z";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MBEVA";
char pass[] = "mashimbye";

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  
  timer.setInterval(1000L, myTimerEvent);

//If button is pressed switch on button V1
pinMode(buttonpin,INPUT);
digitalWrite(buttonpin,HIGH);
pinMode(ledpin,OUTPUT);
digitalWrite(buttonpin,LOW);

//OWN looP
{
 buttonState() = digitalRead(buttonPin);
  if(buttonState() == LOW){
    digitalWrite(buttonpin,HIGH);
    digitalWrite(ledpin,HIGH);
  }
  else{
    digitalWrite(buttonpin,LOW);
    digitalWrite(ledpin,LOW);
    }
  }
}

void loop(){
  
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Okay, two things happening here.
You have some code that you’ve called “Own Loop” which it appears that you want to use as a function that can be called, that block of code is within the void setup, and you haven’t given the function a name.

Secondly, variable names are case sensitive…

Pete.

Thanks

I managed to upload the sketch to the ESP , now the problem i have is that the ESP connects and disconnects now and then(every 2 seconds.)

#define BLYNK_PRINT Serial
#define buttonPin 8
#define ledPin 10
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define buttonState

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = " eCSiYtVdVgVC1V6sifdJxpwcPMG5kT9Z";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MBEVA";
char pass[] = "mashimbye";

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  
  timer.setInterval(1000L, myTimerEvent);

//If button is pressed switch on button V1
pinMode(buttonPin,INPUT);
digitalWrite(buttonPin,HIGH);
pinMode(ledPin,OUTPUT);
digitalWrite(buttonPin,LOW);
{
 //digitalRead(buttonPin);
 //buttonState = digitalRead(buttonPin);
 
 if(digitalRead(buttonPin == LOW ))
 // if(buttonState == LOW)
 {
    digitalWrite(buttonPin,HIGH);
    digitalWrite(ledPin,HIGH);
  }
  else{
    digitalWrite(buttonPin,LOW);
    digitalWrite(ledPin,LOW);
    }
  }
}

void loop(){
  
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
  

 


}
``

Are you actually getting a connection to Blynk? What does your serial monitor say? Does the app show the device as being online?
Are you aware that your auth code has a leading space?

I’m not sure what you’re expecting this code to do, other than display the uptime in seconds. Are you aware that the code in void setup executes once only?

Pete.

It does connect to blynk/cloud and my cellphone wifi, everything is shown in the serial monitor. I can also see it being online and offline in the app. I fixed the leading space.
I’m trying to use my pins in esp to take in inputs from hardware for example when I switch on a button it must show in the blynk app as online/ON. I had the code under my void loop but I thought it was the one slowing down my code(hence connecting and disconnecting) so I moved it to void set up, plus I read somewhere that I must keep my void loop clean when dealing with blynk.I will take it back to void loop since you said the void setup is only executed once.

It’s not connected to the Blynk cloud servers. It says Connecting… then Login timeout.

Are you using your cellphone’s hotspot as an internet connection? If so then that’s probably the cause of your problem. Some mobile providers block the Blynk protocol via a hotspot.

Pete.

1 Like

I;ve been using the same phone and same network and it never gave me any problems like this. I tried to use a different network provider and a router but same error.