Nucleo STM32 F401RE , NodeMCU and TCP Conneciton

Dependencies:   BufferedSerial mbed-rtos mbed

Fork of NucleoF401_ESP8622 by Veysel KARADAG

Connection SCHEMA

/media/uploads/veyselka/schema.jpg

SOCKET DATA

/media/uploads/veyselka/portpeeker.jpg

DETAIL DESCRIPTION

http://veyselkaradag.blogspot.com.tr/

Revision:
1:4a50b910342c
Parent:
0:515a38e245a4
Child:
3:8049d7fb27b7
--- a/main.cpp	Tue Jan 13 15:48:44 2015 +0000
+++ b/main.cpp	Wed Feb 18 13:41:07 2015 +0000
@@ -4,148 +4,162 @@
 ** any purpose.
 **
 ** main.ccp
-** Quectel M95 GPRS module with STM32F401RE Nucleo Board
-**
-** Author: <veyselka@hotmail.com>
+** NodeMCU module with STM32F401RE Nucleo Board
+** Author: <veyselka@hotmail.com> <v.karadag@gmail.com> Veysel KARADAG
+** USB PC for systemout
+** NodeMCU is Connected to PA9 , PA10
+** PA_6 is Output for RESET NODEMCU
+** Thanks sam grove for Buffered Serial Lib.
+** USER button is using Interrupt and Toggle LED1 ( For TESTING INTERRUPT ISSUE )
 ** -------------------------------------------------------------------------*/
 
 
 #include "mbed.h"
 #include "rtos.h"
-#include "ID_STM32F4.h"
-#include "modem.h"
+#include "BufferedSerial.h"
+#include "esp8622.h"
+#include "wifi.h"
+
+ 
+
+  
+
+BufferedSerial pc(USBTX, USBRX);
+
+InterruptIn button(USER_BUTTON);
+DigitalOut myled(LED1);
+DigitalOut wifiRST(PA_6);
 
 
 
-//------------------------------------
-// Hyperterminal configuration
-// 9600 bauds, 8-bit data, no parity
-//------------------------------------
-
-   
-Serial pc(USBTX, USBRX);
-
-Modem com(PA_9, PA_10);
-
+void WIFI(void const *args);
+void SYSTEM(void const *args);
+void button_pressed(void);
 
 
 
 
-InterruptIn button(USER_BUTTON);
-DigitalOut myled(LED1);
-
-int sms_flag;
-
-void GSM(void const *args);
-void GPS(void const *args);
-void SERIAL(void const *args);
-void button_pressed(void);
-
-char command_buffer[255];
-
 int main()
 {
     button.fall(&button_pressed);
     pc.baud(115200);
-    com.baud(115200);
 
-
-
- 
-    Thread GSM_THREAD(GSM);
-    Thread GPS_THREAD(GPS);
-    Thread SERIAL_THREAD(SERIAL);
+    Thread WIFI_THREAD(WIFI);
+    Thread SYSTEM_THREAD(SYSTEM);
+    
+    printf("NODEMCU AT COMMAND TEST APP\r\n");
     
     while(1);
 
-}
-
 
 
-void GSM(void const *args) {
-  
-     sms_flag=0;
-     com.printf("ATE1\r\n");
-     Thread::wait(100);
+}
+
+void WIFI(void const *args) {
+ 
+    int attest=0;
+    int taskcnt=0;
+    
+    char my_ip[32];
+    char st_ip[32];
+    
+    char data[32];
+    
      
-     while(true) {
-        myled=!myled;
         
+    // WIFI MODUL RESTART// 
+    
+    Thread::wait(1000);
+    wifiRST = 0;
+    Thread::wait(1000);
+    wifiRST = 1;
+   
+    while(true) {
+      
+    // Read a line from the large rx buffer from rx interrupt routine
         
+        while(attest==0){
+            
+            Thread::wait(1000);
+            attest=at_TEST();
+            printf("AT TEST:%d\r\n",attest);
+            Echo_OFF();
+            printf("ECHO OFFd\r\n");
+        }
         
-      com.printf("AT+GSN\r\n");
-      Thread::wait(100);
-      memset(command_buffer,0,128); 
-      com.read_buf(command_buffer,128);
-      pc.printf("Command ANs:%s:\r\n",command_buffer);
-        
-      if(sms_flag==1){
+        while(1){
+            
+            Thread::wait(1000);
+            connectRouter("veysel","12345678"); 
+            Thread::wait(6000);
+            
+            read_ip(my_ip,st_ip);
+            printf("MY IP:%s\r\n",my_ip);
+            printf("ST IP:%s\r\n",st_ip);
+            
+            int datacnt=0;
+            
+            Thread::wait(1000);
+            while(1){
+                
+                read_ip(my_ip,st_ip);
+                printf("MY IP:%s\r\n",my_ip);
+                printf("ST IP:%s\r\n",st_ip);
+               
+                if( strlen(my_ip)>6  && strlen(my_ip)>6 ){
+                    
+                
+                    
+                    sprintf(data,"Hello World %d\r\n",datacnt++);
+                    
+                    if( send_SOC_DATA("192.168.1.1",28800,data)==1){   // USE YOUR SERVER and IP
+                        
+                        printf("DATA SENDED\r\n");
+                            
+                    }else{
+                        
+                        printf("DATA SEND ERROR\r\n");
+                    }
     
-        com.printf("AT+CMGF=1\r\n");
-        Thread::wait(250);
-        com.printf("AT+CMGS=\"+905355948809\"\r\n");
-        Thread::wait(1000);
-        com.puts("Hello WORLD");
-        Thread::wait(250);
-        com.putc((char)0x1a);
-          Thread::wait(1000);
-        
-        sms_flag=0;
-    
-      }  
-        Thread::wait(1000);
+                }
+                
+                
+                
+                Thread::wait(1000);
+            }
+                
+         
+                   
+                
+        }
+
+
+        printf("Round:%d\r\n",taskcnt++);
+      
+
+       
     }
 }
 
 
-void GPS(void const *args) {
-
-
- 
-    while(true) {
-        
-    // Read a line from the large rx buffer from rx interrupt routine
-
-       Thread::wait(500);
-    }
-}
+void SYSTEM(void const *args) {
 
 
-void SERIAL(void const *args) {
-
-    int count=0;
-    int ID=0;
-    uint8_t uID[12];
-    
-    ID= TM_ID_GetSignature() ;
-    
-    printf("ID:%X:\r\n",ID);
-    
+    while(true) {
     
-    printf("uID:");
-    for(count=0;count<12;count++){
-        uID[count]=TM_ID_GetUnique8(count);    
-        printf("0x%02X ",uID[count]);
+        Thread::wait(1000); 
         
     }
-    printf("\r\n");
-    count=0;
-    
-    
-    
-
-    while(true) {
-
-  
-      Thread::wait(1000);  
-    }
 }
 
 
 
 void button_pressed()
 {
-      sms_flag=1;
-    
-    
+ 
+
+    printf("Button Pressed\r\n");
+    myled = !myled;
+    wifiRST = !wifiRST;
 }
+