mbed project

Dependencies:   ESP8266NodeMCUInterface Pubnub_mbed2_sync mbed

Revision:
0:2730fbdae986
Child:
1:694056dc14d9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 11 20:37:05 2017 +0000
@@ -0,0 +1,71 @@
+#include "pubnub_sync.h"
+#include "mbed.h"
+#include "ESP8266Interface.h"
+#include "TCPSocket.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1);
+ESP8266Interface esp(p28, p27, p19, 9600, 3000);
+
+char ssid[] = "New England Clam Router";
+char pwd[] = "gettincutgettinbutt";
+const char pubkey[] = "pub-c-f9091d93-c3a8-41a6-80c2-c6e3f840504f";
+const char subkey[] = "sub-c-f558e36c-130b-11e7-b59a-02ee2ddab7fe";
+const char channel[] = "demo";
+int port = 80;
+char host[] = "pubsub.pubnub.com";
+char message[] = "/publish/pub-c-f9091d93-c3a8-41a6-80c2-c6e3f840504f/sub-c-f558e36c-130b-11e7-b59a-02ee2ddab7fe/0/demo/0/%%7B%%22text%%22%%3A%%22heymbed%%22%%7D";
+char sendbuf[180];
+char recvbuf[180];
+//ubNub pn(pubkey, subkey);
+
+int main() {
+
+
+    char buf[] = "hello world! please work";
+    
+    bool success = esp.init();
+    if (success) pc.printf("Successful init\r\n");
+    else pc.printf("Initialize Fail\r\n");
+    bool connection = esp.connect(ssid, pwd);
+    if (connection) pc.printf("Successful connection\r\n");
+    else pc.printf("Connection Fail\r\n");
+    const char *ip = esp.getIPAddress();
+    if (ip) pc.printf("IP Address: %s\r\n", ip);
+    
+    //pc.printf("publishing\r\n");
+    /*
+    TCPSocket sock;
+    sock.open(&esp);
+    sock.connect(host, 80);
+    if(sock.is_connected()) pc.printf("connection w/ google is good");
+    
+    strncpy(sendbuf, message, 180);
+    pc.printf(message);
+    pc.printf("\n");
+    sock.send_all(message, sizeof(message));
+    sock.receive_all(recvbuf, 180);
+    
+    pc.printf(recvbuf);
+    */
+    
+    // set up context
+    pubnub_t* ctx = pubnub_alloc();
+    if (ctx == NULL)
+        pc.printf("FUCKING CTX IS NULL");
+    // initialize pubnub api
+    pubnub_init(ctx, pubkey, subkey);
+
+    pubnub_publish(ctx, channel, "hello world from the mbed");
+    int pbresult = pubnub_await(ctx);
+    if (PNR_OK == pbresult) {
+        pc.printf("published! hell yes!");
+        /* Published successfully */
+    } else {
+        pc.printf("pubnub err: %d\r\n", pbresult);
+    } 
+
+    pubnub_free(ctx);
+    while (1) {};
+    return 0;
+}
\ No newline at end of file