WiFi not declared in this scope, couldn't get wifi to work in particle dev

Hi there,

im using the Particel Dev IDE (not the Web version) and trying to compile my code, but i get following error:

WiFi was not declared in this scope

but the spark_wiring_wifi.h is included. I also included the application.h in another file. Thanks for the help.

Here is the code part that where i get the error, in my socket.cpp file:


    /*
 */
#include "socket.h"
#include "spark_wiring_usbserial.h"
#include "spark_wiring_wifi.h"
#include "Header.h"
#include "MessageDecoder.h"

// An UDP instance to let us send and receive packets over UDP
UDP Udp;

// UDP Port used for two way communication
unsigned int port = 11337;

//mac address of the core
byte mac[6];

//receive buffer
#define MAX_SIZE 1024
char buffer[MAX_SIZE];

//ip for broadcast messages
IPAddress broadcastIp;

void initUdpSocket() {
    //get mac of core
    WiFi.macAddress(mac);

    //start udp server
    Udp.begin(port);
}

byte* getMacAddress() {
    return mac;
}

void setNewBroadcastIpFromWifi() {
    IPAddress myAddr = WiFi.localIP();

    byte first_octet = myAddr[0];
    byte second_octet = myAddr[1];
    byte third_octet = myAddr[2];
    byte fourth_octet = 255;

    broadcastIp = IPAddress(first_octet, second_octet, third_octet, fourth_octet);
    Serial.print("Broadcast address: ");
    Serial.println(broadcastIp);
}

int sendBroadcastMsg(unsigned char *b, int sizeInBytes) {
    //set broadcast address, zz jedesmal neu geholt. kostet glaub 10ms oder so,
    //aber sonst beim startup n race problem
    setNewBroadcastIpFromWifi();

    //send
    Udp.beginPacket(broadcastIp, port);
    Udp.write(b, sizeInBytes);
    Udp.endPacket();
}

void sendUDPMessage(unsigned char *b, int sizeInBytes) {
    setNewBroadcastIpFromWifi();
    Udp.beginPacket(broadcastIp, port);
    Udp.write(b, sizeInBytes);
    Udp.endPacket();
}

/**
 * Return 1 if package was available, otherwise 0
 */
int readUpdPackage() {
    int rcvd = Udp.parsePacket();
    if (rcvd > 0) {
        Serial.print("Received UPD packet, length: ");
        Serial.println(rcvd);
        // Read data
        Udp.read(buffer, rcvd);

        //decode
        decodeIncomingUdpPackage((unsigned char*)buffer, rcvd);

        //more bytes received
        if (rcvd > MAX_SIZE) {
            Serial.println("Too large packet");
            while (Udp.available())
                Udp.read();
        }

        Serial.println("Received UPD packet read successful");
        return 1;
    }
    return 0;
}

void flushUdpSocket() {
    Udp.flush();
}

You should #include "application.h" in every module you are using (either in the .cpp or an .h file that’s included therein).

uhh thanks, that did the trick…removed the

#include "spark_wiring_usbserial.h"
#include "spark_wiring_wifi.h"

and included

#include "application.h"

and it worked^^

thank you:) but why do have to use one global include everywhere in my code?

@Silence66, it is exactly like Arduino.h is included in arduino-compatible files.

ok thanks…didn’t know and it was my old code that worked in old spark times;)

@Silence66, even in “old spark times” we used “application.h”. However, now with the HAL abstraction layer, it makes it more important to use.

yap definitly noticed;)

1 Like