This Program is based on the configuration of ThingSpeak using ARMmbed
Dependencies: Adafruit_GFX WIZnetInterface mbed
Fork of Tweeting_Machine_HelloWorld_WIZwiki-W7500 by
Revision 2:16c044e2f30d, committed 2017-11-24
- Comitter:
- ajeet3004
- Date:
- Fri Nov 24 08:32:11 2017 +0000
- Parent:
- 1:5f4bd210e2f0
- Commit message:
- ThingSpeak_Configuration with Wizwiki w7500 via Ethernet
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5f4bd210e2f0 -r 16c044e2f30d main.cpp --- a/main.cpp Wed May 11 00:51:18 2016 +0000 +++ b/main.cpp Fri Nov 24 08:32:11 2017 +0000 @@ -2,9 +2,13 @@ #include "EthernetInterface.h" #include "Adafruit_SSD1306.h" -#define TOKEN "3252156354-fG0b1utXYAg5IqeJNMSJFlenx1rgSRXm5wgk21l" +#define TOKEN "904626807491530753-sOaChz44g9YFS7EuvRkR75l1W9T303K" //#define TOKEN "UserToken" - +AnalogIn CDS(A0); + + int i = 0; + //int PIR_sensor; + int CDS_data = 0; // an SPI sub-class that provides a constructed default class I2CPreInit : public I2C { @@ -23,88 +27,93 @@ int main() { int phy_link; - printf("Wait a second...\r\n"); + printf("................................configuration using Ethernet connection..........................\r\n\r\n"); //--------- Have to modify the mac address------------- uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x22}; - EthernetInterface eth; + EthernetInterface eth; eth.init(mac_addr); //Use DHCP eth.connect(); - while(1){ + /* phy link */ - do{ + while(!phy_link){ + printf("Failed to obtain IP Adress\r\n\r\n"); phy_link = eth.ethernet_link(); printf("..."); wait(2); - }while(!phy_link); + } printf("\r\n"); - - printf("IP Address is %s\r\n", eth.getIPAddress()); - + printf("IP Adress obtained\r\n\r\n"); + printf("IP Address is: %s\r\n", eth.getIPAddress()); + while(1){ /* TCP socket connect */ TCPSocketConnection sock; - sock.connect("arduino-tweet.appspot.com", 80); - - printf("connected\r\n\r\n"); + - /* typing message */ - printf("typing twitter message :"); + printf("\r\n Reading the LDR sensor values \n\r"); + + while (1) { + //PIR_sensor = PIR; + sock.connect("api.thingspeak.com", 80); + if(sock.is_connected()) + { + printf("\r\nConnected to the DNS Server\r\n\r\n"); + } + else + { + printf("\r\nDNS Server connection error\r\n\r\n"); + } - char* message; - scanf("%s",message); + CDS_data = CDS.read()*1000; + + //CDS Sensor ADC Low Data + printf("===========================================\n\r"); + printf("CDS Data : %3d\r\n",CDS_data); + printf("===========================================\n\r"); + // pc.printf("PIR Value : %d\r\n",PIR_sensor); + // myled =! PIR_sensor; + + /* char* message; + scanf("%s",message); printf("%s",message); printf("\r\n\r\n"); int len = strlen(message); - /* data length measure */ + data length measure char data_len[2]={0}; int ten=0; - int one=0; - - int length = len + sizeof(TOKEN) - 1 + 14; - - printf("length : %d\r\n\r\n",length); + int one=0;*/ - ten = length/10; - one = length%10; - data_len[1] = one + 48; - data_len[0] = ten + 48; - char *cmd1 = "POST http://arduino-tweet.appspot.com/update HTTP/1.0\r\nContent-Length:"; - char *cmd2 = data_len; - char *cmd3 = "\r\n\r\ntoken="; - char *cmd4 = TOKEN; - char *cmd5 = "&status="; - char *cmd6 = message; - char *cmd7 = "\r\n"; - + if(CDS_data>70) + { char send_data[1024]; char buffer[1024] = {0}; - sprintf(send_data, "%s%s%s%s%s%s%s", cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7); - - sock.send_all(send_data, sizeof(send_data)-1); + sprintf(send_data, "GET http://api.thingspeak.com/update?key=1M68DA3MGRI6TGOO&field2=%d\r\n",CDS_data); + - printf("%s\r\n",send_data); - printf("send message done\r\n"); - - sock.receive(buffer, sizeof(buffer)-1); + if(sock.send_all(send_data, sizeof(send_data))!=-1) + { + printf("The sent URL is: %s\r\n",send_data); + // printf("The sent Tweet is: %s",message); + printf("\r\nMessage sent successfully\r\n\r\n"); + } + else + { + printf("\r\nMessage sending failed\r\n\r\n"); + } + printf("Response from the server:\r\n\r\n"); + sock.receive(buffer, sizeof(buffer)); printf("%s\r\n",buffer); - - gOled.begin(); - gOled.printf("%s\r\n",message); - gOled.display(); - - wait(70.0); - - gOled.clearDisplay(); - - //sock.close(); - //eth.disconnect(); + } + //sock.disconnect(); + wait(18); + } };
diff -r 5f4bd210e2f0 -r 16c044e2f30d mbed.bld --- a/mbed.bld Wed May 11 00:51:18 2016 +0000 +++ b/mbed.bld Fri Nov 24 08:32:11 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file