wf
Dependencies: Adafruit_GFX WIZnetInterface mbed
Fork of Tweeting_Machine_HelloWorld_WIZwiki-W7500 by
main.cpp@2:ea5adceaa93c, 2018-06-21 (annotated)
- Committer:
- wiznetw7500
- Date:
- Thu Jun 21 06:44:33 2018 +0000
- Revision:
- 2:ea5adceaa93c
- Parent:
- 1:5f4bd210e2f0
iuytres
Who changed what in which revision?
User | Revision | Line number | New 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 | |
wiznetw7500 | 2:ea5adceaa93c | 5 | #define TOKEN "904626807491530753-sOaChz44g9YFS7EuvRkR75l1W9T303K" |
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); |
wiznetw7500 | 2:ea5adceaa93c | 21 | const char ip_addr[] = "192.168.0.112"; // WIZwiki-W7500 IP-address |
wiznetw7500 | 2:ea5adceaa93c | 22 | const char mask_addr[] = "255.255.255.0"; |
wiznetw7500 | 2:ea5adceaa93c | 23 | const char gateway_addr[] = "192.168.0.1"; |
joon874 | 0:8548416648df | 24 | |
joon874 | 0:8548416648df | 25 | int main() |
joon874 | 0:8548416648df | 26 | { |
joon874 | 0:8548416648df | 27 | int phy_link; |
joon874 | 0:8548416648df | 28 | printf("Wait a second...\r\n"); |
irinakim | 1:5f4bd210e2f0 | 29 | //--------- Have to modify the mac address------------- |
irinakim | 1:5f4bd210e2f0 | 30 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x22}; |
joon874 | 0:8548416648df | 31 | |
joon874 | 0:8548416648df | 32 | EthernetInterface eth; |
wiznetw7500 | 2:ea5adceaa93c | 33 | eth.init(mac_addr,ip_addr,mask_addr,gateway_addr); //Use DHCP |
joon874 | 0:8548416648df | 34 | |
joon874 | 0:8548416648df | 35 | eth.connect(); |
joon874 | 0:8548416648df | 36 | |
joon874 | 0:8548416648df | 37 | while(1){ |
joon874 | 0:8548416648df | 38 | |
joon874 | 0:8548416648df | 39 | /* phy link */ |
joon874 | 0:8548416648df | 40 | do{ |
joon874 | 0:8548416648df | 41 | phy_link = eth.ethernet_link(); |
joon874 | 0:8548416648df | 42 | printf("..."); |
joon874 | 0:8548416648df | 43 | wait(2); |
joon874 | 0:8548416648df | 44 | }while(!phy_link); |
joon874 | 0:8548416648df | 45 | printf("\r\n"); |
joon874 | 0:8548416648df | 46 | |
joon874 | 0:8548416648df | 47 | printf("IP Address is %s\r\n", eth.getIPAddress()); |
joon874 | 0:8548416648df | 48 | |
joon874 | 0:8548416648df | 49 | /* TCP socket connect */ |
joon874 | 0:8548416648df | 50 | TCPSocketConnection sock; |
wiznetw7500 | 2:ea5adceaa93c | 51 | sock.connect("192.168.93.1", 21); |
wiznetw7500 | 2:ea5adceaa93c | 52 | if(sock.is_connected()) |
joon874 | 0:8548416648df | 53 | printf("connected\r\n\r\n"); |
wiznetw7500 | 2:ea5adceaa93c | 54 | else |
wiznetw7500 | 2:ea5adceaa93c | 55 | printf("No connection\r\n"); |
joon874 | 0:8548416648df | 56 | /* typing message */ |
joon874 | 0:8548416648df | 57 | printf("typing twitter message :"); |
joon874 | 0:8548416648df | 58 | |
joon874 | 0:8548416648df | 59 | char* message; |
wiznetw7500 | 2:ea5adceaa93c | 60 | /* scanf("%s",message); |
joon874 | 0:8548416648df | 61 | printf("%s",message); |
joon874 | 0:8548416648df | 62 | printf("\r\n\r\n"); |
joon874 | 0:8548416648df | 63 | |
joon874 | 0:8548416648df | 64 | int len = strlen(message); |
joon874 | 0:8548416648df | 65 | |
joon874 | 0:8548416648df | 66 | /* data length measure */ |
wiznetw7500 | 2:ea5adceaa93c | 67 | // char data_len[2]={0}; |
wiznetw7500 | 2:ea5adceaa93c | 68 | //int ten=0; |
wiznetw7500 | 2:ea5adceaa93c | 69 | //int one=0;*/ |
joon874 | 0:8548416648df | 70 | |
wiznetw7500 | 2:ea5adceaa93c | 71 | // int length = len + sizeof(TOKEN) - 1 + 14; |
joon874 | 0:8548416648df | 72 | |
wiznetw7500 | 2:ea5adceaa93c | 73 | // printf("length : %d\r\n\r\n",length); |
joon874 | 0:8548416648df | 74 | |
wiznetw7500 | 2:ea5adceaa93c | 75 | // ten = length/10; |
wiznetw7500 | 2:ea5adceaa93c | 76 | //one = length%10; |
wiznetw7500 | 2:ea5adceaa93c | 77 | //data_len[1] = one + 48; |
wiznetw7500 | 2:ea5adceaa93c | 78 | //data_len[0] = ten + 48; |
joon874 | 0:8548416648df | 79 | |
joon874 | 0:8548416648df | 80 | char *cmd1 = "POST http://arduino-tweet.appspot.com/update HTTP/1.0\r\nContent-Length:"; |
wiznetw7500 | 2:ea5adceaa93c | 81 | // char *cmd2 = data_len; |
joon874 | 0:8548416648df | 82 | char *cmd3 = "\r\n\r\ntoken="; |
joon874 | 0:8548416648df | 83 | char *cmd4 = TOKEN; |
joon874 | 0:8548416648df | 84 | char *cmd5 = "&status="; |
joon874 | 0:8548416648df | 85 | char *cmd6 = message; |
joon874 | 0:8548416648df | 86 | char *cmd7 = "\r\n"; |
joon874 | 0:8548416648df | 87 | |
joon874 | 0:8548416648df | 88 | char send_data[1024]; |
joon874 | 0:8548416648df | 89 | char buffer[1024] = {0}; |
wiznetw7500 | 2:ea5adceaa93c | 90 | sprintf(send_data, "GET https://api.thingspeak.com/update?api_key=WQ0EX0W6CA5JK57Z&field1=200\r\n",TOKEN,message); |
joon874 | 0:8548416648df | 91 | |
wiznetw7500 | 2:ea5adceaa93c | 92 | sock.send_all(send_data, sizeof(send_data)); |
joon874 | 0:8548416648df | 93 | |
joon874 | 0:8548416648df | 94 | printf("%s\r\n",send_data); |
joon874 | 0:8548416648df | 95 | printf("send message done\r\n"); |
joon874 | 0:8548416648df | 96 | |
wiznetw7500 | 2:ea5adceaa93c | 97 | sock.receive(buffer, sizeof(buffer)); |
joon874 | 0:8548416648df | 98 | |
joon874 | 0:8548416648df | 99 | printf("%s\r\n",buffer); |
joon874 | 0:8548416648df | 100 | |
joon874 | 0:8548416648df | 101 | gOled.begin(); |
joon874 | 0:8548416648df | 102 | gOled.printf("%s\r\n",message); |
joon874 | 0:8548416648df | 103 | gOled.display(); |
joon874 | 0:8548416648df | 104 | |
joon874 | 0:8548416648df | 105 | wait(70.0); |
joon874 | 0:8548416648df | 106 | |
joon874 | 0:8548416648df | 107 | gOled.clearDisplay(); |
joon874 | 0:8548416648df | 108 | |
joon874 | 0:8548416648df | 109 | //sock.close(); |
joon874 | 0:8548416648df | 110 | //eth.disconnect(); |
joon874 | 0:8548416648df | 111 | |
joon874 | 0:8548416648df | 112 | }; |
joon874 | 0:8548416648df | 113 | |
joon874 | 0:8548416648df | 114 | } |