I have an Arduino Uno WiFi device, which is turned on all the time (day and night). The WiFi mode is set to 'STA'. But from time to time it switches to 'AP+STA' mode automatically, so the device is visible in the network as an Access Point, which is not what I want. Is there a way to prevent my Arduino Uno to switch the WiFi mode by itself? Can it be done via code maybe? Thank you for your help.
Here's the code that is working on it (and it's still working without any problems):
#include <Wire.h>
//#include <Ciao.h> // for older IDE
#include <UnoWiFiDevEd.h> // for newer IDE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
int sensorsValues[] = {9999,9999,9999};
int timerCount = 25;
static const uint8_t analogPins[] = {A0, A1, A2};
// for LEDs
int NUMPIXELS = 9;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, 2); // (numOfPixels, pinNo, options)
boolean hasChanged = false;
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
//start serial connection
Serial.begin(9600);
for(int i=0; i<3; i++){
pinMode(analogPins[i], INPUT_PULLUP);
}
strip.setBrightness(40);
strip.begin(); // Initialize the NeoPixel library.
strip.show(); // Initialize all pixels to 'off'
Ciao.begin();
}
void loop() {
for (int i = 0; i < 3; i++) {
int sensorVal = analogRead(analogPins[i]) >= 1000 ? 1 : 0;
if( sensorsValues[i] != sensorVal ) {
hasChanged = true;
if (sensorVal == 1) {
// green light
strip.setPixelColor( (i*3), 100, 255, 100);
strip.setPixelColor( (i*3)+1, 100, 255, 100);
strip.setPixelColor( (i*3)+2, 100, 255, 100);
strip.show();
} else {
// red light
strip.setPixelColor( (i*3), 255, 50, 50);
strip.setPixelColor( (i*3)+1, 255, 50, 50);
strip.setPixelColor( (i*3)+2, 255, 50, 50);
strip.show();
}
}
sensorsValues[i] = sensorVal;
}
timerCount += 1;
if( hasChanged == false && (timerCount % 30) == 0 ){
CiaoData data = Ciao.write("rest", "xxx.xxx.xxx.xxx", "/d/add/A001/active", "GET");
if (!data.isEmpty()){
String st = String(data.get(1));
String re = String(data.get(2));
}
}
if (hasChanged == true && (timerCount % 5) == 0 ) {
CiaoData data = Ciao.write("rest", "xxx.xxx.xxx.xxx", "/d/add/A001/a/" + String(sensorsValues[0]) + "," + String(sensorsValues[1]) + "," + String(sensorsValues[2]), "GET");
if (!data.isEmpty()){
String st = String(data.get(1));
String re = String(data.get(2));
}
hasChanged = false;
}
if (timerCount > 30) timerCount = 0;
delay(1000);
}
-
Are you running any code on it? If so is it possible for you to post the code.Code Gorilla– Code Gorilla2017年04月19日 11:25:33 +00:00Commented Apr 19, 2017 at 11:25
-
Yes, the code reads 3 analog sensors, send their values to server if any has changed and it controls LED strip. Seems like I can't post the code here..tomekc– tomekc2017年04月19日 11:28:24 +00:00Commented Apr 19, 2017 at 11:28
-
You can't do that :) You'll need to edit your post. Have you tried monitoring it with something like Blink running (a do nothing program). If it doesn't do it then its your code, if it does its something to do with the board.Code Gorilla– Code Gorilla2017年04月19日 11:30:08 +00:00Commented Apr 19, 2017 at 11:30
-
@CodeGorilla I just edited my question adding a code.tomekc– tomekc2017年04月19日 11:37:32 +00:00Commented Apr 19, 2017 at 11:37
-
1Well, I already dig a lot in the documentations but found nothing. That's why I posted this question here.. Anyway, thanks.tomekc– tomekc2017年04月19日 11:58:39 +00:00Commented Apr 19, 2017 at 11:58
2 Answers 2
OK. I found a little workaround. Arduino UNO Wifi web interface gives some possibilities. When you go to http://<IPADDRESS>/wifi/info
you'll get json formatted info about its wifi connection settings, including WiFi mode (STA or AP+STA). To set new WiFi Mode you can go to http://<IPADDRESS>/wifi/setmode?mode=<MODE>
to set new mode. mode=1 is for 'STA', mode=2 is for 'AP' only and mode=3 is for 'AP+STA'.
I've created a little cron job on my server that checks the wifi mode and changes it if needed.
Note that when the Uno WiFi board first boots, it is in AP+STA mode...
- Which means it broadcasts its own SSID (that's the AP part).
AND
- It can connect to an existing wireless AP on your network, if you've configured those settings (that's the STA part, because it's a STAtion off the infrastructure AP).
IDEALLY
- You will change it to STA mode so it connects to your existing wireless AP only and stops broadcasting as its own AP.
Why does yours go back to AP+STA mode? Is your sketch crashing/running out of memory/rebooting? Is it older firmware? I'm not sure.
-
The thing is that I have 5 Uno WiFi boards that are working all the time, all of them doing exactly the same stuff (just in different areas of our warehouse). Only two of them are sometimes switching to AP+STA mode in a different periods of time - sometimes once a week, sometimes more frequently. Other 3 devices are running without an issue.tomekc– tomekc2017年10月11日 11:43:13 +00:00Commented Oct 11, 2017 at 11:43