'connectWiFi' was not declared in this scope | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

1   +   2   =  

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
'connectWiFi' was not declared in this scope
No permission to create posts
April 20, 2020
9:50 pm
Avatar
plutonium
New Member
Members
Forum Posts: 1
Member Since:
April 20, 2020
sp_UserOfflineSmall Offline

I am a noob, and I am not sure if this was already answered however when I try to compile the script below I always end up with the above error and I have no idea why.
Any help is appreciated
This is an original script found on the thingspeak website.
i have other Arduino's running w/DHT22(AM2302) sensors and they post just fine to Thingspeak

#include ;

// Network information.
#define WIFI_NAME "xxxxxxxx"
#define PASSWORD "=xxxxxx"

// Hardware information.
#define SENSOR_POWER 13 // Connect the power for the soil sensor here.
#define SOIL_PIN A0 // Connect the sensor output pin here.
#define TIMEOUT 5000 // Timeout for server response.
#define SLEEP_TIME_SECONDS 1800

// ThingSpeak information.
#define NUM_FIELDS 2 // To update more fields, increase this number and add a field label below.
#define SOIL_MOISTURE_FIELD 1 // ThingSpeak field for soil moisture measurement.
#define ELAPSED_TIME_FIELD 2 // ThingSpeak field for elapsed time from startup.
#define THING_SPEAK_ADDRESS "api.thingspeak.com"
String writeAPIKey="xxxxxxxxxxx"; // Change this to the write API key for your channel.

// Global variables.
int numMeasure = 5; // Number of measurements to average.
int ADCValue = 0; // Moisture sensor reading.

WiFiClient client;

// Put your setup code here, to run once:
void setup()
{
Serial.begin( 115200 ); // You may need to adjust the speed depending on your hardware.
connectWiFi();
pinMode( SENSOR_POWER , OUTPUT );
digitalWrite( SENSOR_POWER , LOW ); // Set to LOW so no power is flowing through the sensor.
}

// Put your main code here, to run repeatedly:
void loop()
{
// Write to successive fields in your channel by filling fieldData with up to 8 values.
String fieldData[ NUM_FIELDS ];

// You can write to multiple fields by storing data in the fieldData[] array, and changing numFields.
// Write the moisture data to field 1.
fieldData[ SOIL_MOISTURE_FIELD ] = String( readSoil( numMeasure ) );
Serial.print( "Soil Moisture = " );
Serial.println( fieldData[ SOIL_MOISTURE_FIELD ] );

// Write the elapsed time from startup to Field 2.
fieldData[ ELAPSED_TIME_FIELD ] = String( millis() );

HTTPPost( NUM_FIELDS , fieldData );

delay( 1000 );
Serial.print( "Goodnight for "+String( SLEEP_TIME_SECONDS ) + " Seconds" );
ESP.deepSleep( SLEEP_TIME_SECONDS * 1000000 );
// If you disable sleep mode, add delay so you don't post to ThingSpeak too often.
// delay( 20000 );
}

// This function reads the soil moisture sensor numAve times and returns the average.
long readSoil(int numAve)
{
long ADCValue = 0;

for ( int i = 0; i < numAve; i++ ) {
digitalWrite( SENSOR_POWER, HIGH ); // Turn power to device on.
delay(10); // Wait 10 milliseconds for sensor to settle.
ADCValue += analogRead( SOIL_PIN ); // Read the value from sensor.
digitalWrite( SENSOR_POWER, LOW ); // Turn power to device off.
}

ADCValue = ADCValue / numAve;
return ADCValue; // Return the moisture value.
}

// This function builds the data string for posting to ThingSpeak
// and provides the correct format for the wifi client to communicate with ThingSpeak.
// It posts numFields worth of data entries, and takes the
// data from the fieldData parameter passed to it.

int HTTPPost( int numFields , String fieldData[] ){

if (client.connect( THING_SPEAK_ADDRESS , 80 )){

// Build the postData string.
// If you have multiple fields, make sure the sting does not exceed 1440 characters.
String postData= "api_key=" + writeAPIKey ;
for ( int fieldNumber = 1; fieldNumber < numFields+1; fieldNumber++ ){
String fieldName = "field" + String( fieldNumber );
postData += "&" + fieldName + "=" + fieldData[ fieldNumber ];

}

// POST data via HTTP.
Serial.println( "Connecting to ThingSpeak for update..." );
Serial.println();

client.println( "POST /update HTTP/1.1" );
client.println( "Host: api.thingspeak.com" );
client.println( "Connection: close" );
client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println( "Content-Length: " + String( postData.length() ) );
client.println();
client.println( postData );

Serial.println( postData );

String answer=getResponse();
Serial.println( answer );
}
else
{
Serial.println ( "Connection Failed" );
}

}

// Wait for a response from the server indicating availability,
// and then collect the response and build it into a string.

String getResponse(){
String response;
long startTime = millis();

delay( 200 );
while ( client.available() < 1 && (( millis() - startTime ) 0 ){ // Get response from server.
char charIn;
do {
charIn = client.read(); // Read a char from the buffer.
response += charIn; // Append the char to the string response.
} while ( client.available() > 0 );
}
client.stop();

return response;
}

April 22, 2020
9:50 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

It means you have an extra open or close brace somewhere. The compiler is confused about what is a separate function. I'd use an online code formatter to do the proper indenting on your code and then you should be able to find the missing open or close brace on a function block. Some editors will also highlight the matching brace when you hover on it.

FYI, MATLAB answers is the preferred location for ThingSpeak Community support.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

briskpanda, Dejw0089, Yassine Ben Salah, anis, 43994554AKS, suda

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457