wf

Dependencies:   Adafruit_GFX WIZnetInterface mbed

Fork of Tweeting_Machine_HelloWorld_WIZwiki-W7500 by IOP

Committer:
irinakim
Date:
Wed May 11 00:51:18 2016 +0000
Revision:
1:5f4bd210e2f0
Parent:
0:8548416648df
Child:
2:ea5adceaa93c
Add comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joon874 0:8548416648df 1 #include "mbed.h"
joon874 0:8548416648df 2 #include "EthernetInterface.h"
joon874 0:8548416648df 3 #include "Adafruit_SSD1306.h"
joon874 0:8548416648df 4
irinakim 1:5f4bd210e2f0 5 #define TOKEN "3252156354-fG0b1utXYAg5IqeJNMSJFlenx1rgSRXm5wgk21l"
irinakim 1:5f4bd210e2f0 6 //#define TOKEN "UserToken"
joon874 0:8548416648df 7
joon874 0:8548416648df 8 // an SPI sub-class that provides a constructed default
joon874 0:8548416648df 9 class I2CPreInit : public I2C
joon874 0:8548416648df 10 {
joon874 0:8548416648df 11 public:
joon874 0:8548416648df 12 I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
joon874 0:8548416648df 13 {
joon874 0:8548416648df 14 frequency(100000);
joon874 0:8548416648df 15 start();
joon874 0:8548416648df 16 };
joon874 0:8548416648df 17 };
joon874 0:8548416648df 18
joon874 0:8548416648df 19 I2CPreInit gI2C(PA_10,PA_9);
joon874 0:8548416648df 20 Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128);
joon874 0:8548416648df 21
joon874 0:8548416648df 22
joon874 0:8548416648df 23 int main()
joon874 0:8548416648df 24 {
joon874 0:8548416648df 25 int phy_link;
joon874 0:8548416648df 26 printf("Wait a second...\r\n");
irinakim 1:5f4bd210e2f0 27 //--------- Have to modify the mac address-------------
irinakim 1:5f4bd210e2f0 28 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x22};
joon874 0:8548416648df 29
joon874 0:8548416648df 30 EthernetInterface eth;
joon874 0:8548416648df 31 eth.init(mac_addr); //Use DHCP
joon874 0:8548416648df 32
joon874 0:8548416648df 33 eth.connect();
joon874 0:8548416648df 34
joon874 0:8548416648df 35 while(1){
joon874 0:8548416648df 36
joon874 0:8548416648df 37 /* phy link */
joon874 0:8548416648df 38 do{
joon874 0:8548416648df 39 phy_link = eth.ethernet_link();
joon874 0:8548416648df 40 printf("...");
joon874 0:8548416648df 41 wait(2);
joon874 0:8548416648df 42 }while(!phy_link);
joon874 0:8548416648df 43 printf("\r\n");
joon874 0:8548416648df 44
joon874 0:8548416648df 45 printf("IP Address is %s\r\n", eth.getIPAddress());
joon874 0:8548416648df 46
joon874 0:8548416648df 47 /* TCP socket connect */
joon874 0:8548416648df 48 TCPSocketConnection sock;
joon874 0:8548416648df 49 sock.connect("arduino-tweet.appspot.com", 80);
joon874 0:8548416648df 50
joon874 0:8548416648df 51 printf("connected\r\n\r\n");
joon874 0:8548416648df 52
joon874 0:8548416648df 53 /* typing message */
joon874 0:8548416648df 54 printf("typing twitter message :");
joon874 0:8548416648df 55
joon874 0:8548416648df 56 char* message;
joon874 0:8548416648df 57 scanf("%s",message);
joon874 0:8548416648df 58 printf("%s",message);
joon874 0:8548416648df 59 printf("\r\n\r\n");
joon874 0:8548416648df 60
joon874 0:8548416648df 61 int len = strlen(message);
joon874 0:8548416648df 62
joon874 0:8548416648df 63 /* data length measure */
joon874 0:8548416648df 64 char data_len[2]={0};
joon874 0:8548416648df 65 int ten=0;
joon874 0:8548416648df 66 int one=0;
joon874 0:8548416648df 67
joon874 0:8548416648df 68 int length = len + sizeof(TOKEN) - 1 + 14;
joon874 0:8548416648df 69
joon874 0:8548416648df 70 printf("length : %d\r\n\r\n",length);
joon874 0:8548416648df 71
joon874 0:8548416648df 72 ten = length/10;
joon874 0:8548416648df 73 one = length%10;
joon874 0:8548416648df 74 data_len[1] = one + 48;
joon874 0:8548416648df 75 data_len[0] = ten + 48;
joon874 0:8548416648df 76
joon874 0:8548416648df 77 char *cmd1 = "POST http://arduino-tweet.appspot.com/update HTTP/1.0\r\nContent-Length:";
joon874 0:8548416648df 78 char *cmd2 = data_len;
joon874 0:8548416648df 79 char *cmd3 = "\r\n\r\ntoken=";
joon874 0:8548416648df 80 char *cmd4 = TOKEN;
joon874 0:8548416648df 81 char *cmd5 = "&status=";
joon874 0:8548416648df 82 char *cmd6 = message;
joon874 0:8548416648df 83 char *cmd7 = "\r\n";
joon874 0:8548416648df 84
joon874 0:8548416648df 85 char send_data[1024];
joon874 0:8548416648df 86 char buffer[1024] = {0};
joon874 0:8548416648df 87 sprintf(send_data, "%s%s%s%s%s%s%s", cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7);
joon874 0:8548416648df 88
joon874 0:8548416648df 89 sock.send_all(send_data, sizeof(send_data)-1);
joon874 0:8548416648df 90
joon874 0:8548416648df 91 printf("%s\r\n",send_data);
joon874 0:8548416648df 92 printf("send message done\r\n");
joon874 0:8548416648df 93
joon874 0:8548416648df 94 sock.receive(buffer, sizeof(buffer)-1);
joon874 0:8548416648df 95
joon874 0:8548416648df 96 printf("%s\r\n",buffer);
joon874 0:8548416648df 97
joon874 0:8548416648df 98 gOled.begin();
joon874 0:8548416648df 99 gOled.printf("%s\r\n",message);
joon874 0:8548416648df 100 gOled.display();
joon874 0:8548416648df 101
joon874 0:8548416648df 102 wait(70.0);
joon874 0:8548416648df 103
joon874 0:8548416648df 104 gOled.clearDisplay();
joon874 0:8548416648df 105
joon874 0:8548416648df 106 //sock.close();
joon874 0:8548416648df 107 //eth.disconnect();
joon874 0:8548416648df 108
joon874 0:8548416648df 109 };
joon874 0:8548416648df 110
joon874 0:8548416648df 111 }