This is made by seminal03_SIT_mechanical_engineering. This quotes ban4jp"CyaSSL_Twitter-OAuth4Tw".

Dependencies:   EthernetInterface HTTPClient-wolfSSL NTPClient OAuth4Tw mbed-rtos mbed wolfSSL

Fork of CyaSSL-Twitter-OAuth4Tw by ban4jp -

Files at this revision

API Documentation at this revision

Comitter:
mbed2015
Date:
Thu Feb 04 01:50:30 2016 +0000
Parent:
6:f5189d4f109f
Commit message:
?????????????????????????????????????????????????????????????????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f5189d4f109f -r 48019055e3a3 main.cpp
--- a/main.cpp	Sat Jul 18 16:23:11 2015 +0000
+++ b/main.cpp	Thu Feb 04 01:50:30 2016 +0000
@@ -1,18 +1,24 @@
+// Original: https://developer.mbed.org/users/ban4jp/code/CyaSSL-Twitter-OAuth4Tw/
+
 #include <string.h>
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "NTPClient.h"
 #include "OAuth4Tw.h"
+#include "lwip/dns.h"
+
 
 Serial pc(USBTX, USBRX);
 DigitalOut myled(LED1);
 EthernetInterface eth;
 NTPClient ntp;
 
-OAuth4Tw oa4t("XXXXXXXXXXXXXXXXXXXXXXXXX",                          // Consumer key
-              "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // Consumer secret
-              "000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Access token
-              "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");     // Access token secret
+OAuth4Tw oa4t("f3fcA4S61FcOz0VMLgia9ewn2",// Consumer key
+              "Djaz2ooEf95b8yr3yE7DWS1XrYuwjBYZdz7QqnDKFTKNdMd8Ml", // Consumer secret
+              "4044135739-da2aYe6fs6aCcpCKlqagVxM3rjDj5yPUaJaZ7O7", // Access token
+              "uIrtt88FWWIz2yqpU9AkBeoLEHW5ls5ZdA9SoQvcGY47c");// Access token secret
+
+
 
 #if defined(TARGET_LPC1768)
 #define RESPONSE_BUFFER_SIZE 512
@@ -31,13 +37,22 @@
 void example_tweet2();
 void example_tweet3();
 void example_getUserData();
