Created Sun, 07 Jun 2015 13:41:20 +0000 by Robbedoes
Sun, 07 Jun 2015 13:41:20 +0000
Hi, For a (solar) garden sprinkler system with multiple APs within range (where the passphrase is all the same) I am trying to realise that at startup, the WiFiScan routine is first performed, and thereafter the AP with the best signal strenght found is connected to. The WIFiScan exemple works fine and returnes the best AP, but how to replace the const char * szSsid = "SCWiFi7" with name of the best station found, to connect to? (since this is a const and I could not change that to a char since the library doesn't accept that?
const char * szSsid = "SCWiFi7"; // this must be replaced with the outcome of the WiFiScan routine called GetszSsid(); const char * szPassPhrase = "wachtwoord"; #define WiFiConnectMacro() deIPcK.wfConnect(szSsid, szPassPhrase, &status)
I have enclosed my entire code which includes tons of irrelevant stuff (sorry, newbie) and hope someone can help me get thru this showstopper.
Thanks,
Rob
#include <SHT1x.h>
#include <string.h>
#include <Wire.h>
#include <MRF24G.h>
#include <DEIPcK.h>
#include <DEWFcK.h>
#include <SD.h>
#include <WProgram.h>
#include <Arduino.h>
#include <OneWire.h>
#include <stdio.h>
#include <RTCC.h>
#define MRFVERSION
int UserLed1 = 13; // WF on board
int UserLed2 = 43;
int UserLed3 = 48;
int UserLed4 = 47;
int RedLed = 6; // RGB led
int GreenLed = 8;
int BlueLed = 7;
int GPSResetPin = 5;
int LDR_Pin = A8; //analog pin 8 voor LDR
int LDRReading = 0;
int cbRead = 0;
int count = 0;
int i = 1;
int mode = 1; // 1 = debug local echo ON , 0 = Serial GPS disabled, all to network, 2 = live, eliminate all overhead
byte rgbRead[1024];// a buffer
String UDPMessage; // te zenden naar Client
String inString; // ontvangen van Client
String redString;
String greenString;
String blueString;
String clearString;
char Comma = ',';
String CheckSumString;
String EData = "";
String GPSDataString;
String SoilTempString;
//RTCC
String NTPTimeString;
// A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
char months[26] = { 4, 0, 0, 12, 0, 2, 0, 0, 0, 1, 0, 0, 3, 11, 10, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0 };
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 9 // SHT15
#define clockPin 10
SHT1x sht1x(dataPin, clockPin);
char CelsiusString[5];
char HumidityString[6];
#define ONE_WIRE_BUS 2 // DS18S20
// DS18S20 Temperature chip i/o
OneWire ds(12); // on pin 12
char EnvironmentBuf;
String GPSString;
char inChar;
float temp_c;
float temp_f;
float humidity;
char * test;// celsius from DS18S20
// Internet assigned Static IP for this device
IPv4 ipServer = { 192, 168, 1, 194 }; // for this station
unsigned short portServer = 44400;
const char * szSsid = "SCWiFi7";
const char * szPassPhrase = "1a2b3c4d5e";
#define WiFiConnectMacro() deIPcK.wfConnect(szSsid, szPassPhrase, &status)
typedef enum
{
NONE = 0,
CONNECT,
LISTEN,
ISLISTENING,
AVAILABLECLIENT,
ACCEPTCLIENT,
READ,
WRITE,
CLOSE,
EXIT,
DONE
} STATE;
STATE state = CONNECT;
unsigned tStart = 0;
unsigned tWait = 3000; // wait before disconnecting client
// give the UDP client a datagram cache
#define cUDPSockets 3
static UDPSocket rgUDPClient[cUDPSockets];
static UDPSocket * pUdpSocket = NULL;
static UDPServer udpServer;
IPSTATUS status;
FILE EDataFile; // SD card
FILE SDataFile;
//================
String IPAdress;
String ALARM_TYPE = ("");
String ID_HOSTNAME = ("");
String ID_ETHERNET = ("");
String SEN_PIR = ("");
String SEN_ILR = ("");
String SEN_ILL = ("");
String TMS = ("");
String FINGERPRINT_EVENT = ("");
String FPR_ENO = ("");
String GPSDateTimeString;
String GPSHhMmSs;
//String GPSString;
String CFSendString;
String GPSTimeString;
String Result;
String InString;
String Datastring;
String WatchStateString;
String DigCommNumberString;
char Letter[8];
char thisChar;
int C; // choice for Case
int ActualHours;
int ActualTenHours;
int ActualMinutes;
int ActualTenMinutes;
int ActualSeconds;
int ActualTenSeconds;
int ActualMillis;
int TimeZoneOffset = 0; // UTC +1 in Winter +2 in Zomer (NL)
char Dem;
int Temp;
String PREF_SSID;
float celsius;
float fahrenheit;
String TimeString;
char * SoilTempString2[20];
bool GPS = 0; // aangeslotem dient dit 1 te zijn
char * F_szSsid;
//=======================
void setup()
{
Serial.begin(115200); // Open serial connection to report values to host
delay(4000); //for RTCC to initialise NTP
RTCCInitialise();
Serial.println("WeatherWizard 0.1");
Serial.println("");
pinMode(UserLed1, OUTPUT);
pinMode(UserLed2, OUTPUT); // leds on WF32 board to be disabled for Final version with Sleep
pinMode(UserLed3, OUTPUT);
pinMode(UserLed4, OUTPUT);
pinMode(RedLed, OUTPUT);
pinMode(GreenLed, OUTPUT);
pinMode(BlueLed, OUTPUT);
pinMode(GPSResetPin, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(UserLed1, HIGH); // show Power is ON
LedRed();
delay(1000);
LedGreen();
delay(1000);
LedBlue();
delay(1000);
Serial1.begin(9600);
delay(200);
inputString.reserve(200);
if (GPS)
{
GPSInitialise(); // 10Hz 115K uitgeschakeld voor WeatherWizard, update 1 Hz voldoende
Serial.println("GPS Initialised");
}
// Data wire is plugged into port 2 on the Arduino, MAY CONFLICT with RTCC interrupt for alarm or chime
String PREF_SSID;
//char * szSsid;
const char * szSsid = GetszSsid();
}
void loop()
{
StateLed();
//LocalMonitor(1); // if Serial1 GPS is echoed to local monitor or to UDP Client (if connected)
switch (state)
{
case CONNECT:
if (WiFiConnectMacro())
{
Serial.println("Connection Created");
Serial.println(szSsid);
deIPcK.begin(ipServer);
state = LISTEN;
}
else if (IsIPStatusAnError(status))
{
Serial.print("Unable to make connection, status: ");
Serial.println(status, DEC);
state = CLOSE;
}
break;
// say to listen on the port
case LISTEN:
if (deIPcK.udpStartListening(portServer, udpServer, &status))
{
// add our sockets
for (i = 0; i < cUDPSockets; i++)
{
udpServer.addSocket(rgUDPClient[i]);
}
Serial.println("Started Listening");
state = ISLISTENING;
}
else if (IsIPStatusAnError(status))
{
Serial.print("Listening Error: 0x");
Serial.println(status, HEX);
state = EXIT;
LedRed();
}
break;
case ISLISTENING:
if ((i = udpServer.isListening(&status)) > 0)
{
Serial.print(i, DEC);
Serial.print(" Sockets listening on port: ");
Serial.print(portServer, DEC);
Serial.println("");
state = AVAILABLECLIENT;
}
else if (IsIPStatusAnError(status))
{
Serial.print("Lost IP connectivity, error: 0x");
Serial.println(status, HEX);
LedRed();
state = EXIT;
}
break;
// wait for a connection
case AVAILABLECLIENT:
if ((count = udpServer.availableClients()) > 0)
{
Serial.print("Got ");
Serial.print(count, DEC);
Serial.println(" clients pending");
state = ACCEPTCLIENT;
}
break;
// accept the connection
case ACCEPTCLIENT:
// accept the client
if ((pUdpSocket = udpServer.acceptClient()) != NULL)
{
Serial.println("Got a SprinklerWizard Connection");
state = READ;
tStart = (unsigned)millis();
}
// this probably won't happen unless the connection is dropped
// if it is, just release our socket and go back to listening
else
{
state = CLOSE;
}
break;
case READ:
// see if we got anything to read
if ((cbRead = pUdpSocket->available()) > 0)
{
cbRead = cbRead < sizeof(rgbRead) ? cbRead : sizeof(rgbRead);
cbRead = pUdpSocket->readDatagram(rgbRead, cbRead);
Serial.print("Got ");
Serial.print(cbRead, DEC);
Serial.println(" bytes");
for (int i = 0; i < cbRead; i++)
{
inString = inString + rgbRead[i], BYTE;
}
Serial.print("Received <");
Serial.print(inString);
Serial.println(">");
inString = "";
state = WRITE;
}
// If too much time elapsed between reads, close the connection
else if ((((unsigned)millis()) - tStart) > tWait)
{
state = CLOSE;
LedRed();
}
break;
case WRITE:
// this routine echos EDATA$ back to clients if they send an(y) UDP-message from the system provided a client has logged in
makeEData();
Serial.println(UDPMessage);
// UDPMessage naar verzendbuffer
i = 0;
while (i <= UDPMessage.length()){
cbRead = i;
rgbRead[i] = UDPMessage.charAt(i);
i++;
}
pUdpSocket->writeDatagram(rgbRead, cbRead);
LedRed();
state = READ;
tStart = (unsigned)millis();
break;
// close our udpClient and go back to listening
case CLOSE:
if (pUdpSocket != NULL)
{
pUdpSocket->close();
udpServer.addSocket(*pUdpSocket);
}
Serial.print("Closing UdpClient after timeout of ");
Serial.print(tStart/1000);
Serial.println(" seconds ");
state = ISLISTENING;
break;
// something bad happen, just exit out of the program
case EXIT:
udpServer.close();
for (i = 0; i < cUDPSockets; i++)
{
rgUDPClient[i].close();
}
Serial.println("Something went wrong, trying to re-connect");
state = DONE;
LedRed();
break;
// do nothing in the loop
case DONE:
default:
break;
}
// every pass through loop(), keep the stack alive
DEIPcK::periodicTasks();
}
void LocalMonitor(int mode)
{
if (mode == 1) // show all incoming data
{
Serial.println("Mode");
if (Serial1.available())
{
int inByte = Serial1.read();
//Serial.write(inByte);
GPSString = GPSString + String(inByte, DEC);
if (inByte == '$')
{
// dan is er net een hele regel binnengekomen die in GPSString staat
Serial.println(GPSString);
GPSString = ("");
}
}
}
if ((mode == 2) && (state == 6)) // client connected, send GPS?
{
if (Serial1.available()) {
cbRead = Serial1.available();
Serial1.readBytes(rgbRead, cbRead);
pUdpSocket->writeDatagram(rgbRead, cbRead);
}
}
}
void GetLDR(){
// LDR
LDRReading = analogRead(LDR_Pin);
//Serial.println("LDR Routine");
}
void GetEnvironment()
{
// Read values from the temp & humidity sensor SHT15
temp_c = sht1x.readTemperatureC();
// temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();
delay(1000);
}
String GPSInitialise()
{
Serial1.begin(9600); // gps module defaults to 1 Hz and 9600 Bd at powercycle, must be speeded up
digitalWrite(GPSResetPin, HIGH); //reset GPS
delay(1000);
digitalWrite(GPSResetPin, LOW);
delay(200);
digitalWrite(GPSResetPin, HIGH);
//Serial1.println("$PMTK104*37"); // Cold start
Serial.println("GPS Module Factory Restart... wait....");
delay(1000);
//Serial1.println("$PMTK251,115200*1F");// to 115kBd now
//delay(500);
//Serial1.end();
//delay(1000);
//Serial1.begin(9600);
//delay(1000);
//Serial.println("GPS module on UART1 configured for 115200 Bd and 10 Hz updates");
//Serial1.println("$PMTK220,100*2F");
digitalWrite(UserLed2, HIGH);
}
void makeEData() // string om desgevraagd uit te sturen
{
GetEnvironment();
dtostrf(temp_c, 6, 2, CelsiusString); // omzetten
dtostrf(humidity, 10, 2, HumidityString);
GetLDR();
GetGPS();
GetSoilTemp();
EData = "$EDATA";
EData = EData += Comma;
if (GPS)
{
EData = EData += GPSDataString.substring(7, sizeof(GPSDataString)); // alleen als GPS aangesloten is
}
else
{
EData = EData += NTPTimeString;// van RTCC
}
EData = EData += Comma;
EData = EData += String(CelsiusString); // SHT15
EData = EData += Comma;
EData = EData += String(HumidityString);
EData = EData += Comma;
EData = EData += String(LDRReading);
EData = EData += Comma;
EData = EData += SoilTempString; // DS18S20
EData = EData += "*";
EData = EData += (String(makeCheckSum(EData), HEX));
UDPMessage = EData;
}
int makeCheckSum(String EData)
{
char EnvironmentBuf[sizeof EData];
EData.toCharArray(EnvironmentBuf, sizeof EData);
int i;
int XOR;
int c;
// Bereken checksum zonder $'s in the string
for (XOR = 0, i = 0; i < strlen(EnvironmentBuf); i++) {
c = (unsigned char)EnvironmentBuf[i];
if (c == '*') break;
if (c != '$') XOR ^= c;
}
return XOR;
}
/* Voor toekomst https://timzaman.wordpress.com/code-c-arduino/checksum-xor-cpp/
Validates the checksum on an (for instance NMEA) string
// Returns 1 on valid checksum, 0 otherwise
int validateChecksum(void) {
char gotSum[2];
gotSum[0] = buffer[strlen(buffer) - 2];
gotSum[1] = buffer[strlen(buffer) - 1];
// Check that the checksums match up
if ((16 * atoh(gotSum[0])) + atoh(gotSum[1]) == getCheckSum(buffer)) return 1;
else return 0;
}
*/
void GetRMC() // obtain (wait) for a completed GPS-RMC string to get date & time
{
do
{
if (Serial1.available()); // zolang het duurt om een complete string binnen te krijgen
{
inChar = Serial1.read();
GPSString += inChar;
}
} while ((int(inChar) != 13) || inChar == '$'); // carriage return of begin string
Serial.print("> ");
Serial.println(GPSString);
if (GPSString.substring(1, 7) == "$GPRMC")
{
//GetTimeInt();//get the time in hh:mm:ss from GPRMC string
Serial.println(GPSString);
GPSString = ("");
GPSTimeString = ("");
}
}
void GetGPS()
{
while (Serial1.available()) {
char inChar = (char)Serial1.read();
GPSString += inChar;
if (inChar == '\n')
{
if (GPSString.substring(0, 6) == "$GPRMC")
{
GPSDataString = GPSString;
//Serial.print(GPSString);
//GetTimeIntegers();
}
GPSString = "";
}
}
}
void GetSoilTemp()
{
handleOWIO(12, i); // pin 12 = data
}
void handleOWIO(byte pin, byte resolution) {
int owpin = pin;
// Device identifier
byte dsaddr[8];
OneWire myds(owpin);
getfirstdsadd(myds, dsaddr);
Serial.println(getdstemp(myds, dsaddr, resolution)); //om temp uit te printen
}
void getfirstdsadd(OneWire myds, byte firstadd[]){
byte i;
byte present = 0;
byte addr[8];
float celsius, fahrenheit;
int length = 8;
//Serial.print("Looking for 1-Wire devices...\n\r");
while (myds.search(addr)) {
//Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
for (i = 0; i < 8; i++) {
firstadd[i] = addr[i];
// Serial.print("0x");
if (addr[i] < 16) {
// Serial.print('0');
}
// Serial.print(addr[i], HEX);
if (i < 7) {
//Serial.print(", ");
}
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
// the first ROM byte indicates which chip
//Serial.print("\n\raddress:");
// Serial.print(addr[0]);
return;
}
}
float getdstemp(OneWire myds, byte addr[8], byte resolution) {
byte present = 0;
int i;
byte data[12];
byte type_s;
float celsius;
float fahrenheit;
switch (addr[0]) {
case 0x10:
//Serial.println(F(" Chip = DS18S20")); // or old DS1820
type_s = 1;
break;
case 0x28:
//Serial.println(F(" Chip = DS18B20"));
type_s = 0;
break;
case 0x22:
//Serial.println(F(" Chip = DS1822"));
type_s = 0;
break;
default:
Serial.println(F("(Un)connected device is not a DS18x20 family device."));
}
// Get byte for desired resolution
byte resbyte = 0x1F;
if (resolution == 12){
resbyte = 0x7F;
}
else if (resolution == 11) {
resbyte = 0x5F;
}
else if (resolution == 10) {
resbyte = 0x3F;
}
// Set configuration
myds.reset();
myds.select(addr);
myds.write(0x4E); // Write scratchpad
myds.write(0); // TL
myds.write(0); // TH
myds.write(resbyte); // Configuration Register
myds.write(0x48); // Copy Scratchpad
myds.reset();
myds.select(addr);
long starttime = millis();
myds.write(0x44, 1); // start conversion, with parasite power on at the end
while (!myds.read()) {
// do nothing
}
//Serial.print("Conversion took: ");
//Serial.print(millis() - starttime);
//Serial.println(" ms");
//delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = myds.reset();
myds.select(addr);
myds.write(0xBE); // Read Scratchpad
//Serial.print(" Data = ");
//Serial.print(present,HEX);
//Serial.println("Raw Scratchpad Data: ");
for (i = 0; i < 9; i++) { // we need 9 bytes
data[i] = myds.read();
// Serial.print(data[i], HEX);
// Serial.print(" ");
}
//Serial.print(" CRC=");
//Serial.print(OneWire::crc8(data, 8), HEX);
// Serial.println();
// convert the data to actual temperature
unsigned int raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// count remain gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
// default is 12 bit resolution, 750 ms conversion time
}
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
SoilTempString = String(celsius);
return celsius;
}
void GetTimeIntegers()
{ //get hours, minutes, seconds from GPSString
int second;
// int ActualTenHours = atoi(GPSString.charAt(7)); // was 9, werkt voor $GPRMC,034652.008,V,,,,,0.00,0.00,250415,,,N*44
Serial.print("ActualTenHours = ");
Serial.println(ActualTenHours);
inChar = GPSString.charAt(10);
ActualHours = (ActualTenHours + int(inChar));
ActualHours = (ActualHours + TimeZoneOffset);
if (ActualHours == 24)
{
ActualHours = 0;
}
if (ActualHours == 25)
{
ActualHours = 1;
}
inChar = GPSString.charAt(11);
ActualTenMinutes = int(inChar) * 10;
inChar = GPSString.charAt(12);
ActualMinutes = ActualTenMinutes + int(inChar);
inChar = GPSString.charAt(13);
int ActualTenSeconds = int(inChar);
inChar = GPSString.charAt(14);
int ActualSeconds = ActualTenSeconds + int(inChar);
second = ActualSeconds;
if (ActualHours < 1)
{
GPSTimeString = ("0");
}
GPSTimeString = GPSTimeString + ActualHours;
GPSTimeString = (GPSTimeString + ":");
if (ActualMinutes < 10)
{
GPSTimeString = (GPSTimeString + "0");
}
GPSTimeString = GPSTimeString + ActualMinutes;
GPSTimeString = (GPSTimeString + ":");
if (ActualSeconds < 10)
{
GPSTimeString = (GPSTimeString + "0");
}
GPSTimeString = GPSTimeString + ActualSeconds;
}
void LedOFF()
{
digitalWrite(RedLed, LOW);
digitalWrite(GreenLed, LOW);
digitalWrite(BlueLed, LOW);
}
void LedRed()
{
LedOFF();
digitalWrite(RedLed, HIGH);
}
void LedGreen()
{
LedOFF();
digitalWrite(GreenLed, HIGH); // show Power is ON
}
void LedBlue()
{
LedOFF();
digitalWrite(BlueLed, HIGH); // show Power is ON
}
void StateLed()
{
if (state == 1)
{
LedRed();
}
if (state == 2)
{
LedRed();
}
if (state == 3)
{
LedRed();
}
if (state == 4)
{
LedBlue();
}
if (state == 5)
{
LedBlue();
}
if (state == 6)
{
LedRed();
}
if (state == 7)
{
LedRed();
}
if (state == 8)
{
LedRed();
}
if (state == 9)
{
LedRed();
}
if (state == 10)
{
LedRed();
}
}
/* NONE = 0,
1 CONNECT,
2 LISTEN,
3 ISLISTENING,
4 AVAILABLECLIENT,
5 ACCEPTCLIENT,
6 READ,
7 WRITE,
8 CLOSE,
9 EXIT,
10 DONE
*/
void RTCCInitialise()
{
Serial.println("Compiled " __DATE__ " " __TIME__ "\n");
// I n i t i a l i z e the RTCC module
RTCC.begin();
// Set the time to something s e n s i b l e
RTCCValue rv = RTCC.value();
char aaStr[9] = __TIME__;
unsigned char hours = (10 * (aaStr[0] - '0')) + aaStr[1] - '0';
unsigned char minutes = (10 * (aaStr[3] - '0')) + aaStr[4] - '0';
unsigned char seconds = (10 * (aaStr[6] - '0')) + aaStr[7] - '0';
rv.time(hours, minutes, seconds);
char bStr[12] = __DATE__;
unsigned char year = (10 * (bStr[9] - '0')) + bStr[10] - '0';
unsigned char month = months[bStr[0] - 'A'];
if (month == 4 && bStr[1] == 'u') {
month = 8;
}
if (month == 3 && bStr[2] != 'r') {
month = 5;
}
if (month == 1 && bStr[1] == 'u') {
if (bStr[2] == 'n') month = 6;
else month = 7;
}
if (bStr[4] == ' ') bStr[4] = '0';
unsigned char day = (10 * (bStr[4] - '0')) + bStr[5] - '0';
rv.date(year, month, day);
rv.setValidity(RTCC_VAL_GCC); // date/time approximated using compilation time: works for developers only!!!
RTCC.set(rv);
rv.seconds(0); // Align alarms to the minute
RTCC.alarmSet(rv);
// Set the alarm to t r i g g e r every second
RTCC.alarmMask(AL_10_SECOND);
RTCC.chimeEnable();
RTCC.alarmEnable();
// Attach our routine to send the time through the serial port
RTCC.attachInterrupt(&outputTime);
}
//RTCCValue lastChime = RTCCValue();
void outputTime()
{
// Remember last chime: most useful action of an interrupt routine like this one...
RTCCValue lastChime = RTCC.value();
char time[50];
// Format the time and print it .
sprintf(time, "%02d/%02d/%02d %02d:%02d:%02d\r",
lastChime.day(),
lastChime.month(),
lastChime.year(),
lastChime.hours(),
lastChime.minutes(),
lastChime.seconds()
);
Serial.println(time);
NTPTimeString = time;
}
char * GetszSsid() // funktie om szSsid samen te stellen
{
Serial.println("Scanning for preferred AP");
typedef enum WStates
{
NONE = 0,
WIFISCAN,
PRINTAPINFO,
ERROR,
STOP,
DONE
};
enum WStates WiFiSTATE = WIFISCAN;
IPSTATUS status = ipsSuccess;
int cNetworks = 0;
int iNetwork = 0;
String AP_SSID[20]; // //ruimte voor 20 APs
int AP_Strenght[20];
char Current_SSID[20];
int PREF_SSID_INDEX = 0;
int AP_Best_Power = 0;
Serial.println("Starting WiFi Scan");
cNetworks = 0;
///
do
{
switch (WiFiSTATE)
{
case WIFISCAN:
if (deIPcK.wfScan(&cNetworks, &status))
{
Serial.print("Scan Done, ");
Serial.print(cNetworks, DEC);
Serial.println(" Networks Found");
WiFiSTATE = PRINTAPINFO;
iNetwork = 0;
}
else if (IsIPStatusAnError(status))
{
Serial.println("Scan Failed");
Serial.println("");
WiFiSTATE = ERROR;
}
break;
case PRINTAPINFO:
if (iNetwork < cNetworks)
{
SCANINFO scanInfo;
int j = 0;
if (deIPcK.getScanInfo(iNetwork, &scanInfo))
{
for (j = 0; j<scanInfo.ssidLen; j++)
{
Current_SSID[j] = scanInfo.ssid[j];
}
String str(Current_SSID); // array naar string
AP_SSID[iNetwork] = (Current_SSID);
for (int i = 0; i < sizeof(Current_SSID); ++i){ // clear the array
Current_SSID[i] = (char)0;
}
for (j = 0; j<sizeof(scanInfo.bssid); j++)
{
if (scanInfo.bssid[j] < 16)
{
}
}
AP_Strenght[iNetwork] = (scanInfo.rssi);
for (j = 0; j< scanInfo.cBasicRates; j++)
{
uint32_t rate = (scanInfo.basicRateSet[j] & 0x7F) * 500;
}
}
else
{
}
iNetwork++;
}
else
{
WiFiSTATE = STOP;
}
break;
case ERROR:
WiFiSTATE = STOP;
break;
case STOP:
int j;
Serial.println("NETWORKS FOUND :");
for (j = 0; j < cNetworks; j++){
Serial.print(AP_SSID[j]);
Serial.print(" > ");
Serial.println(AP_Strenght[j]);
if (AP_Strenght[j]>AP_Best_Power)
{
AP_Best_Power = AP_Strenght[j];
PREF_SSID_INDEX = j;
}
}
PREF_SSID = (AP_SSID[PREF_SSID_INDEX]);
Serial.print("Preferred AP = ");
Serial.println(PREF_SSID);
WiFiSTATE = DONE;
break;
case DONE:
default:
break;
}
DEIPcK::periodicTasks();
} while (WiFiSTATE != DONE);
Serial.print("@ WiFiState > ");
Serial.println(PREF_SSID);
int PREF_SSID_LEN = (sizeof PREF_SSID);
Serial.print("Size of PREF_SSID> ");
Serial.println(PREF_SSID_LEN);
// PREF_SSID.getBytes(* szSsid,3,0);
for (i = 1; i >= PREF_SSID_LEN; i++)
{
Serial.println("Printing?");
Serial.println(PREF_SSID.charAt(i));
}
//PREF_SSID.toCharArray(szSsid, PREF_SSID_LEN);
PREF_SSID.toCharArray(F_szSsid,PREF_SSID.length(),0);
Serial.print("Returning szSsid > ");
Serial.println(String(F_szSsid));
return F_szSsid;
}
Sun, 07 Jun 2015 14:49:38 +0000
Any char * can be used as a const char *. The "const" just signifies to the compiler "The contents of this string mustn't be changed".
You can just cast the char * to a const char * and it should work fine.
deIPcK.wfConnect((const char *)F_szSsid, szPassPhrase, &status);
... for example.
Sun, 28 Jun 2015 06:31:39 +0000
Now works without problems!. Thanks! Rob