ESP32 web server; works in STA mode -but- not AP mode - arduino

Web server using ESP32 WROOM-32 DevKit 1
Problem: uploaded web server created by Jason Coon via esp32- fastled-webserver; works as described in Station Mode; added softAP mode to existing code; Station mode still works without any problems -however- softAP will not connect and load web pages even though WiFi channel is created. Changed channel from default "1" to "9" with no change in working status; changed IP address with same results; changed from using Arduino 1.8.19 to VS Code, same results
const bool apMode = true;
when bool is true
if (apMode)
{
WiFi.mode(WIFI_AP);
WiFi.softAP(hostnameChar, WiFiAPPSK, 9);
Serial.printf("Connect to Wi-Fi access point: %s\n", hostnameChar);
Serial.println("and open http://192.168.4.1 in your browser");
}
else
{
WiFi.mode(WIFI_STA);
Serial.printf("Connecting to %s\n", ssid);
if (String(WiFi.SSID()) != String(ssid)) {
WiFi.begin(ssid, password);
}
}
const char hostnameChar[] = "JailCell";
const char WiFiAPPSK[] = "123456789";
This initializes the module as softAP. understood.
Scanning for WiFi activity I find JailCell and attempt to connect to it using the address provided thru the WiFi Activity app. The address is accepted and attempts to load but does not.
If I can const bool apMode = true; >> change to false
// cellphone
const char* ssid = "xxxxxxxxxx";
const char* password = "xxxxxxxxxx";
if (apMode)
{
WiFi.mode(WIFI_AP);
WiFi.softAP(hostnameChar, WiFiAPPSK, 9);
Serial.printf("Connect to Wi-Fi access point: %s\n", hostnameChar);
Serial.println("and open http://192.168.4.1 in your browser");
}
else
{
WiFi.mode(WIFI_STA);
Serial.printf("Connecting to %s\n", ssid);`your text`
if (String(WiFi.SSID()) != String(ssid)) {
WiFi.begin(ssid, password);
}
}
I can now access the web server using an address provided from the serial monitor port; 192.168.77.50 and web pages loads with no problem.
No other changes occurs... what are I missing?
Initial build & compile using Arduino 1.8.19; ESP 2.0.5
Changed to VS Code with same results
*** AP Mode *****
WebServer webServer(80);
const bool apMode = true;
13: 14: 48.984 -> rst: 0x1 (POWERON_RESET), boot: 0x13 (SPI_FAST_FLASH_BOOT)
13: 14: 48.984 -> configsip: 0, SPIWP: 0xee
13: 14: 48.984 -> clk_drv: 0x00, q_drv: 0x00, d_drv: 0x00, cs0_drv: 0x00, hd_drv: 0x00, wp_drv: 0x00
13: 14: 48.984 -> mode: DIO, clock div: 1
13: 14: 48.984 -> load: 0x3fff0030, len: 1240
13: 14: 48.984 -> load: 0x40078000, len: 13012
13: 14: 48.984 -> load: 0x40080400, len: 3648
13: 14: 49.018 -> entry 0x400805f8
13: 14: 49.451 -> Listing directory: /
13: 14: 49.584 -> FILE: app.js SIZE: 13101
13: 14: 49.584 -> FILE: favicon.ico SIZE: 4286
13: 14: 49.584 -> FILE: atom196.png SIZE: 5469
13: 14: 49.584 -> FILE: styles.css SIZE: 31
13: 14: 49.618 -> FILE: index.htm SIZE: 10733
13: 14: 49.786 -> Connect to Wi - Fi access point: JailCell
13: 14: 49.786 -> and open http: //192.168.4.1 in your browser
13: 14: 49.917 -> HTTP server started
13: 14: 50.050 -> ......................................................................................
***** STA Mode: *****
WebServer webServer(80);
const bool apMode = false;
13: 21: 28.421 -> rst: 0x1 (POWERON_RESET), boot: 0x13 (SPI_FAST_FLASH_BOOT)
13: 21: 28.421 -> configsip: 0, SPIWP: 0xee
13: 21: 28.421 -> clk_drv: 0x00, q_drv: 0x00, d_drv: 0x00, cs0_drv: 0x00, hd_drv: 0x00, wp_drv: 0x00
13: 21: 28.454 -> mode: DIO, clock div: 1
13: 21: 28.454 -> load: 0x3fff0030, len: 1240
13: 21: 28.454 -> load: 0x40078000, len: 13012
13: 21: 28.454 -> load: 0x40080400, len: 3648
13: 21: 28.454 -> entry 0x400805f8
13: 21: 28.887 -> Listing directory: /
13: 21: 29.053 -> FILE: app.js SIZE: 13101
13: 21: 29.053 -> FILE: favicon.ico SIZE: 4286
13: 21: 29.053 -> FILE: atom196.png SIZE: 5469
13: 21: 29.053 -> FILE: styles.css SIZE: 31
13: 21: 29.053 -> FILE: index.htm SIZE: 10733
13: 21: 29.214 -> Connecting to SMG930V5FE3
13: 21: 29.353 -> HTTP server started
13: 21: 29.486 -> ...............
13: 21: 31.419 -> WiFi connected
13: 21: 31.419 -> IP address: 192.168.77.50
13: 21: 31.552 -> HTTP server started
// ESP32 FastLED WebServer: https://github.com/jasoncoon/esp32-fastled-webserver; Copyright (C) 2017 Jason Coon
#include <FastLED.h>
#include <WiFi.h>
#include <WebServer.h>
#include <FS.h>
#include <SPIFFS.h>
#include <EEPROM.h>
#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3003000)
#warning "Requires FastLED 3.3 or later; check github for latest code."
#endif
WebServer webServer(80);
const bool apMode = true;
const int led = 5;
uint8_t autoplay = 0;
uint8_t autoplayDuration = 10;
unsigned long autoPlayTimeout = 0;
uint8_t currentPatternIndex = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
uint8_t power = 1;
uint8_t brightness = 8;
uint8_t speed = 30;
uint8_t cooling = 50;
uint8_t sparking = 120;
CRGB solidColor = CRGB::Blue;
uint8_t cyclePalettes = 0;
uint8_t paletteDuration = 10;
uint8_t currentPaletteIndex = 0;
unsigned long paletteTimeout = 0;
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
#define DATA_PIN 18
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_STRIPS 1
#define NUM_LEDS_PER_STRIP 64
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
CRGB leds[NUM_LEDS];
#define FRAMES_PER_SECOND 120
#include "patterns.h"
#include "field.h"
#include "fields.h"
#include "msds.h"
#include "web.h"
void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.name(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void setup() {
pinMode(led, OUTPUT);
digitalWrite(led, 1);
Serial.begin(115200);
SPIFFS.begin();
listDir(SPIFFS, "/", 1);
if (apMode)
{
WiFi.mode(WIFI_AP);
WiFi.softAP(hostnameChar, WiFiAPPSK, 9);
Serial.printf("Connect to Wi-Fi access point: %s\n", hostnameChar);
Serial.println("and open http://192.168.4.1 in your browser");
}
else
{
WiFi.mode(WIFI_STA);
Serial.printf("Connecting to %s\n", ssid);
if (String(WiFi.SSID()) != String(ssid)) {
WiFi.begin(ssid, password);
}
}
setupWeb();
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(brightness);
autoPlayTimeout = millis() + (autoplayDuration * 1000);
}
void loop()
{
handleWeb();
if (power == 0) {
fill_solid(leds, NUM_LEDS, CRGB::Black);
}
else {
// Call the current pattern function once, updating the 'leds' array
patterns[currentPatternIndex].pattern();
EVERY_N_MILLISECONDS(40) {
// slowly blend the current palette to the next
nblendPaletteTowardPalette(currentPalette, targetPalette, 8);
gHue++; // slowly cycle the "base color" through the rainbow
}
if (autoplay == 1 && (millis() > autoPlayTimeout)) {
nextPattern();
autoPlayTimeout = millis() + (autoplayDuration * 1000);
}
if (cyclePalettes == 1 && (millis() > paletteTimeout)) {
nextPalette();
paletteTimeout = millis() + (paletteDuration * 1000);
}
}
// send the 'leds' array out to the actual LED strip
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
currentPatternIndex = (currentPatternIndex + 1) % patternCount;
}
void nextPalette()
{
currentPaletteIndex = (currentPaletteIndex + 1) % paletteCount;
targetPalette = palettes[currentPaletteIndex];
}
// ESP32 FastLED WebServer: https://github.com/jasoncoon/esp32-fastled-webserver; Copyright (C) 2017 Jason Coon
#include <FastLED.h>
#include <WiFi.h>
#include <WebServer.h>
#include <FS.h>
#include <SPIFFS.h>
#include <EEPROM.h>
#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3003000)
#warning "Requires FastLED 3.3 or later; check github for latest code."
#endif
WebServer webServer(80);
const bool apMode = true;
const int led = 5;
uint8_t autoplay = 0;
uint8_t autoplayDuration = 10;
unsigned long autoPlayTimeout = 0;
uint8_t currentPatternIndex = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
uint8_t power = 1;
uint8_t brightness = 8;
uint8_t speed = 30;
uint8_t cooling = 50;
uint8_t sparking = 120;
CRGB solidColor = CRGB::Blue;
uint8_t cyclePalettes = 0;
uint8_t paletteDuration = 10;
uint8_t currentPaletteIndex = 0;
unsigned long paletteTimeout = 0;
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
#define DATA_PIN 18
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_STRIPS 1
#define NUM_LEDS_PER_STRIP 64
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
CRGB leds[NUM_LEDS];
#define FRAMES_PER_SECOND 120
#include "patterns.h"
#include "field.h"
#include "fields.h"
#include "msds.h"
#include "web.h"
void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.name(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void setup() {
pinMode(led, OUTPUT);
digitalWrite(led, 1);
Serial.begin(115200);
SPIFFS.begin();
listDir(SPIFFS, "/", 1);
if (apMode)
{
WiFi.mode(WIFI_AP);
WiFi.softAP(hostnameChar, WiFiAPPSK, 9);
Serial.printf("Connect to Wi-Fi access point: %s\n", hostnameChar);
Serial.println("and open http://192.168.4.1 in your browser");
}
else
{
WiFi.mode(WIFI_STA);
Serial.printf("Connecting to %s\n", ssid);
if (String(WiFi.SSID()) != String(ssid)) {
WiFi.begin(ssid, password);
}
}
setupWeb();
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(brightness);
autoPlayTimeout = millis() + (autoplayDuration * 1000);
}
void loop()
{
handleWeb();
if (power == 0) {
fill_solid(leds, NUM_LEDS, CRGB::Black);
}
else {
// Call the current pattern function once, updating the 'leds' array
patterns[currentPatternIndex].pattern();
EVERY_N_MILLISECONDS(40) {
// slowly blend the current palette to the next
nblendPaletteTowardPalette(currentPalette, targetPalette, 8);
gHue++; // slowly cycle the "base color" through the rainbow
}
if (autoplay == 1 && (millis() > autoPlayTimeout)) {
nextPattern();
autoPlayTimeout = millis() + (autoplayDuration * 1000);
}
if (cyclePalettes == 1 && (millis() > paletteTimeout)) {
nextPalette();
paletteTimeout = millis() + (paletteDuration * 1000);
}
}
// send the 'leds' array out to the actual LED strip
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
currentPatternIndex = (currentPatternIndex + 1) % patternCount;
}
void nextPalette()
{
currentPaletteIndex = (currentPaletteIndex + 1) % paletteCount;
targetPalette = palettes[currentPaletteIndex];
}
// AP mode password
// WiFi.softAP(hostnameChar, WiFiAPPSK);
const char hostnameChar[] = "JailCell";
const char WiFiAPPSK[] = "123456789";
// Wi-Fi network to connect to (if not in AP mode)
//LVL1 uncomment this!
// const char* ssid = "RouterName";
// const char* password = "RouterPassword";
In my search to find the answer for why the esp32 module works flawlessly in STATION mode but sudo in AP mode (generates WiFi channel and IP address but never loads web page) I found this unique bit of code that might help.
void get_network_info() {
if (WiFi.status() == WL_CONNECTED) {
Serial.print("[*] Network information for ");
Serial.println(ssid);
Serial.println("[+] BSSID : " + WiFi.BSSIDstr());
Serial.print("[+] Gateway IP : ");
Serial.println(WiFi.gatewayIP());
Serial.print("[+] Subnet Mask : ");
Serial.println(WiFi.subnetMask());
Serial.println((String)"[+] RSSI : " + WiFi.RSSI() + " dB");
Serial.print("[+] ESP32 IP : ");
Serial.println(WiFi.localIP());
}
}
Adding this I configured the esp32 module for STATION mode and see the expects results in the monitor port.
***** STATION Mode *****
07:41:47.858 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
07:41:47.858 -> configsip: 0, SPIWP:0xee
07:41:47.891 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
07:41:47.891 -> mode:DIO, clock div:2
07:41:47.891 -> load:0x3fff0030,len:1344
07:41:47.891 -> load:0x40078000,len:13836
07:41:47.891 -> load:0x40080400,len:3608
07:41:47.891 -> entry 0x400805f0
07:41:48.190 -> [ 1][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=80, ...)
07:41:48.190 -> ⸮⸮⸮mYum]⸮⸮M⸮⸮ٕɹcpp:87] WebServer(): WebServer::Webserver(port=80)
07:41:48.190 -> [ 9][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
07:41:48.823 -> Listing directory: /
07:41:48.922 -> FILE: app.js SIZE: 13101
07:41:48.922 -> FILE: favicon.ico SIZE: 4286
07:41:48.922 -> FILE: atom196.png SIZE: 5469
07:41:48.956 -> FILE: styles.css SIZE: 31
07:41:48.956 -> FILE: index.htm SIZE: 10733
07:41:49.155 -> [ 819][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
07:41:49.155 -> [ 907][I][WiFiGeneric.cpp:1354] setDualAntennaConfig(): TX Antenna will be automatically selected
07:41:49.155 -> Connecting to SMG930V5FE3
07:41:49.155 -> [ 907][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
07:41:49.155 -> [ 910][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
07:41:49.155 -> [ 913][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
07:41:49.155 -> [ 940][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/index.htm uri=/ isFile=1, cache_header=max-age=86400
07:41:49.155 ->
07:41:49.155 -> [ 944][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/index.htm uri=/index.htm isFile=1, cache_header=max-age=86400
07:41:49.155 ->
07:41:49.272 -> [ 1004][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/favicon.ico uri=/favicon.ico isFile=1, cache_header=max-age=86400
07:41:49.272 ->
07:41:49.272 -> [ 1009][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/css/styles.css uri=/css/styles.css isFile=1, cache_header=max-age=86400
07:41:49.272 ->
07:41:49.272 -> [ 1009][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: SMG930V5FE3, BSSID: 1e:83:64:fa:c3:2b, Channel: 11, Auth: WPA2_PSK
07:41:49.390 -> [ 1034][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
07:41:49.390 -> [ 1076][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/js/app.js uri=/js/app.js isFile=1, cache_header=max- age=86400
07:41:49.390 ->
07:41:49.390 -> [ 1080][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/images/atom196.png uri=/images/atom196.png isFile=1, cache_header=max-age=86400
07:41:49.390 ->
07:41:49.390 -> [ 1096][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got New IP:192.168.212.50
07:41:49.390 -> [ 1100][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
07:41:49.390 -> [ 1107][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 192.168.212.50, MASK: 255.255.255.0, GW: 192.168.212.234
07:41:49.390 -> HTTP server started
07:41:49.390 -> [*] Network information for SMG930V5FE3
07:41:49.390 -> [+] BSSID : 1E:83:64:FA:C3:2B
07:41:49.390 -> [+] Gateway IP : 192.168.212.234
07:41:49.390 -> [+] Subnet Mask : 255.255.255.0
07:41:49.390 -> [+] RSSI : -71 dB
07:41:49.390 -> [+] ESP32 IP : 192.168.212.50
07:41:49.390 ->
However I did not get the same when I changed the mode to AP.
***** AP Mode *****
07:53:55.176 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
07:53:55.176 -> configsip: 0, SPIWP:0xee
07:53:55.176 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
07:53:55.176 -> mode:DIO, clock div:2
07:53:55.209 -> load:0x3fff0030,len:1344
07:53:55.209 -> load:0x40078000,len:13836
07:53:55.209 -> load:0x40080400,len:3608
07:53:55.209 -> entry 0x400805f0
07:53:55.475 -> [ 1][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=80, ...)
07:53:55.509 -> ⸮⸮⸮mYum]⸮⸮M⸮⸮ٕɹcpp:87] WebServer(): WebServer::Webserver(port=80)
07:53:55.509 -> [ 9][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
07:53:56.141 -> Listing directory: /
07:53:56.240 -> FILE: app.js SIZE: 13101
07:53:56.240 -> FILE: favicon.ico SIZE: 4286
07:53:56.240 -> FILE: atom196.png SIZE: 5469
07:53:56.240 -> FILE: styles.css SIZE: 31
07:53:56.240 -> FILE: index.htm SIZE: 10733
07:53:56.409 -> [ 826][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
07:53:56.409 -> [ 920][I][WiFiGeneric.cpp:1354] setDualAntennaConfig(): TX Antenna will be automatically selected
07:53:56.409 -> [ 920][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
07:53:56.409 -> [ 924][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
07:53:56.907 -> [ 1421][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring SoftAP static IP: 192.168.222.1, MASK: 255.255.255.0, GW: 192.168.200.10
07:53:56.907 -> [ 1423][V][WiFiGeneric.cpp:143] set_esp_interface_ip(): SoftAP: 192.168.222.1 | Gateway: 192.168.200.10 | DHCP Start: 0.0.0.0 | Netmask: 255.255.255.0
07:53:56.970 -> [ 1436][V][WiFiGeneric.cpp:190] set_esp_interface_ip(): DHCP Server Range: 192.168.222.2 to 192.168.222.12
07:53:57.938 -> [ 2446][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
07:53:57.938 -> [ 2447][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
07:53:57.938 -> [ 2449][I][WiFiGeneric.cpp:1354] setDualAntennaConfig(): TX Antenna will be automatically selected
07:53:58.016 -> [ 2459][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
07:53:58.016 -> [+] AP Created with IP Gateway 192.168.222.1
07:53:58.016 -> [ 2476][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/index.htm uri=/ isFile=1, cache_header=max-age=86400
07:53:58.016 ->
07:53:58.016 -> [ 2485][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/index.htm uri=/index.htm isFile=1, cache_header=max-age=86400
07:53:58.016 ->
07:53:58.016 -> [ 2545][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/favicon.ico uri=/favicon.ico isFile=1, cache_header=max-age=86400
07:53:58.156 ->
07:53:58.156 -> [ 2549][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/css/styles.css uri=/css/styles.css isFile=1, cache_header=max-age=86400
07:53:58.156 ->
07:53:58.156 -> [ 2609][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/js/app.js uri=/js/app.js isFile=1, cache_header=max-age=86400
07:53:58.156 ->
07:53:58.156 -> [ 2613][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/images/atom196.png uri=/images/atom196.png isFile=1, cache_header=max-age=86400
07:53:58.156 ->
07:53:58.156 -> HTTP server started
07:53:58.298 -> ....................[ 5309][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: esp32_softAP, BSSID: 00:00:00:00:00:00, Reason: 201
07:54:00.797 -> [ 5310][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
07:54:00.858 -> [ 5317][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
07:54:00.858 -> [ 5324][D][WiFiGeneric.cpp:966] _eventCallback(): WiFi Reconnect Running
07:54:00.858 -> [ 5333][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
07:54:00.913 -> .....................[ 8182][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: esp32_softAP, BSSID: 00:00:00:00:00:00, Reason: 201
07:54:03.670 -> [ 8183][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
07:54:03.732 -> [ 8190][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
07:54:03.732 -> [ 8197][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
07:54:03.732 -> [ 8206][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
07:54:03.732 -> ...............
Here is the Setup code.
void setup() {
pinMode(led, OUTPUT);
digitalWrite(led, 1);
Serial.begin(115200);
if (!SPIFFS.begin(true)) {
Serial.println("SPIFFS Mount Failed");
return;
}
listDir(SPIFFS, "/", 1);
/*
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(local_ip, gateway, subnet);
WiFi.softAP(ssid, password, channel, hide_SSID, max_connection);
WiFi.begin(ssid, password);
Serial.print("[+] AP Created with IP Gateway ");
Serial.println(WiFi.softAPIP());
*/
WiFi.mode(WIFI_STA);
Serial.printf("Connecting to %s\n", ssid);
if (String(WiFi.SSID()) != String(ssid)) {
WiFi.begin(ssid, password);
}
setupWeb();
get_network_info();
void get_network_info() {
if (WiFi.status() == WL_CONNECTED) {
Serial.print("[*] Network information for ");
Serial.println(ssid);
Serial.println("[+] BSSID : " + WiFi.BSSIDstr());
Serial.print("[+] Gateway IP : ");
Serial.println(WiFi.gatewayIP());
Serial.print("[+] Subnet Mask : ");
Serial.println(WiFi.subnetMask());
Serial.println((String)"[+] RSSI : " + WiFi.RSSI() + " dB");
Serial.print("[+] ESP32 IP : ");
Serial.println(WiFi.localIP());
}
}
Open to comments and suggestions as to why STATION mode works while AP mode sudo works

Related

Unable to establish connection to mosquitto broker from Arduino+ESP8266

I am using Arduino Uno and ESP8266 for WIFI connectivity. My Laptop on which mosquitto broker is running and Arduino(through ESP8266) is are both connected to wifi network. But I am unable to establish a connection to mqtt server.
I am using the follwing code.
#define FASTLED_INTERNAL
#include <SoftwareSerial.h>
#include <DHT.h>
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspUdp.h>
#include <PubSubClient.h>
#include <FastLED.h>
#define DHTPIN 2
#define DHTTYPE DHT11
#define ESP_RX 9
#define ESP_TX 8
#define WIFI_AP "Anurag"
#define WIFI_PASSWORD "qwerty12345"
#define NUM_LED 64
#define DATA_PIN 5
#define CLOCK_PIN 13
static const int RXPin = 4, TXPin = 3;
static const uint32_t baudRate = 9600;
static const int rainSensorMin = 0;
static const int rainSensorMax = 1024;
WiFiEspClient espClient;
PubSubClient mqttClient(espClient);
IPAddress broker(192,168,43,235);
SoftwareSerial ESP8266(ESP_RX, ESP_TX);
DHT dht(DHTPIN, DHTTYPE);
int status = WL_IDLE_STATUS;
char *ID = "uno";
char *TOPIC = "weatherStats";
int AT_cmd_time;
boolean AT_cmd_result = false;
CRGB leds[NUM_LED];
void setup() {
//pinMode(13, OUTPUT);
//FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LED);
Serial.begin(9600);
//ss.begin(baudRate);
initWiFi();
dht.begin();
mqttClient.setServer(broker,1883);
Serial.println("GPS, DHT11, and, Raindrop detector started.");
}
void loop() {
status = WiFi.status();
if ( status != WL_CONNECTED) {
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(WIFI_AP);
// Connect to WPA/WPA2 network
status = WiFi.begin(WIFI_AP, WIFI_PASSWORD);
delay(500);
}
Serial.println("Connected to AP");
}
delay(3000);
float h = dht.readHumidity();
float t = dht.readTemperature();
int rainReading = analogRead(A0);
int range = map(rainReading, rainSensorMin, rainSensorMax, 0, 2);
if(!mqttClient.connected()){
reconnect_mqtt();
}
mqttClient.loop();
mqttClient.publish(TOPIC,"one step forward");
//Serial.println("Satellites: " + String(gps.satellites.value()));
if (!isnan(h) || !isnan(t))
Serial.print("Temparture: " + String(t) + "°C | " + " Humidity: " + String(h) + " | ");
else {
Serial.println("Failed to obtain temparature and humidity data");
}
switch (range) {
case 0:
Serial.print("Rain Warning : 1");
break;
case 1:
Serial.print("Rain Warning : 0");
break;
}
Serial.println(" | Lat: 22.716191217468406 Lon: 72.44229199663788");
}
void initWiFi(){
ESP8266.begin(9600);
WiFi.init(&ESP8266);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true) {
}
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(WIFI_AP);
//Connect to WPA/WPA2 network
status = WiFi.begin(WIFI_AP, WIFI_PASSWORD);
}
}
void reconnect_mqtt(){
while(!mqttClient.connected()){
Serial.println("Attempting MQTT Connection");
if(mqttClient.connect(ID)){
Serial.println("MQTT connection established.");
Serial.print("Publishing to: ");
Serial.println(TOPIC);
}
else{
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
Runnig this code I keep getting output "try again in 5 seconds". Please help.

Can't connect arduino to IBM IoT platform

I have been trying to make this tutorial work: https://developer.ibm.com/recipes/tutorials/arduino-nano-ethernet-shield-and-iot/.
I have done every step but my Arduino nano is not connected. At dashboard Connection Status of device is Disconnected and at serial monitor I have messages Arduino MQTT v, 1, 2, Reconnecting client...
My code is below.
#include <UIPEthernet.h>
#include <PubSubClient.h>
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 200 }; //put your device’s local ip here DA
EthernetClient ethClient;
//char servername[]=”1jyf9u.messaging.internetofthings.ibmcloud.com”;
char servername[] = { 141, 125, 70, 157 };
PubSubClient client(servername, 1883, 0, ethClient);
void setup()
{
Serial.begin(9600);
Serial.println("Arduino MQTT v, 1, 2");
Ethernet.begin(mac, ip);
}
void loop()
{
//client.loop();
char clientStr[33];
String clientName = String("d:1jyf9u:my_nano_type:my_nano_id");
clientName.toCharArray(clientStr, 33);
char token[] = "6q_n#g#HjUyQJEv6Nx";
while (!client.connected()) {
Serial.println("Reconnecting client … ");
client.connect(clientStr, "use - token - auth", token);
}
String data = "{\"d\": {\"TEST\" : \"";
data += random(10);
data += "\" } } " ;
char jsonStr[33];
data.toCharArray(jsonStr, 33);
char topicStr[33];
String topicName = String("iot - 2 / evt / status / fmt / json");
topicName.toCharArray(topicStr, 33);
Serial.print("attempt to send ");
Serial.print(jsonStr);
Serial.print(" to ");
Serial.println(topicStr);
if (client.publish(topicStr, jsonStr))
Serial.println("successfully sent");
else
Serial.println("unsuccessfully sent");
Serial.println("Disconnecting client … ");
client.disconnect();
delay(5000);
}
I have tried to changed default rule to TLS optional. Also, I tried to change port to 8883 and set up default rule to TLS with Token Authentication but none succeeded.
Any idea/suggestions?

Code error in smart irrigation system, using dht11 sensor

I have wrtitten a code for automatically watering plant using esp8266, dht11, moisture sensor but my code has some error, i dont know how to fix it
#include <DHT.h>
#include <ESP8266WiFi.h>
String apiKey = "X5AQ3EGIKMBYW31H"; // Enter your Write API key here
const char* server = "api.thingspeak.com";
const char *ssid = "CircuitLoop"; // Enter your WiFi Name
const char *pass = "circuitdigest101"; // Enter your WiFi Password
#define DHTPIN D3 // GPIO Pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
WiFiClient client;
const int moisturePin = A0; // moisteure sensor pin
const int motorPin = D0;
unsigned long interval = 10000;
unsigned long previousMillis = 0;
unsigned long interval1 = 1000;
unsigned long previousMillis1 = 0;
float moisturePercentage; //moisture reading
float h; // humidity reading
float t; //temperature reading
void setup()
{
Serial.begin(115200);
delay(10);
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, LOW); // keep motor off initally
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("."); // print ... till not connected
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
unsigned long currentMillis = millis(); // grab current time
h = dht.readHumidity(); // read humiduty
t = dht.readTemperature(); // read temperature
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
moisturePercentage = ( 100.00 - ( (analogRead(moisturePin) / 1023.00) * 100.00 ) );
if ((unsigned long)(currentMillis - previousMillis1) >= interval1) {
Serial.print("Soil Moisture is = ");
Serial.print(moisturePercentage);
Serial.println("%");
previousMillis1 = millis();
}
if (moisturePercentage < 50) {
digitalWrite(motorPin, HIGH); // tun on motor
}
if (moisturePercentage > 50 && moisturePercentage < 55) {
digitalWrite(motorPin, HIGH); //turn on motor pump
}
if (moisturePercentage > 56) {
digitalWrite(motorPin, LOW); // turn off mottor
}
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
sendThingspeak(); //send data to thing speak
previousMillis = millis();
client.stop();
}
}
void sendThingspeak() {
if (client.connect(server, 80))
{
String postStr = apiKey; // add api key in the postStr string
postStr += "&field1=";
postStr += String(moisturePercentage); // add mositure readin
postStr += "&field2=";
postStr += String(t); // add tempr readin
postStr += "&field3=";
postStr += String(h); // add humidity readin
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length()); //send lenght of the string
client.print("\n\n");
client.print(postStr); // send complete string
Serial.print("Moisture Percentage: ");
Serial.print(moisturePercentage);
Serial.print("%. Temperature: ");
Serial.print(t);
Serial.print(" C, Humidity: ");
Serial.print(h);
Serial.println("%. Sent to Thingspeak.");
}
}
This is the error which i get
Arduino: 1.8.9 (Windows 8.1), Board: "Generic ESP8266 Module, 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), ck, 26 MHz, 40MHz, DOUT (compatible), 512K (no SPIFFS), 2, nonos-sdk 2.2.1 (legacy), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
sketch_oct03a:7:16: error: 'D3' was not declared in this scope
#define DHTPIN D3 // GPIO Pin where the dht11 is connected
^
C:\Users\Shweta\Desktop\Libraries\sketch_oct03a\sketch_oct03a.ino:8:9: note: in expansion of macro 'DHTPIN'
DHT dht(DHTPIN, DHT11);
^
sketch_oct03a:12:22: error: 'D0' was not declared in this scope
const int motorPin = D0;
^
exit status 1
'D3' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Digital pins are not prefixed with D, unlike their analog counterparts.
#define DHTPIN 3
const int motorPin = 0;

how to set up RGB leds on arduino ethernet with udp instruction?

I'm working on a kind of traffic light with RGB LEDs. I try to take a udp value sent from a server to the arduino mega and ethernet shield, then the arduino should change the color of the LED.
Sadly until now, it does not work. In the serial monitor, I find out that the udp packet was received, but then the LED does not work. I was hoping that you guys can help me to figure out why my code isn't working. Thank you in advance! Here is my code:
/*
Web Server
*/
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
void Color(int R, int G, int B) //set up for the RGB led
{
analogWrite(3, R) ; // Rojo
analogWrite(5, G) ; // Green - Verde
analogWrite(6, B) ; // Blue - Azul
}
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10, 90, 111, 150);
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() { //seting up the outputs for the rgb
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet WebServer Example");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// start the server
Udp.begin(localPort);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
char numero = packetBuffer;
if (numero = "1") Color(250, 0, 0) ;
if (numero = "2") Color(100, 110, 0);
if (numero = "3") Color(0, 255, 0);
delay(10);
}
From now, it just receives the udp, and while compiling I get:
warning: invalid conversion from 'const char*' to 'char' [-fpermissive]
but in the end, it compiles.
edited:
i changed the code in this way (just in the final part), and now when i send the udp packet, no matter what i send, i get the green light on, but only the green one, here is the code
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
char numero = packetBuffer;
if (numero = 'R') Color(250, 0, 0) ;
if (numero = 'A') Color(100, 100, 0);
if (numero = 'V') Color(0, 255, 0);
// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
I'd recommend to find some C++ tutorial for starters.
Anyway:
char numero = packetBuffer; // wrong, you are assigning part of address to char, not character at that address...
if (numero = 'R') Color(250, 0, 0) ; // better but still wrong - numero is set to 'R' and it's also always true
if (numero = 'A') Color(100, 100, 0); // similar to previous
if (numero = 'V') Color(0, 255, 0); // and again
Correct version:
char numero = packetBuffer[0]; // get the first character in buffer
if (numero == 'R') Color(250, 0, 0) ; // compare numero with 'R'
if (numero == 'A') Color(100, 100, 0); // compare numero with 'A'
if (numero == 'V') Color(0, 255, 0); // ...
If there is nothing else wrong, that should fix it

Supress AT code output in the serial monitor on Adafruit Fona

I have modified the Adafruit Fona GPS example file to show the error between my location and GPS and GSM locations that it collects. The error part that I'm outputting is showing up correctly, but the AT codes are also displaying on the serial monitor and I can't figure out how to suppress them. Code is below and output is below that. I'm trying to get rid of everything that isn't the line starting with "GPS Error...".
/**
* ___ ___ _ _ _ ___ __ ___ ___ ___ ___
* | __/ _ \| \| | /_\ ( _ )/ \( _ ) / __| _ \/ __|
* | _| (_) | .` |/ _ \ / _ \ () / _ \ | (_ | _/\__ \
* |_| \___/|_|\_/_/ \_\ \___/\__/\___/ \___|_| |___/
*
* This example is meant to work with the Adafruit
* FONA 808 or 3G Shield or Breakout
*
* Copyright: 2015 Adafruit
* Author: Todd Treece
* Licence: MIT
*
*/
#include "Adafruit_FONA.h"
// standard pins for the shield, adjust as necessary
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
const float CURR_LAT = 28.086084;
const float CURR_LON = -82.401916;
float GPS_LAT;
float GPS_LON;
float GSM_LAT;
float GSM_LON;
// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Have a FONA 3G? use this object type instead
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
void setup() {
while (! Serial);
Serial.begin(115200);
// Serial.println(F("Adafruit FONA 808 & 3G GPS demo"));
// Serial.println(F("Initializing FONA... (May take a few seconds)"));
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
// Serial.println(F("Couldn't find FONA"));
while(1);
}
// Serial.println(F("FONA is OK"));
// Try to enable GPRS
// Serial.println(F("Enabling GPS..."));
fona.enableGPS(true);
}
void loop() {
delay(1000);
float latitude, longitude, speed_kph, heading, speed_mph, altitude;
// if you ask for an altitude reading, getGPS will return false if there isn't a 3D fix
boolean gps_success = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);
if (gps_success) {
// Serial.print("GPS lat:");
// Serial.println(latitude, 6);
// Serial.print("GPS long:");
// Serial.println(longitude, 6);
// Serial.print("GPS speed KPH:");
// Serial.println(speed_kph);
// Serial.print("GPS speed MPH:");
// speed_mph = speed_kph * 0.621371192;
// Serial.println(speed_mph);
// Serial.print("GPS heading:");
// Serial.println(heading);
// Serial.print("GPS altitude:");
// Serial.println(altitude);
GPS_LAT = latitude;
GPS_LON = longitude;
} else {
// Serial.println("Waiting for FONA GPS 3D fix...");
}
// Fona 3G doesnt have GPRSlocation :/
if ((fona.type() == FONA3G_A) || (fona.type() == FONA3G_E))
return;
// Check for network, then GPRS
// Serial.println(F("Checking for Cell network..."));
if (fona.getNetworkStatus() == 1) {
// network & GPRS? Great! Print out the GSM location to compare
boolean gsmloc_success = fona.getGSMLoc(&latitude, &longitude);
if (gsmloc_success) {
// Serial.print("GSMLoc lat:");
// Serial.println(latitude, 6);
// Serial.print("GSMLoc long:");
// Serial.println(longitude, 6);
GSM_LAT = latitude;
GSM_LON = longitude;
} else {
// Serial.println("GSM location failed...");
// Serial.println(F("Disabling GPRS"));
fona.enableGPRS(false);
// Serial.println(F("Enabling GPRS"));
if (!fona.enableGPRS(true)) {
// Serial.println(F("Failed to turn GPRS on"));
}
}
}
//const float CURR_LAT = 28.086084;
//const float CURR_LON = -82.401916;
//float GPS_LAT;
//float GPS_LON;
//float GSM_LAT;
//float GSM_LON;
float GPS_DIFF = sqrt((GPS_LAT - CURR_LAT)*(GPS_LAT - CURR_LAT) + (GPS_LON - CURR_LON)*(GPS_LON - CURR_LON));
float GSM_DIFF = sqrt((GSM_LAT - CURR_LAT)*(GSM_LAT - CURR_LAT) + (GSM_LON - CURR_LON)*(GSM_LON - CURR_LON));
Serial.print("GPS Error: ");
Serial.print(GPS_DIFF,6);
Serial.print(" GSM Error: ");
Serial.println(GSM_DIFF,6);
}
And the output is:
GPS Error: 87.056900 GSM Error: 87.056900
---> AT+CGNSINF
<--- +CGNSINF: 1,0,20170529194222.000,,,,0.20,78.0,0,,,,,,12,3,,,25,,
---> AT+CREG?
<--- +CREG: 0,1
---> AT+CIPGSMLOC=1,1
<--- +CIPGSMLOC: 601
---> AT+CIPSHUT
<--- SHUT OK
---> AT+SAPBR=0,1
<--- ERROR
---> AT+CIPSHUT
<--- SHUT OK
---> AT+CGATT=1
<--- OK
---> AT+SAPBR=3,1,"CONTYPE","GPRS"
<--- OK
---> AT+SAPBR=3,1,"APN","FONAnet"
<--- OK
---> AT+CSTT="FONAnet"
<--- OK
---> AT+SAPBR=1,1
<--- OK
---> AT+CIICR
<--- OK
GPS Error: 87.056900 GSM Error: 87.056900
You are using Adafruit's library/functions like fona.getGPS and is coded to return information.
It can be edited at the libraries "Adafruit_Fona" folder.

Resources