TCP proxy server that converts HTTPS Firebase RTDB SSE streams to plain TCP, bypassing SSL/TLS handshake issues with Airtel M2M SIM cards.
Airtel M2M SIM cards have SSL/TLS handshake issues with Firebase HTTPS endpoints. This proxy:
- Receives plain TCP connections from ESP32 (via EC200U modem)
- Connects to Firebase RTDB using HTTPS
- Streams data back over TCP using SSE format
ESP32 → EC200U 4G Modem → Railway Proxy (TCP) → Firebase RTDB (HTTPS)
-
Push to GitHub:
cd railway-proxy git add . git commit -m "Update server.js for relay control" git push origin main
-
Railway Auto-Deploy:
- Railway will automatically detect changes
- Build and deploy within 1-2 minutes
- Check logs in Railway dashboard
-
Verify Deployment:
curl http://yamabiko.proxy.rlwy.net:45343/test
Expected response:
✅ Firebase Railway Proxy Running! Server Time: 2025-11-16T... Firebase: relay-test1001-default-rtdb.asia-southeast1.firebasedatabase.app Usage: GET /relay/{DEVICE_ID}
GET /test
GET /
Response: Server status and info
GET /relay/{DEVICE_ID}
Response: SSE stream of relay state changes
Format: data: ON\n\n or data: OFF\n\n
# Health check
curl http://yamabiko.proxy.rlwy.net:45343/test
# Stream relay state for device
curl http://yamabiko.proxy.rlwy.net:45343/relay/dev_mhlj9n2msbwqu6bno- Flash
esp32-firmware/relay_control_railway_proxy.ino - Open Serial Monitor (115200 baud)
- Wait for connection confirmation
- Change relay state in Firebase:
- Path:
/devices/dev_mhlj9n2msbwqu6bno/relay - Value:
"ON"or"OFF"
- Path:
- ESP32 should respond within 1-2 seconds
{
"devices": {
"dev_mhlj9n2msbwqu6bno": {
"relay": "OFF",
"status": {
"lastSeen": 1700000000000,
"online": true
}
}
}
}PORT: Server port (auto-set by Railway)DEBUG: Enable debug logging (default: true)
FIREBASE_URL: Firebase RTDB URLTCP_HOST: Railway proxy hostnameTCP_PORT: Railway TCP port (45343)
Railway automatically captures logs. To view:
- Go to Railway dashboard
- Select your project
- Click on "Logs" tab
- See real-time server logs
Problem: ESP32 can't connect to proxy
Solutions:
- Check Railway proxy status (should show "Active")
- Verify Railway TCP port is 45343
- Check Airtel SIM has data connection
- Try health check:
curl http://yamabiko.proxy.rlwy.net:45343/test
Problem: Connected but no relay state updates
Solutions:
- Verify Firebase path:
/devices/{DEVICE_ID}/relay - Check Firebase rules allow read access
- Update relay value in Firebase console
- Check Railway logs for errors
Problem: Connection drops after few minutes
Solutions:
- Check keep-alive interval (default: 30s)
- Verify modem doesn't timeout TCP connections
- Check Railway server logs for disconnections
- Deploy Railway proxy
- Test relay ON/OFF via SSE
- Verify ESP32 connection
- Add schedule streaming endpoint
- Update ESP32 to handle schedules
- Test schedule execution
- Add bidirectional communication
- Stream power data to Firebase
- Display in Flutter app
MIT
- Relay Control Team