Communicates with the WiFi - be very careful when using as it is tempremental.
Dependencies: mbed
Diff: initiateWifi.cpp
- Revision:
- 2:0b9ca0830cd3
- Parent:
- 1:cd1fe330bc2a
- Child:
- 3:b593f43b7251
--- a/initiateWifi.cpp Wed May 24 15:42:41 2017 +0000 +++ b/initiateWifi.cpp Wed May 24 16:17:04 2017 +0000 @@ -15,8 +15,43 @@ DigitalOut blueLED(LED3); //to prove it's working char input; //character to store inputs/outputs in communication +char* startCommands[10]= { + "AT", + "AT", + "AT", + "AT+RST", + "AT+CWMODE=1", + "AT+CWJAP=\"BTHub3-WXWX\",\"fdd6f7c682\"", + "AT+CIFSR", + "AT+CIPMUX=1", + "AT+CIPSERVER=1,8080", + "AT+CIPSEND=0," +}; +int numberOfCommands; + +int k = 0; //counter for comm numb + + +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 + + pc.printf("\r\ncommand %d",i); //identify the command number + 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 rstPin = 0; wait(2); @@ -39,15 +74,42 @@ while(pc.readable()) { c=pc.getc(); esp.putc(c); - //pc.putc(c); // echo back + + if(c==13) { - esp.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc + pc.printf("\r\ncommand %d",k); //identify the command number + pc.printf("\r\n"); + + esp.printf("%s\r\n",startCommands[k]); //send command + esp.putc(10); //send the command by pressing enter pc.putc(10); //ie makes enter perform as expected + + if (k <10) { k++;} else {k=0;} //reset k if required } } } +void sendCommand() { + char c; + while(pc.readable()) { + c=pc.getc(); + //pc.putc(c); // echo back + int k = 0; + if(c==13) { + + pc.printf("\r\ncommand %d",k); //identify the command number + pc.printf("\r\n"); + + esp.printf("%s\r\n",startCommands[k]); //send command + esp.putc(10); //send the command by pressing enter + pc.putc(10); //ie makes enter perform as expected + + if (k <10) { k ++;} else {k=0;} //reset k if required + } + } + +} -int initiateWifi() { +void initiateWifi() { //initialise the pins rstPin = 1; @@ -60,5 +122,7 @@ pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services esp.attach(&esp_recv, Serial::RxIrq); + //wait(10); + //start(); } \ No newline at end of file