+void mm2(void);
+
+Ticker mmTicker;
+volatile int sum = 0;    
 
 int main()
 {
     pc.baud(115200);
 
-    eth.init(); //Use DHCP
-    printf("Initialized, MAC: %s\n", eth.getMACAddress());
+    eth.init();
+    // eth.init("172.20.29.40","255.255.255.0","172.20.29.1");
+    // printf("Initialized, MAC: %s\n", eth.getMACAddress());
+
+    // ip_addr_t primaryDnsServer;
+    // ip4_addr_set_u32(&primaryDnsServer, ipaddr_addr("202.18.66.8")); 
+    // dns_setserver(0, &primaryDnsServer);
 
     int ret;
     while ((ret = eth.connect()) != 0) {
@@ -50,24 +65,43 @@
     // requires accurate time, for OAuth Authorization.
     updateTime();
 
-    while (1) {
 
-        example_tweet1();
-        //example_tweet2();
-        //example_tweet3();
+//    example_getUserData();
+//        printf("\n");
+    
+    myled = 0;
+    time_t ctTime;
+        struct tm* lTime;
+        int hour;
+        int countmin = 0;
 
-        example_getUserData();
+    
+/*tickerオブジェクトで0.1秒ごとにmm2関数を呼び出す*/
+    mmTicker.attach(&mm2, 0.5);     
 
-        // Wait 60 seconds for next time.
-        for (int t=0; t<60; t++) {
-            myled = 1;
-            wait(0.2);
-            myled = 0;
-            wait(0.8);
+    while (1) {
+        time(&ctTime);
+        lTime = localtime(&ctTime);
+        hour = lTime->tm_hour;
+        countmin = 5;
+        if (12<=hour&&hour<=13) {
+         countmin=15;
+         }
+    
+
+        // Wait 60*5 seconds for next time.
+        for (int t=0; t<60*countmin; t++) {
+            myled = !myled;
+            wait_ms(1000);
+            printf("%d\n", sum);            
+            //time(&ctTime);
+            //lTime = localtime(&ctTime);
+            //hour = lTime->tm_hour;
+            //if (12<=hour&&hour<=13) break;
         }
-
-        printf("\n");
+        example_tweet2();
     }
+    // mmTicker.detach();
 }
 
 
@@ -79,8 +113,7 @@
     NTPResult result;
 
     while (1) {
-        result = ntp.setTime("pool.ntp.org");
-        //result = ntp.setTime("pool.ntp.org", NTP_DEFAULT_PORT, 2000);
+        result = ntp.setTime("ntp.nict.jp");
 
         if (result == NTP_OK) {
             time(&ctTime);
@@ -111,13 +144,110 @@
 }
 
 
+
+/*センサ安定時間*/
+#define INIT 30.0
+/*ノイズ検出用*/
+#define NOISE 0.1
+/*センサ再読み取り時間*/
+#define DELAY 0.05
+
+DigitalIn pA(p19);
+DigitalIn pB(p20);
+DigitalOut led2(LED2);
+
+void mm2(void)
+{
+    int nA = pA;
+    int nB = pB;
+    static int prevA = 0;
+    static int prevB = 0;
+    
+    int status = 0;
+    static int prevUpStatus = 0;
+
+    if (prevA == nA)
+        status = nA;
+    if (prevB == nB)
+        status |= (nB << 1);
+    if (prevUpStatus == 0x03) {
+        if (status == 0x02)
+            sum++;
+        else if (status == 0x01)
+            sum--;
+    }
+        
+    prevA = nA;
+    prevB = nB;
+
+    if (status)
+        prevUpStatus = status;
+}
+
+
+void mm(void) {
+    int a = 0;
+    int b = 0;
+    int c = 0;
+    int d = 0;    
+    int plus = 0;
+    int minus = 0;
+    led2 = 0;
+
+//    pc.printf("a=%d b=%d c=%d d=%d\n",a,b,c,d);
+   
+            if(pA){
+                wait(NOISE);
+                if(pA){ 
+                    a ++;
+//                    pc.printf("a=%d\n",a);
+                    wait(DELAY);
+                    if(pB){
+                        wait(NOISE);
+                        if(pB){
+                            b ++;
+//                            pc.printf("b=%d\n",b);
+                            wait(DELAY);
+                            plus ++;
+//                            pc.printf("plus=%d\n",plus);
+                            }
+                        }
+                }
+                wait(DELAY);
+            }
+            
+            if(pB){
+                wait(NOISE);
+                if(pB){ 
+                    c ++;
+//                    pc.printf("c=%d\n",c);
+                    wait(DELAY);
+                    if(pA){
+                        wait(NOISE);
+                        if(pA){
+                            d ++;
+//                            pc.printf("d=%d\n",d);
+                            wait(DELAY);
+                            minus ++;
+//                            pc.printf("minus=%d\n",minus);
+
+                            }
+                        }
+                    }
+                wait(DELAY);
+                }         
+        sum = plus - minus ;
+//        pc.printf("sum=%d\n",sum);
+}    
+
 void example_tweet1()
 {
-    const char url[] = "https://api.twitter.com/1.1/statuses/update.json"
-                       "?status=Hello World! - %s";
+    const char url[] = "https://api.twitter.com/1.1/statuses/update.json?status=Hello Everybody! Now, the number of people in the co-op - %s";
     char url2[128];
 
+
     time_t ctTime;
+
     time(&ctTime);
 
     snprintf(url2, sizeof(url2), url, ctime(&ctTime));
@@ -131,10 +261,10 @@
     }
 }
 
-void example_tweet2()
+void example_tweet2(void)
 {
     const char url[] = "https://api.twitter.com/1.1/statuses/update.json";
-
+    wait(INIT);
     std::vector<std::string> post;
     post.reserve(1);
 
@@ -142,8 +272,8 @@
 
     time_t ctTime;
     time(&ctTime);
-
-    snprintf(status, sizeof(status), "status=Hello World! - %s", ctime(&ctTime));
+    
+    snprintf(status, sizeof(status), "status=Hello Everybody! Now, the number of people in the co-op - %d %s",sum, ctime(&ctTime));
     post.push_back(status);
 
     HTTPResult result = oa4t.post(url, &post, &response);
@@ -154,7 +284,7 @@
         printf("POST error. (result = %d)\n", result);
     }
 }
-
+/*
 void example_tweet3()
 {
     const char url[] = "https://api.twitter.com/1.1/statuses/update.json";
@@ -192,6 +322,7 @@
         printf("POST error. (result = %d)\n", result);
     }
 }
+*/
 
 void example_getUserData()
 {