How To Solve Nodemcu ESP8266's Exception3 Problem? - wifi

I downloaded from Github Spacehuhn's ESP8266 deauther project (https://github.com/SpacehuhnTech/esp8266_deauther/tree/v2). It compiled without problem, and I could upload it to my board too, but after some seconds this appeared on my serial monitor:
OK
Formatting EEPROM...OK
Loading settings...Invalid Hash - reseted to default
Device names loaded from /names.json
SSIDs loaded from /ssids.json
Scan results saved in /scan.json
Serial interface enabled
Started AP
[WiFi] Path: '/web', Mode: 'AP', SSID: 'pwned', password: 'deauther', channel: '1', hidden: false, captive-portal: true
STARTED! \o/
2.2.0
# scan -t 5s
Stopped scan
Scan results saved in /scan.json
Removed all APs
Cleared station list
Starting scan for access points (Wi-Fi networks)...
I think it is interesting from this point:
Exception (3):
epc1=0x4000bef4 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4025adda depc=0x00000000
ctx: cont
sp: 3fff1b00 end: 3fff1e20 offset: 01a0
>>>stack>>>
3fff1ca0: 00000100 40004b14 3fff1ce0 4022af66
3fff1cb0: 3ffe87a8 4025adda 3fff1ce0 4022afb4
3fff1cc0: 4025adda 4010695e 3fff1dd0 3ffefcd0
3fff1cd0: 000147e1 3fff09d4 3fff1dd0 40218726
3fff1ce0: 3fff2ae8 0000000f 00000007 4022af36
3fff1cf0: 000147e1 3fff09d4 3fff1dd0 40218a2d
3fff1d00: 000147e1 3fff09d4 3fff0a90 40218e45
3fff1d10: 00000202 00000001 0000003c 00000000
3fff1d20: 00000258 00000119 00000001 00000001
3fff1d30: fb240001 00bbcdb8 2e105304 00c800e7
3fff1d40: 77700003 0064656e 00000000 00000000
3fff1d50: 00000000 00000000 00000000 00000000
3fff1d60: 64000000 74756165 00726568 00000000
3fff1d70: 00000000 00000000 00000000 00000000
3fff1d80: 00000000 00000000 00000000 00000000
3fff1d90: 00000000 00000000 00000000 00000000
3fff1da0: 00000000 04a8c000 00010101 01006e65
3fff1db0: 00000101 00000000 00000258 9c34a91b
3fff1dc0: 919c28e6 fe4cd405 401dd719 3e9e76c3
3fff1dd0: 3fff6a58 0000025f 00000002 3ffefcd0
3fff1de0: 000147e1 3ffefccc 3fff09d4 4021c8f0
3fff1df0: 00000000 00000000 00000000 3fff0dec
3fff1e00: 3fffdc20 00000000 3fff0de5 402250e5
3fff1e10: 00000000 00000000 3fff0e00 40100114
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
I could not figure out what could be the problem, so if you know what to do, don't hesitate, please reply as fast as possible. Thanks in advance. :)
Here is the sourcecode, but you can find it on the linked Github page too.
/*
===========================================
Copyright (c) 2018 Stefan Kremser
github.com/spacehuhn
===========================================
*/
extern "C" {
// Please follow this tutorial:
// https://github.com/spacehuhn/esp8266_deauther/wiki/Installation#compiling-using-arduino-ide
// And be sure to have the right board selected
#include "user_interface.h"
}
#include "EEPROMHelper.h"
#include <ArduinoJson.h>
#if ARDUINOJSON_VERSION_MAJOR != 5
// The software was build using ArduinoJson v5.x
// version 6 is still in beta at the time of writing
// go to tools -> manage libraries, search for ArduinoJSON and install version 5
#error Please upgrade/downgrade ArduinoJSON library to version 5!
#endif // if ARDUINOJSON_VERSION_MAJOR != 5
#include "oui.h"
#include "language.h"
#include "functions.h"
#include "Settings.h"
#include "Names.h"
#include "SSIDs.h"
#include "Scan.h"
#include "Attack.h"
#include "CLI.h"
#include "DisplayUI.h"
#include "A_config.h"
#include "webfiles.h"
#include "LED.h"
// Run-Time Variables //
LED led;
Settings settings;
Names names;
SSIDs ssids;
Accesspoints accesspoints;
Stations stations;
Scan scan;
Attack attack;
CLI cli;
DisplayUI displayUI;
#include "wifi.h"
uint32_t autosaveTime = 0;
uint32_t currentTime = 0;
bool booted = false;
void setup() {
// for random generator
randomSeed(os_random());
// start serial
Serial.begin(115200);
Serial.println();
// start SPIFFS
prnt(SETUP_MOUNT_SPIFFS);
bool spiffsError = !SPIFFS.begin();
prntln(spiffsError ? SETUP_ERROR : SETUP_OK);
// Start EEPROM
EEPROMHelper::begin(EEPROM_SIZE);
#ifdef FORMAT_SPIFFS
prnt(SETUP_FORMAT_SPIFFS);
SPIFFS.format();
prntln(SETUP_OK);
#endif // ifdef FORMAT_SPIFFS
#ifdef FORMAT_EEPROM
prnt(SETUP_FORMAT_EEPROM);
EEPROMHelper::format(EEPROM_SIZE);
prntln(SETUP_OK);
#endif // ifdef FORMAT_EEPROM
// Format SPIFFS when in boot-loop
if (spiffsError || !EEPROMHelper::checkBootNum(BOOT_COUNTER_ADDR)) {
prnt(SETUP_FORMAT_SPIFFS);
SPIFFS.format();
prntln(SETUP_OK);
prnt(SETUP_FORMAT_EEPROM);
EEPROMHelper::format(EEPROM_SIZE);
prntln(SETUP_OK);
EEPROMHelper::resetBootNum(BOOT_COUNTER_ADDR);
}
// get time
currentTime = millis();
// load settings
#ifndef RESET_SETTINGS
settings.load();
#else // ifndef RESET_SETTINGS
settings.reset();
settings.save();
#endif // ifndef RESET_SETTINGS
// set mac address
wifi_set_macaddr(STATION_IF, (uint8_t*)settings.getWifiSettings().mac_st);
wifi_set_macaddr(SOFTAP_IF, (uint8_t*)settings.getWifiSettings().mac_ap);
// start WiFi
WiFi.mode(WIFI_OFF);
wifi_set_opmode(STATION_MODE);
wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) {
scan.sniffer(buf, len);
});
// start display
if (settings.getDisplaySettings().enabled) {
displayUI.setup();
displayUI.mode = displayUI.DISPLAY_MODE::INTRO;
}
// copy web files to SPIFFS
copyWebFiles(false);
// load everything else
names.load();
ssids.load();
cli.load();
// create scan.json
scan.setup();
// set channel
setWifiChannel(settings.getWifiSettings().channel);
// load Wifi settings: SSID, password,...
loadWifiConfigDefaults();
// dis/enable serial command interface
if (settings.getCLISettings().enabled) {
cli.enable();
} else {
prntln(SETUP_SERIAL_WARNING);
Serial.flush();
Serial.end();
}
// start access point/web interface
if (settings.getWebSettings().enabled) startAP();
// STARTED
prntln(SETUP_STARTED);
// version
prntln(DEAUTHER_VERSION);
// setup LED
led.setup();
}
void loop() {
currentTime = millis();
led.update(); // update LED color
wifiUpdate(); // manage access point
attack.update(); // run attacks
displayUI.update();
cli.update(); // read and run serial input
scan.update(); // run scan
ssids.update(); // run random mode, if enabled
// auto-save
if (settings.getAutosaveSettings().enabled
&& (currentTime - autosaveTime > settings.getAutosaveSettings().time)) {
autosaveTime = currentTime;
names.save(false);
ssids.save(false);
settings.save(false);
}
if (!booted) {
booted = true;
EEPROMHelper::resetBootNum(BOOT_COUNTER_ADDR);
#ifdef HIGHLIGHT_LED
displayUI.setupLED();
#endif // ifdef HIGHLIGHT_LED
}
}

