Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By xtal
#96420 WEMOS R1 D1 as socket server station mode aok ... When changing to AP mode , I have no internet connection.
I cannot seem to find any way to get the time of day without internet connection .
This is an IRRIGATION socket server 6 relay 4-real 2 virtual 95 % done in station mode.
Four users can control then displayed webpage. It is very stable thus far..

1> How can I get internet connection when in AP mode, did I do something wrong?
2> How can I get time of day without internet connection?

3> I managed to get time from client after connecting but can't set my clock.
I'm using struct tm *timeinfo time_t tnow = time(nullptr) , I apparently don't know how to set it.
using this may require connect, disconnect, then again connect, I'm sure its not the best way.
I would prefer INET connection while in access point mode.
User avatar
By rooppoorali
#96424 When you switch the WEMOS R1 D1 to AP mode, it acts as a standalone Access Point and does not connect to the Internet. To provide internet connectivity, you will need to connect the WEMOS R1 D1 to a WiFi network that has Internet connectivity. You can do this by configuring the WEMOS R1 D1 to connect to your home or office WiFi network using the WiFiManager library or a similar library. Once you have connected the WEMOS R1 D1 to the WiFi network, you should have internet connectivity.

You can get the time of day without an Internet connection by using an RTC (Real-Time Clock) module. The RTC module keeps track of time using an internal clock and battery backup, and can be used to provide accurate timekeeping even when there is no Internet connectivity. You can interface the RTC module with the WEMOS R1 D1 using the I2C interface and use a library like RTClib or a similar library to read the time from the RTC module.

To set the clock on the WEMOS R1 D1, you can use the settimeofday function from the time.h library. This function takes a struct timeval argument that contains the current time in seconds and microseconds. You can obtain the current time using the time function, and then convert it to a struct timeval using the gmtime and mktime functions. Here's some sample code that demonstrates how to set the clock on the WEMOS R1 D1:

Code: Select all#include <time.h>

// obtain the current time
time_t now = time(nullptr);

// convert to a struct tm
struct tm* timeinfo = gmtime(&now);

// set the time to 12:00:00
timeinfo->tm_hour = 12;
timeinfo->tm_min = 0;
timeinfo->tm_sec = 0;

// convert back to a time_t
now = mktime(timeinfo);

// set the system clock
struct timeval tv;
tv.tv_sec = now;
tv.tv_usec = 0;
settimeofday(&tv, nullptr);