Session Expired Too Fast
Your OceanRemote device disconnects frequently with "session expired" messages. The device goes offline every 60 minutes or less. This guide covers session timeout configuration, auto-refresh failures, token issues, and network problems that cause premature session expiration.
Last updated: April 22, 2026 | 8 min read
Symptoms
- Device goes offline every 60 minutes
- Serial Monitor shows "session expired" or "401 Unauthorized" messages
- Device reconnects automatically but takes 30-60 seconds
- Dashboard shows "Away" status more often than "Online"
- Manual session renewal works but auto-renewal fails
- Device works fine for exactly one hour then disconnects
Common Causes
- Session Auto-Refresh Failure Device firmware not renewing session before 60-minute expiry
- Network Interruption During Renewal WiFi drop at the exact moment of session refresh
- Token Invalid or Expired Permanent token corrupted or revoked, preventing new session
- Clock Skew Device time differs from server time by more than 5 minutes
- Firewall Blocking Renewal Requests Network blocks specific API endpoints
- Firmware Version Incompatibility Old firmware without proper session renewal logic
OceanRemote Session Parameters
| Parameter | Default Value | Notes |
|---|---|---|
| Session Duration | 60 minutes | Fixed by server configuration |
| Auto-Refresh Interval | 45 minutes | Device renews before expiry |
| Session Entropy | 128 bits | 2 possible session IDs |
| Renewal Endpoint | /api/device/<id>/renew-session/ |
Manual renewal available |
Step-by-Step Fixes
1. Check Firmware Version
Ensure your device is running firmware v5.0 or newer :
// Open Serial Monitor at 115200 baud
// Look for this line at boot:
// "# OceanicRemote v5.0 - ESP32"
//
// Version 5.0+ has auto session renewal
// Version 4.x and older require manual renewal
// If using older firmware, regenerate from OceanRemote dashboard
2. Verify Session Renewal in Serial Monitor
Watch for session renewal messages during normal operation:
// Normal session behavior :
// [UPDATE] Using session: a1b2c3d4e5f6g7h8
// [UPDATE] Sending temperature: 22.4C
// ...
//
// If you see this, session renewal failed:
// [UPDATE] Session invalid - attempting to recover with token
// [UPDATE] Failed to renew session. Will re-register.
//
// This indicates network or token issue during renewal
3. Manually Renew Session from Dashboard
Force session renewal to test if auto-renewal is the problem:
- Log into OceanRemote dashboard
- Go to Device Details page
- Click "Renew Session" button
- Watch Serial Monitor for renewal confirmation
- If manual renewal works but auto fails firmware issue
- If both fail network or token issue
4. Check Device Time Synchronization
Session validation requires accurate device time:
// Add time sync check to your firmware
#include
void printTime() {
time_t now = time;
Serial.print;
Serial.println);
}
// Compare with actual time
// If difference > 5 minutes, session validation may fail
// OceanRemote firmware includes NTP time sync automatically
5. Check Token Status
Invalid token prevents new session creation:
- Go to Device Details page in dashboard
- Check token status
- If token shows "Invalid" or "Expired", click "Regenerate Token"
- Flash new firmware with regenerated token
- Test session renewal after token update
6. Add Session Renewal Debugging
Monitor renewal attempts with additional logging:
// Add to your firmware
unsigned long lastRenewalAttempt = 0;
const unsigned long RENEWAL_INTERVAL = 2700000; // 45 minutes
void checkSessionRenewal() {
unsigned long now = millis();
if {
lastRenewalAttempt = now;
Serial.println;
// Your renewal code here
if ) {
Serial.println;
} else {
Serial.println;
}
}
}
7. Check Network Stability
Session renewal requires stable internet during the renewal window:
- Monitor WiFi RSSI should be above -70 dBm
- Check for network interruptions around the 45-minute mark
- Test ping stability:
ping -t www.oceanremote.netfor 1 hour - If packet loss > 5%, improve WiFi signal or use Ethernet
- Consider static IP to avoid DHCP renewal conflicts
Session Error Codes
| HTTP Code | Meaning | Solution |
|---|---|---|
| 200 | Session valid | Normal operation |
| 401 | Session expired / Invalid token | Renew session or regenerate token |
| 404 | Device not found | Check device ID, re-register if needed |
| 429 | Too many requests | Reduce polling frequency |
Prevention Tips
- Keep device firmware updated to latest version
- Ensure stable WiFi connection with RSSI above -70 dBm
- Monitor device logs for "session invalid" warnings
- Regenerate tokens every 90 days for security and reliability
- Use static IP address to avoid DHCP renewal conflicts
- Add watchdog timer to restart device if session renewal fails repeatedly
Related Issues
- Token Invalid or Expired Permanent token issues
- Device Offline in Dashboard Connection problems
- Firmware Flash Success But No Connection Registration issues
- ESP32 Not Connecting to WiFi Network stability
Frequently Asked Questions
Q: Why does my device disconnect exactly every 60 minutes?
A: OceanRemote sessions are hard-coded to expire after 60 minutes for security. The device should auto-renew at 45 minutes. If it disconnects at 60 minutes, the auto-renewal failed. Check WiFi stability and token validity.
Q: Can I increase the session timeout duration?
A: Not currently. The 60-minute timeout is fixed for security. This limits exposure if a session ID is intercepted. Auto-renewal happens at 45 minutes, so devices stay connected with no user action required.
Q: My device reconnects but loses relay state. Why?
A: When session expires, the device re-registers and creates a new session. Relay states are not preserved across session loss. The device defaults to OFF for all relays. To prevent this, ensure stable auto-renewal or use offline backup mode .
Still having session issues? Contact Support or return to the Troubleshooting Hub.