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.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
Revision 16:65193d8d29e6, committed 2014-12-09
- Comitter:
- emuboy
- Date:
- Tue Dec 09 16:34:21 2014 +0000
- Parent:
- 15:69e41cbbc8ac
- Commit message:
- Just a small example how to use the pushover.net service and generally POST in mbed.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Sep 21 05:55:13 2014 +0000
+++ b/main.cpp Tue Dec 09 16:34:21 2014 +0000
@@ -1,17 +1,53 @@
#include "mbed.h"
#include "EthernetInterface.h"
-int main() {
+
+/*
+ By Andrea Campanella
+ Just a small example how to use pushover.net
+ with mbed and generally ho to use POST in mbed.
+*/
+
+
+int main()
+{
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
-
+ // Pushover settings
+ char pushoversite[] = "api.pushover.net";
+ char apitoken[] = "APIKEY";
+ char userkey [] = "USERKEY";
+ char message [] = "Hello mate";
TCPSocketConnection sock;
- sock.connect("mbed.org", 80);
-
- char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
+ sock.connect(pushoversite, 80);
+
+ char http_cmd[300] = "POST /1/messages.json HTTP/1.1\r\n" ;
+ char length[10];
+ sprintf(length, "%d", 113 + sizeof(message)-1);
+
+ //strcat( http_cmd , "POST /1/messages.json HTTP/1.1" );
+ strcat( http_cmd , "Host: api.pushover.net\r\n");
+ strcat( http_cmd , "Connection: close\r\n ");
+ strcat( http_cmd , "Content-Type: application/x-www-form-urlencoded\r\n");
+ strcat( http_cmd , "Content-Length: ");
+ strcat( http_cmd , length);
+ strcat( http_cmd , "\r\n\r\n");;
+ strcat( http_cmd , "token=");
+ strcat( http_cmd , apitoken);
+ strcat( http_cmd , "&user=");
+ strcat( http_cmd , userkey);
+ strcat( http_cmd , "&message=");
+ strcat( http_cmd , message);
+ strcat( http_cmd , "&priority=");
+ strcat( http_cmd , "0");
+ strcat( http_cmd , "&retry=60");
+ strcat( http_cmd , "&expire=3600");
+ printf("Sending :%s\n", http_cmd);
+
sock.send_all(http_cmd, sizeof(http_cmd)-1);
+
char buffer[300];
int ret;
@@ -22,10 +58,10 @@
buffer[ret] = '\0';
printf("Received %d chars from server:\n%s\n", ret, buffer);
}
-
+
sock.close();
-
+
eth.disconnect();
-
+
while(1) {}
}
