Communicates with the WiFi - be very careful when using as it is tempremental.

Dependencies:   mbed

Revision:
7:bfb2b5142c29
Parent:
6:99841ed0c8a8
Child:
8:e09edf050cca
--- a/initiateWifi.cpp	Thu May 25 12:12:09 2017 +0000
+++ b/initiateWifi.cpp	Thu May 25 12:12:58 2017 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "RawSerial.h"
 
-    //setup the other wifi pins
+//setup the other wifi pins
 DigitalOut rstPin (PTE29);
 DigitalOut chpdPin (PTE23);
 
@@ -10,7 +10,7 @@
 
 Serial pc(USBTX, USBRX, 115200);
 
-DigitalOut redLED(LED1); // twp leds  
+DigitalOut redLED(LED1); // twp leds
 DigitalOut greenLED(LED2); // to allow visual check of bidirectional comms
 DigitalOut blueLED(LED3);  //to prove it's working
 
@@ -33,30 +33,32 @@
 int k = 0; //counter for comm numb
 
 
-void start() {
+void start()
+{
     pc.printf("Initialising start sequence\r\n");
-    
+
     //numberOfCommands = sizeof(startCommands)/sizeof(startCommands[0]);
     numberOfCommands = 10;
-    
-    for (int i = 0; i<numberOfCommands; i++) { //replace the 9 with sizeOf start commands 
-        
+
+    for (int i = 0; i<numberOfCommands; i++) { //replace the 9 with sizeOf start commands
+
         pc.printf("\r\ncommand %d",i);  //identify the command number
-        pc.printf("\r\n");     
-        
+        pc.printf("\r\n");
+
         esp.printf("%s\r\n",startCommands[i]);    //send command
         esp.putc(10); //send the command by pressing enter
-        
-        
+
+
     }
 }
 
-void reset() {   //resets the module by turning rst off for 2 seconds then on again
+void reset()     //resets the module by turning rst off for 2 seconds then on again
+{
     rstPin = 0;
     wait(2);
     rstPin = 1;
     pc.printf("Reset complete\r\n");
-    
+
 }
 void esp_recv()
 {
@@ -73,33 +75,38 @@
     while(pc.readable()) {
         c=pc.getc();
         esp.putc(c);
-        
-        
+
+
         if(c==13) {
             pc.printf("\r\ncommand %d",k);  //identify the command number
-            pc.printf("\r\n");     
-            
+            pc.printf("\r\n");
+
             esp.printf("%s\r\n",startCommands[k]);    //send command
             pc.putc(10); //ie makes enter perform as expected
-            
-            if (k <10) { k++;} else {k=0;} //reset k if required
+
+            if (k <10) {
+                k++;   //reset k if required
+            } else {
+                k=0;
+            }
         }
     }
 }
 
-void initiateWifi() {
-    
+void initiateWifi()
+{
+
     //initialise the pins
     rstPin = 1;
     chpdPin = 1;
-    
+
     reset();    //perform an initial reset
-    
+
     blueLED = 1; //turn on test light
 
     pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services
     esp.attach(&esp_recv, Serial::RxIrq);
-    
+
     //wait(10);
     //start();