esp8266 / esp8266/Arduino

Issue with AP password length in AP_STA mode

Open
#4,167 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

Please fill the info fields, it helps to get you faster support ;)

if you have a stack dump decode it:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst

for better debug messages:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst

----------------------------- Remove above -----------------------------

### Basic Infos

#### Hardware
Hardware: Wemos Mini D1
Core Version: 2.4.0

### Description

When the password length for the AP in AP_STA mode is more than 8 characters I am not
getting any answers from NTP

### Settings in IDE

Module: Wemos D1 R2 mini
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: ?OTA / SERIAL?
Reset Method: ?ck / nodemcu?

The sketch below is the standard NTP example sketch (adapted from Ethernet to WiFi).
I did not make any changes in the NTP part. My changes are only in the setup part
to adapt from Ethernet to WiFi. (original example is ethernet).

Step 0: Use IDE version **2.4.0** (Arduino 1.8.5)
Step 1: Look for the critical line in the code below (marked <=========)
Step 2: Try with a AP password that is less than 8 characters long
e.g. WiFi.softAP("TEST", "1234567");
Step 3: watch the NTP answers coming in every 11 seconds
Seconds since Jan 1 1900 = 3724996794
Unix time = 1516007994
The UTC time is 9:19:54
++++++++++++++++++++++++++++++++++++++++++
Step 4: No change the AP password to
e.g. WiFi.softAP("TEST", "12345678");
Step 5: watch that there are no NTP answers getting through
you only get:
++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++
Step 6: change the IDE version to **2.4.0-rc2**
Step 7: watch the NTP answers coming in every 11 seconds
Seconds since Jan 1 1900 = 3724996794
Unix time = 1516007994
The UTC time is 9:19:54
++++++++++++++++++++++++++++++++++++++++++

So the workaround is:

a) either stay on 2.4.0-rc2
or
b) use an AP password length of less than 8 characters
### Sketch

/*

Udp NTP Client

Get the time from a Network Time Protocol (NTP) time server
Demonstrates use of UDP sendPacket and ReceivePacket
For more on NTP time servers and the messages needed to communicate with them,
see http://en.wikipedia.org/wiki/Network_Time_Protocol

created 4 Sep 2010
by Michael Margolis
modified 9 Apr 2012
by Tom Igoe

This code is in the public domain.

*/

#include

#if defined (ARDUINO_ARCH_ESP8266)
extern "C" {
#include "user_interface.h"
}
#endif

#if defined (ARDUINO_ARCH_AVR)
#include
#endif

#include
#include

char my_ssid_0[] = "YOUR_SSID";
char my_password_0[] = "YOUR_STA_PASSWORD";
unsigned int localPort = 8888; // local port to listen for UDP packets
char timeServer[] = "ptbtime1.ptb.de"; // time.nist.gov NTP server
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
WiFiUDP UDPNTPClient;

void setup()
{
// Open serial communications and wait for port to open:
delay(1000);
Serial.begin(115200);
Serial.println(F("SETUP START"));

// WiFi.mode(WIFI_STA);
WiFi.mode(WIFI_AP_STA);
WiFi.begin(my_ssid_0, my_password_0);
while(WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.print(".");
delay(1000);
}

// WiFi.softAP("TEST", "TEST");
WiFi.softAP("TEST", "12345678"); // <======== critical line

UDPNTPClient.begin(localPort);
}

void loop()
{
sendNTPpacket(timeServer); // send an NTP packet to a time server

// wait to see if a reply is available
delay(1000);
if ( UDPNTPClient.parsePacket() ) {
// We've received a packet, read the data from it
UDPNTPClient.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer

//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print("Seconds since Jan 1 1900 = " );
Serial.println(secsSince1900);

// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.println(epoch);

// print the hour, minute and second:
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
Serial.print(':');
if ( ((epoch % 3600) / 60) < 10 ) {
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print('0');
}
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Serial.print(':');
if ( (epoch % 60) < 10 ) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0');
}
Serial.println(epoch % 60); // print the second
}

Serial.println(F("++++++++++++++++++++++++++++++++++++++++++"));

// wait ten seconds before asking for the time again
delay(10000);
}

// send an NTP request to the time server at the given address
unsigned long sendNTPpacket(char* address)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;

// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
UDPNTPClient.beginPacket(address, 123); //NTP requests are to port 123
UDPNTPClient.write(packetBuffer, NTP_PACKET_SIZE);
UDPNTPClient.endPacket();
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.