BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Help for a newbie 77


#1

I have searched for similar topics and can’t find the answer I need.
I have built a distance sensor using wemos D1 mini

I had a guy write the code for Blynk and when I try to upload thru Arduino I get
Blynk.begin line highlighted with the error message- pass not declared in this scope-

Below is the code, I don’t write code and I would appreciate any help I could get.


#define BLYNK_PRINT Serial
#define CALIBRATION 0.968656756
//pins for the distance sensor  HSSR04
#define trigPin D5
#define echoPin D6

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

BlynkTimer timer;
//////////////////////////////////////////////////////auth code sent to your mail 
char auth[] = "6aa3eed2506d4a158f3aae3dxxxxxx";
///////////////////////////////////////////////////
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid [] = "NETWORK77";
char password [] = "82FCB97xxx";
                    
//////////////////////////////////////////////////////////

void setup()
{
  // Debug console
  Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // running timer every second
}



////_____________________________
void myTimerEvent()
{
Blynk.virtualWrite(V1,distanceReading() );
}


long distanceReading(){
  float duration, distance; //our beloved variables
 digitalWrite(trigPin, LOW);  //PULSE ___|---|___ 
 delayMicroseconds(2);  
 digitalWrite(trigPin, HIGH); 
 delayMicroseconds(10);  
 digitalWrite(trigPin, LOW); 
 duration = pulseIn(echoPin, HIGH);
 distance = ((duration*0.0168422+0.221)*0.393701)*CALIBRATION;//returns inches 1cm =*0.393701 inches
 //Serial.print("distance(inch): ");Serial.println(distance);
 return distance;
}


#2

You could ask the guy that DID write the code :stuck_out_tongue_winking_eye:

But you are using the variable password in the declare but referencing just pass in the command.

That and now we all know your WiFi and Auth codes :stuck_out_tongue:

The WiFi is no big deal unless you are my neighbor… but others can mess around with your hardware until you change you AUTH code. (refresh in the App and replace in the sketch).

I have also never tried to run a Blynk.virtualWrite() that way… directly calling a function. I know functions can return final results of a process, but I though it is coded differently? Something for me to Google :smiley:

Anyhow, not how I would have done such a simple process… more like this…


#3

Thank you Gunner for your reply. Like I said, new and learning and I can’t make contact with the guy to ask. So can I copy and paste what you wrote?
Also, how do I fix the variable password in the declare issue?


#4

Understandable, but there are sites that teach in-depth programming… but not here :stuck_out_tongue: We mainly try to help people learn about using Blynk, although we may we toss out a coding snippet or so :wink:

Sure… but if you don’t understand the differences you might end up with yet another compiling error.

Change one or the other to match. Eg. use pass or password in both places, otherwise they are actually considered two totally separate variables.

BTW, I also have an Ultrasonic example sketch here that adds in a servo response…


#5

Ok, thank you.
I tried your, timer.setInterval(1000L, distanceReading()); // Call the scanning function directly, and got an error saying -distance reading was not declared in this scope-
When I put the original one back in I got an error - My timer event not declared in this scope-.
Do you have any ideas on these?


#6

It’s exactly as @Gunner predicted…

You really need to understand at least the basics of C++ programming if you’re going to make any progress with this, or get someone else to modify the code for you.
The time you invest in learning will be useful in the long run.

Pete.