Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:f149c178dd58, committed 2018-06-27
- Comitter:
- nikitoslav
- Date:
- Wed Jun 27 10:33:32 2018 +0000
- Parent:
- 1:60fc2072f184
- Child:
- 3:24f12bc2b76d
- Commit message:
- 3
Changed in this revision
| ESP8266.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ESP8266.lib Wed Jun 27 07:17:23 2018 +0000 +++ b/ESP8266.lib Wed Jun 27 10:33:32 2018 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/nikitoslav/code/ESP8266/#af8bf1171171 +https://os.mbed.com/users/nikitoslav/code/ESP8266/#3518f7c570de
--- a/main.cpp Wed Jun 27 07:17:23 2018 +0000
+++ b/main.cpp Wed Jun 27 10:33:32 2018 +0000
@@ -2,21 +2,22 @@
#include <string>
#include "ESP8266.h"
-Serial console(USBTX,USBRX);
-ESP8266 wifi(PF_7,PF_6);
-
int localOutPort = 3001;
int localInPort = 3002;
+Serial console(USBTX,USBRX);
+ESP8266 wifi(PF_7,PF_6,localOutPort,localInPort);
+
const char* ap = "Clapeyron_Industries";
const char* passPhrase = "06737184";
Thread listeningThread;
void onReceive(void);
+void processReceivedData(string);
int main() {
- console.baud(9600);
+ console.baud(9600);
if (wifi.startup(1) && wifi.connect(ap,passPhrase))
console.printf("Your IP is: %s\n",wifi.getIPAddress());
else
@@ -26,18 +27,27 @@
}
void onReceive(void) {
+ const int maxSize = 100;
+
char buffer[100];
+ string buf = "";
char IP[16];
int port;
int bytes;
while(1) {
- bytes = wifi.recv(&buffer,100,IP,&port);
+ buf = "";
+ bytes = wifi.recv(&buffer,maxSize,IP,&port);
if (bytes != -1) {
console.printf("Bytes received: %d; from %s:%d\n",bytes,IP,port);
- console.printf("Data: ");
- for(int i = 0; i < bytes; i++)
- console.printf("%c",buffer[i]);
- console.printf("\n");
+ for(int i = 0; i < bytes; i++) {
+ buf += buffer[i];
+ }
+ console.printf("Data: %s\n",buf);
+ processReceivedData(buf);
}
}
+}
+
+void processReceivedData(string data) {
+
}
\ No newline at end of file