esp_distance:51: error: 'Serial' does not name a type
esp_distance:55: error: 'cmd' does not name a type
esp_distance:56: error: 'cmd' does not name a type
esp_distance:57: error: 'ser' does not name a type
esp_distance:59: error: expected unqualified-id before 'if'
esp_distance:66: error: 'getStr' does not name a type
esp_distance:67: error: 'getStr' does not name a type
esp_distance:68: error: 'getStr' does not name a type
esp_distance:69: error: 'getStr' does not name a type
esp_distance:72: error: 'cmd' does not name a type
esp_distance:73: error: 'cmd' does not name a type
esp_distance:74: error: 'ser' does not name a type
esp_distance:76: error: expected unqualified-id before 'if'
esp_distance:79: error: expected unqualified-id before 'else'
esp_distance:86: error: expected constructor, destructor, or type conversion before '(' token
esp_distance:87: error: expected declaration before '}' token
'Serial' does not name a type
CrossRoads:
What folder do you have these libraries in?
I really have no idea about libraries on programming.I just include them at the beginning of codes. I've to say that I just copied this code from somewhere on web and a little change it to use according to my desires to establish my project.If I don't change anything and directly upload to sketch then there is no compiling error and runs fine.
Where should exactly look for the find out what folder do have these libraries in?
If you want to take a look here is the original code
// esp8266_test.ino
//
// Plot LM35 data on thingspeak.com using an Arduino and an ESP8266 WiFi
// module.
//
// Author: Mahesh Venkitachalam
// Website: electronut.in
#include <SoftwareSerial.h>
#include <stdlib.h>
// LED
int ledPin = 13;
// LM35 analog input
int lm35Pin = 0;
// replace with your channel's thingspeak API key
String apiKey = "2TNSKZAUY0FUD7QY";
// connect 10 to TX of Serial USB
// connect 11 to RX of serial USB
SoftwareSerial ser(2,3); // RX, TX
// this runs once
void setup() {
// initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
// enable debug serial
Serial.begin(9600);
// enable software serial
ser.begin(9600);
// reset ESP8266
ser.println("AT+RST");
}
// the loop
void loop() {
// blink LED on board
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
// read the value from LM35.
// read 10 values for averaging.
int val = 0;
for(int i = 0; i < 10; i++) {
val += analogRead(lm35Pin);
delay(500);
}
// convert to temp:
// temp value is in 0-1023 range
// LM35 outputs 10mV/degree C. ie, 1 Volt => 100 degrees C
// So Temp = (avg_val/1023)*5 Volts * 100 degrees/Volt
float temp = val*50.0f/1023.0f;
// convert to string
char buf[16];
String strTemp = dtostrf(temp, 4, 1, buf);
Serial.println(strTemp);
// TCP connection
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
ser.println(cmd);
if(ser.find("Error")){
Serial.println("AT+CIPSTART error");
return;
}
// prepare GET string
String getStr = "GET /update?api_key=";
getStr += apiKey;
getStr +="&field1=";
getStr += String(strTemp);
getStr += "\r\n\r\n";
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
ser.println(cmd);
if(ser.find(">")){
ser.print(getStr);
}
else{
ser.println("AT+CIPCLOSE");
// alert user
Serial.println("AT+CIPCLOSE");
}
// thingspeak needs 15 sec delay between updates
delay(16000);
}
What board are you trying to compile the program for?
It's Arduino UNO.
I'm using Arduino 2,3 pins to serial communication with ESP8266-01. I can send AT commands manually from serial monitor. You may want to look this post or just this video
Now I've to write down codes for other 3 sensors. And maybe I should reduce the delay times between each measure.I guess hcsr04,esp and thingspeak can handle it.
Do you understand what I meant by it being "in no-mans-land" ?
At first, I just thought you are making fun with me because, I'm taking someone's code and trying to fit in mine desires with basic programming knowledge.
However, now I can somehow understand what you meant a little. I was defining or calling a variable that it is in reality not exist right there! or something similar. Anyway I appreciate your help.
No, I was not trying to make fun of you, though I was trying for a little humour. The effect of your stray bracket was to maroon some of the code outside of any function - hence my use of the term "no man's land"