diff --git a/examples/ESP8266_RTOS/user/Makefile b/examples/ESP8266_RTOS/user/Makefile
index d4006b1a2c656ae2051a2978e709bcc1e386a413..56ca9321325af6a6fd991861c793631834095f20 100644
--- a/examples/ESP8266_RTOS/user/Makefile
+++ b/examples/ESP8266_RTOS/user/Makefile
@@ -23,9 +23,7 @@ endif
 #   makefile at its root level - these are then overridden
 #   for a subtree within the makefile rooted therein
 #
-DEFINES += -DCS_PLATFORM=3 \
-           -DRTOS_SDK \
-           -DMG_INTERNAL=
+DEFINES +=
 
 #############################################################
 # Recursion Magic - Don't touch this!!
diff --git a/mongoose.h b/mongoose.h
index fa596d2efc86d81c99121d8fb0af0f5cc8d831bd..af56f135522d8d59d90de3c34e0d9e40f1ffd385 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -77,6 +77,8 @@
 #define CS_PLATFORM CS_P_NXP_KINETIS
 #elif defined(PIC32)
 #define CS_PLATFORM CS_P_PIC32_HARMONY
+#elif defined(ICACHE_FLASH)
+#define CS_PLATFORM CS_P_ESP8266
 #endif
 
 #ifndef CS_PLATFORM
@@ -465,14 +467,17 @@ typedef struct stat cs_stat_t;
 
 #define MG_LWIP 1
 
-#ifdef RTOS_SDK
+/* struct timeval is defined in sys/time.h. */
+#define LWIP_TIMEVAL_PRIVATE 0
+
+#ifndef MG_NET_IF
+#include <lwip/opt.h>
+#if LWIP_SOCKET /* RTOS SDK has LWIP sockets */
 #  define MG_NET_IF MG_NET_IF_SOCKET
 #else
 #  define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
 #endif
-
-/* struct timeval is defined in sys/time.h. */
-#define LWIP_TIMEVAL_PRIVATE 0
+#endif
 
 #ifndef CS_ENABLE_STDIO
 #define CS_ENABLE_STDIO 1