wifi testing

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
himanshukaushik
Date:
Tue Mar 16 09:31:32 2021 +0000
Commit message:
wifi testing on march 16

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r eec7d62631de main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 16 09:31:32 2021 +0000
@@ -0,0 +1,89 @@
+#include "mbed.h"
+Serial pc(USBTX, USBRX);
+Serial esp(p9, p10); // tx, rx
+Timer t;
+char buf[1024];
+char snd[255];
+int  count;
+int timeout,ended;
+char ssid[32] = "Chaitanya1";     // enter WiFi router ssid inside the quotes
+char pwd [40] = "9632964359"; // enter WiFi router password inside the quotes
+void SendCMD(),getreply();
+
+int main() {
+    pc.baud(9600);
+    esp.baud(9600);
+    
+    strcpy(snd,"AT\r\n");
+    SendCMD();
+    timeout=1;
+    getreply();
+    pc.printf(buf);
+    pc.printf("\n---------- Setting Mode ----------\r\n");
+    strcpy(snd, "AT+CWMODE=3\r\n");
+    SendCMD();
+    timeout=3;
+    getreply();
+    pc.printf(buf);
+
+    wait(2);
+     pc.printf("\n---------- Listing Access Points ----------\r\n");
+    strcpy(snd, "AT+CWLAP\r\n");
+    SendCMD();
+    timeout=3;
+    getreply();
+    pc.printf(buf);
+    wait(2);
+
+    pc.printf("\n---------- Connecting to AP ----------\r\n");
+    pc.printf("ssid = %s   pwd = %s\r\n",ssid,pwd);
+    strcpy(snd, "AT+CWJAP=\"");
+    strcat(snd, ssid);
+    strcat(snd, "\",\"");
+    strcat(snd, pwd);
+    strcat(snd, "\"\r\n");
+    SendCMD();
+    timeout=3;
+    getreply();
+    pc.printf(buf);
+wait(5);
+pc.printf("\n---------- Get IP's ----------\r\n");
+    strcpy(snd, "AT+CIFSR\r\n");
+    SendCMD();
+    timeout=10;
+    getreply();
+    pc.printf(buf);
+    wait(1);
+
+    pc.printf("\n---------- Get Connection Status ----------\r\n");
+    strcpy(snd, "AT+CIPSTATUS\r\n");
+    SendCMD();
+    timeout=5;
+    getreply();
+    pc.printf(buf);
+    
+}
+void SendCMD()
+{
+    esp.printf("%s", snd);
+}
+void getreply()
+{ 
+    memset(buf, '\0', sizeof(buf));
+    t.start();
+    ended=0;
+    count=0;
+    while(!ended) {
+        if(esp.readable()) {
+            buf[count] = esp.getc();
+            count++;
+        }
+        
+        
+        if(t.read() > timeout) {
+            ended = 1;
+            t.stop();
+            t.reset();
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r eec7d62631de mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 16 09:31:32 2021 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c
\ No newline at end of file