I was facing the similar reset loop problem, resolve after fall back to older board in Board Manager.
Repository: https://github.com/SpacehuhnTech/esp8266_deauther.git
Branch: v2
Commit: 501281c604adae3634bd46ed43abc615fc1246e5
Test 1. Board = esp8266 by ESP8266 Community version 2.7.4
-> Reset loop :-(
Test 2. Board = esp8266 by ESP8266 Community version 2.3.0
-> Works!

I got the similar error while i using esp8266 on the bread board and dispeard after i removed from the board, then i realised it might caused short circuit between the pin feet

Related

memory error: "conn.connect(server_addr, 3306, user, password)"

Recently I dived into making an Arduino project. I use Arduino IDE 2.0.3 and the board, LILYGO T-PICOC3.
When I tried to let my board connect to the MySQL server, I encountered an issue...
This is my sketch. I uploaded it to the board successfully
#include <WiFiEspAT.h>
#include <TFT_eSPI.h>
#include <SPI.h>
#include <Button2.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
//#include "MAX30105.h"
#include <Wire.h>
//#include "heartRate.h"
//#define I2C_SDA 12
//#define I2C_SCL 13
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(xxx, xxx, xx, xxx);
char user[] = "project" ;
char password[] = "1234";
WiFiClient client;
MySQL_Connection conn((Client *)&client);
char ssid[] = "Home3";
char pass[] = "12341234";
// max30102 setup ----
//MAX30105 particleSensor;
//long lastbeat;
// max30102 setup ----
void setup() {
Serial.begin(115200);
// power supply ----
pinMode(22, OUTPUT);
digitalWrite(22,HIGH);
// power supply ----
// esp32 setup ----
Serial2.setTX(8);
Serial2.setRX(9);
Serial2.begin(115200);
// esp32 setup ----
// max30102 segment ----
//if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false){
// Serial.println("MAX30102 was not found");
// while(true);
//}
//particleSensor.setup();
//particleSensor.setPulseAmplitudeRed(0x0A);
//Serial.print("max30102 is online!");
// max30102 segment ----
// WiFi start ----
WiFi.init(Serial2);
WiFi.begin(ssid, pass);
Serial.println("connecting to wifi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1600);
}
Serial.println("Connected to network");
pinMode(29, OUTPUT);
digitalWrite(29, HIGH);
IPAddress ip = WiFi.localIP();
Serial.print("My IP address is: ");
Serial.println(ip);
// WiFi start ----
// connect to database ----
Serial.println("Connecting to the database");
if (conn.connect(server_addr, 3306, user, password)){
delay(1000);
}
Serial.println("unSuccessfully connect!");
conn.close();
// connect to database ----
}
void loop() {
//long irvalue = particleSensor.getIR();
//if (checkForBeat(irvalue) == true){
// long delta = millis() - lastbeat;
// lastbeat = millis();
// float beatsperminute = 60 / (delta/1000.0);
//}
}
And I got the message from Output :
Sketch uses 340796 bytes (16%) of program storage space. Maximum is 2093056 bytes.
Global variables use 69008 bytes (26%) of dynamic memory, leaving 193136 bytes for local variables. Maximum is 262144 bytes.
Resetting COM5
Converting to uf2, output size: 714240, start address: 0x2000
Flashing G: (RPI-RP2)
Wrote 714240 bytes to G:/NEW.UF2
Everything seems fine so far... but as I check out the Serial Monitor, I receive a Memory error when the process reaches the code " conn.connect(server_addr, 3306, user, password) "
12:33:29.765 -> Connected to network
12:33:29.810 -> My IP address is: 192.168.0.159
12:33:29.810 -> Connecting to the database
12:33:29.810 -> ...trying...
12:33:31.116 -> Memory error.
12:33:32.481 -> Memory error.
12:33:32.481 -> Error: -1 = unSuccessfully connect!
I was originally trying to integrate the Max30102 module into my board, but after the error occurred, I uncommented the code associated with Max30102 and try it again. In the end, It turned out the same. In addition, I change the “server_addr” for the other MySQL server and restart Arduino IDE and nothing changed too. Perhaps the problem is derived from the hardware, the libraries, or the potentially incomplete uploading?

UART Interrupt problem while performing real-time image processing with camera by using opencv in c++ (I worked on Ubuntu 18.04, Linux Kernel 5x)

I write a code to process real time video by using camera. I can run this code within any error by itself but I want to implement a UART interrupt. Basically I aim that when I take a data from UART, other processes will be interrupted and after reading data, processes will be continue.
Here my UART interrupt implemented code.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <errno.h>
#include <termios.h>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void signal_handler_IO(int status);
VideoCapture vid("/dev/video0", CAP_V4L2);
int n;
int fd;
int connected;
struct termios termAttr;
struct sigaction saio;
const int fps = 20;
int main(int argc, char *argv[])
{
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
Mat frame;
if (fd == -1)
{
perror("open_port: Unable to open /dev/ttyO1\n");
exit(1);
}
saio.sa_handler = signal_handler_IO;
saio.sa_flags = 0;
saio.sa_restorer = NULL; //
sigaction(SIGIO,&saio,NULL);
fcntl(fd, F_SETFL, FNDELAY|FASYNC);
fcntl(fd, F_SETOWN, getpid());
tcgetattr(fd,&termAttr);
cfsetispeed(&termAttr,B9600);
cfsetospeed(&termAttr,B9600);
termAttr.c_cflag &= ~PARENB; // --> Parity Enable
termAttr.c_cflag &= ~CSTOPB; // -->two stop bit else one
termAttr.c_cflag &= ~CSIZE; // Character Size (C5, C6...)
termAttr.c_cflag |= CS8; // Charachter size 8 bit
termAttr.c_cflag |= (CLOCAL | CREAD);
//CLOCAL --> Ignore modem status lines. ¦ CREAD --> Enable receiver.
termAttr.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
termAttr.c_iflag &= ~(IXON | IXOFF | IXANY);
termAttr.c_oflag &= ~OPOST; // OPOST --> Post-process output
tcsetattr(fd, TCSANOW, &termAttr);
printf("UART1 configured....\n");
connected = 1;
if (!vid.isOpened())
{
return -1;
}
vid.set(CAP_PROP_FRAME_WIDTH, 1280);
vid.set(CAP_PROP_FRAME_HEIGHT, 720);
while (vid.read(frame))
{
imshow("webcam", frame);
if (waitKey(1000/fps) >= 0)
break;
}
destroyAllWindows();
vid.release();
close(fd);
exit(0);
}
void signal_handler_IO (int status)
{
printf("received data from UART.\n");
}
Now let's get to the main problem:
When I implement UART interrupt to this code, my captured video was stopped by the core (I takes Core Dumped Error). I guess that after process interrupted and when it will continue again, compiler is try to set again the video properties which I defined as
(vid.set(CAP_PROP_FRAME_WIDTH, 1280);)
(vid.set(CAP_PROP_FRAME_HEIGHT, 720);)
so I think I got such an error.
I think as I mentioned because when I deleted these size setting commands, code run very well with UART interrupt.
I try to define these commands globally but I cant do this. I take "vid does not name a type." error.
Thus, I can't solve this problem. I am not sure about why this problem occur and I don't know how it will be solved.
First, you cannot invoke printf(3) in a signal handler. Printf interacts with stdio, which in turn interacts with malloc(3); neither of these frameworks are signal safe. So, change your printf() to a write(2), which is safe.
That is unlikely to be your problem.
You didn't post the source to the implementation of vid, and in particular, how does vid.read deal with signals (ie EINTR)? Does it handle them correctly? Well? Perhaps return 0 if it is interrupted?
You will likely need to vet vid., so you should have a test candidate that gets a timer based signal over random intervals to gain confidence that it works.

L2CAP IOS + Linux (Bluez)

I'm trying to make a simple L2CAP Socket communication between IOS and a Linux PC.
I've been able to:
Create an L2CAP connection between two Linux machines (using example code from https://github.com/atwilc3000/sample/tree/master/Bluetooth)
Create an L2CAP connection between two Iphones (using example code from https://github.com/github-deden/iOS_L2Cap)
On that IOS example they are using some PSM advertise in order to chose the correct PSM for the L2CAP channel. On the integration, I've set a fixed PSM on both sides. The Iphone is connecting to the Linux machine fixed PSM. I've tried multiple PSM (0x1001, 0x25).
The problem is, I can't connect and can't get any information on what is happening on the air.
My question is, do I need to implement a dynamic/advertise PSM on the Linux application? Do I need to pick a specific PSM? Have you been able to make this work? Do you have any suggestions?
Thanks in advance!
Server code:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>
#include "l2cap_socket.h"
int main(int argc, char **argv)
{
struct sockaddr_l2 loc_addr = { 0 }, rem_addr = { 0 };
char buf[1024] = { 0 };
int server_socket, client_socket, bytes_read;
unsigned int opt = sizeof(rem_addr);
printf("Start Bluetooth L2CAP server...\n");
/* allocate socket */
server_socket = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
/* bind socket to the local bluetooth adapter */
loc_addr.l2_family = AF_BLUETOOTH; /* Addressing family, always AF_BLUETOOTH */
bacpy(&loc_addr.l2_bdaddr, BDADDR_ANY); /* Bluetooth address of local bluetooth adapter */
loc_addr.l2_psm = htobs(L2CAP_SERVER_PORT_NUM); /* port number of local bluetooth adapter */
printf("binding\n");
if(bind(server_socket, (struct sockaddr *)&loc_addr, sizeof(loc_addr)) < 0) {
perror("failed to bind");
exit(1);
}
printf("listening\n");
/* put socket into listening mode */
listen(server_socket, 1);
/* accept one connection */
client_socket = accept(server_socket, (struct sockaddr *)&rem_addr, &opt); /* return new socket for connection with a client */
ba2str( &rem_addr.l2_bdaddr, buf );
printf("connected from %s\n", buf);
/* read data from the client */
memset(buf, 0, sizeof(buf));
bytes_read = recv(client_socket, buf, sizeof(buf), 0);
if( bytes_read > 0 ) {
printf("received [%s]\n", buf);
}
/* close connection */
close(client_socket);
close(server_socket);
return 0;
}
Client is based on (from https://github.com/bluekitchen/CBL2CAPChannel-Demo).
I have now a working version based on https://github.com/bluekitchen/btstack
On the iOS side i have been using https://github.com/bluekitchen/CBL2CAPChannel-Demo
On the server side le_data_channel_server.

fatal error: ESP8266WiFi.h: No such file or directory

I'm trying to make a "home weight" with my ESP32 and display the value using IBMCloud, however I'm running into some issues with the Arduino IDE and my code.
I get this error:
Arduino:1.8.5 (Windows 10), Tarjeta:"ESP32 Dev Module, QIO, 80MHz, 4MB (32Mb), 921600, None"
C:\Users\XX\Documents\Arduino\IBM_Watson_Connect\IBM_Watson_Connect.ino:8:25: fatal error: ESP8266WiFi.h: No such file or directory
compilation terminated.
exit status 1
Compiling error for the ESP32 Dev Module card.
I'm using a ESP32 dev board. My code is this:
#include <ESP8266WiFi.h>
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/v2.3
#include "HX711.h" //Load Cell Amplifier
HX711 cell(D2, D4); //Amplifier is connected to these pins on the NodeMCU ESP8266 Board
#define WLAN_SSID "XXXXX"
#define WLAN_PASS "XXXXX"
#define ORG "XXXXX"
#define DEVICE_TYPE "XXXXXX"
#define DEVICE_ID "XXXXX"
#define TOKEN "XXXXXXXX"
char server[] = ORG ".messaging.internetofthings.ibmcloud.com";
char topic[] = "iot-2/evt/status/fmt/json";
char authMethod[] = "use-token-auth";
char token[] = TOKEN;
char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;
WiFiClient wifiClient;
PubSubClient client(server, 1883, NULL, wifiClient);
void setup() {
Serial.begin(115200);
Serial.println();
// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
}
int counter = 0;
void loop() {
if (!!!client.connected()) {
Serial.print("Reconnecting client to ");
Serial.println(server);
while (!!!client.connect(clientId, authMethod, token)) {
Serial.print(".");
delay(500);
}
Serial.println();
}
//----------Get data from load cell and amplifier
long valCalibrated = 0;
long val = 0;
float count = 0;
count = count + 1;
val = 0.5 * val + 0.5 * cell.read();
valCalibrated = (val - 4137240) / 234.20;
//----------Send data to IBM Waton IoT Service
String payload = "{\"d\":{\"weight\":";
payload += valCalibrated;
payload += "}}";
Serial.print("Sending payload: ");
Serial.println(payload);
if (client.publish(topic, (char*) payload.c_str())) {
Serial.println("Publish ok");
} else {
Serial.println("Publish failed");
}
++counter;
delay(100); //adjust delay to send more or less reads per unit time
}
Some places mentioned that the library was missing, that the board wasn't properly selected, the library wasn't updated.. I checked them all.. Arduino is updated, libraries are installed and updated, proper board is selected (I actually have tried all the other Esp32 related boards with the same result)
You're building a program for the ESP32, not the ESP8266. There are a lot of similarities but they're entirely different chips with different software.
So you don't use ESP8266WiFi.h with the ESP32. On the ESP32, the header file is just called WiFi.h (keeping more in line with WiFi support on Arduinos - the ESP32 Arduino Core is intended to be more compatible with the normal Arduino Core than the ESP8266 version was).
You need to
#include <WiFi.h>
instead of ESP8266WiFi.h
You can find the code for these files in the official repository for the Arduino SDK for the ESP32.
(It doesn't help that WiFi.h for the ESP32 identifies itself as ESP8266.h in its own comments...)

Can the Arduino's LiquidCrystal library interfere with the Wi-Fi library?

One day I was playing around with my Arduino and had a cool idea. Maybe I could do a wireless connection WITHOUT the serial monitor! I could use an LCD display instead! So, I went to work. I replaced all of the serial stuff with LCD stuff.
Finally I had no errors in my code (according to the Arduino client, that is).
Here is my code:
#include <LiquidCrystal.h>
#include <WiFi.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char ssid[] = "Fake Network"; // Your network SSID (name)
char key[] = "1"; // your network key
int keyIndex = 0; // Your network key Index number
int status = WL_IDLE_STATUS; // The Wi-Fi radio's status
void setup() {
lcd.begin(16, 2);
// Check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
lcd.println("WiFi shield not present");
// Don't continue:
while(true);
}
// Attempt to connect to Wi-Fi network:
while ( status != WL_CONNECTED) {
lcd.print("Attempting to connect to WEP network, SSID: ");
lcd.println(ssid);
status = WiFi.begin(ssid, keyIndex, key);
// Wait 10 seconds for connection:
delay(10000);
}
// Once you are connected:
lcd.print("You're connected to the network");
printCurrentNet();
printWifiData();
}
void loop() {
// Check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
}
void printWifiData() {
// Print your Wi-Fi shield's IP address:
IPAddress IPaddr = WiFi.localIP();
lcd.print("IP Address: ");
lcd.println(IPaddr);
lcd.println(IPaddr);
// Print your MAC address:
byte MACaddr[6];
WiFi.macAddress(MACaddr);
lcd.print("MAC address: ");
lcd.print(MACaddr[5],HEX);
lcd.print(":");
lcd.print(MACaddr[4],HEX);
lcd.print(":");
lcd.print(MACaddr[3],HEX);
lcd.print(":");
lcd.print(MACaddr[2],HEX);
lcd.print(":");
lcd.print(MACaddr[1],HEX);
lcd.print(":");
lcd.println(MACaddr[0],HEX);
}
void printCurrentNet() {
// Print the SSID of the network you're attached to:
lcd.print("SSID: ");
lcd.println(WiFi.SSID());
// Print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
lcd.print("BSSID: ");
lcd.print(bssid[5],HEX);
lcd.print(":");
lcd.print(bssid[4],HEX);
lcd.print(":");
lcd.print(bssid[3],HEX);
lcd.print(":");
lcd.print(bssid[2],HEX);
lcd.print(":");
lcd.print(bssid[1],HEX);
lcd.print(":");
lcd.println(bssid[0],HEX);
// Print the received signal strength:
long rssi = WiFi.RSSI();
lcd.print("signal strength (RSSI):");
lcd.println(rssi);
// Print the encryption type:
byte encryption = WiFi.encryptionType();
lcd.print("Encryption Type:");
lcd.println(encryption,HEX);
lcd.println();
}
And the result was....... Nothing. Nothing displayed.
Then I went and did my version of debugging. Note that I started at the bottom of the code.
lcd.print("bug");
I put this under every line of my code. Finally, I got to the top, under this line:
lcd.begin(16, 2);
AND GUESS WHAT! No display in any of the lines! I looked everywhere and I checked the display pins.
FINALLY, I found the problem!
It's a horrible bug that I can't get rid of! The display won't show with the WiFi.h library! I don't know why, But if I even #include <WiFi.h> into my program (or any program with the LiquidCrystal library... Things go exactly the same way!
What is the reason for this problem and how can I fix it? I haven't got any luck yet.
According to the documentation:
Arduino communicates with both the Wifi shield's processor and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On Uno 11 is MOSI, and 12 is MISO.
According to your code
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
you are using pins 11 and 12 for the LCD. Now if the LCD was using SPI, then the LCD could share pins 11 and 12 with the Wi-Fi shield, because the same set of pins used for SS (Slave Select) function would tell the peripherals which one of them should be listening. However, the LiquidCrystal library uses its first two argument pins for RS and Enable respectively, making it incompatible with SPI. The solution: move your LCD onto different pins.

Resources