Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit_GFX HTTPClient WIZnetInterface mbed
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "Adafruit_SSD1306.h" 00004 #include "HTTPClient.h" 00005 00006 00007 #if defined(TARGET_WIZWIKI_W7500)||defined(TARGET_WIZWIKI_W7500P) 00008 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x53, 0xAE, 0x90}; 00009 #endif 00010 // W7500 onboard LED & Init 00011 DigitalOut rled(LED1,1); 00012 DigitalOut gled(LED2,0); 00013 DigitalOut bled(LED3,1); 00014 AnalogIn Sensor(A0); 00015 // I2C Class 00016 I2C i2c(PA_10,PA_9); 00017 00018 // OLED Class 00019 Adafruit_SSD1306_I2c gOled(i2c,NC,0x78,64,128); 00020 Serial pc(USBTX, USBRX); 00021 00022 EthernetInterface eth; 00023 00024 // Declare TCP Connection Class 00025 TCPSocketConnection sock; 00026 00027 DigitalOut myled(D1); 00028 00029 00030 00031 int main() { 00032 00033 00034 00035 int phy_link; 00036 printf("Wait a second...\r\n"); 00037 00038 eth.init(mac_addr); //Use DHCP 00039 00040 printf("Check Ethernet Link\r\n"); 00041 /*while(1) //Wait link up 00042 { 00043 if(eth.link() == true) 00044 break; 00045 }*/ 00046 printf("Link up\r\n"); 00047 00048 eth.connect(); 00049 00050 printf("IP Address is %s\r\n\r\n", eth.getIPAddress()); 00051 printf("MASK Address is %s\r\n\r\n", eth.getNetworkMask()); 00052 printf("GATEWAY Address is %s\r\n\r\n", eth.getGateway()); 00053 printf("MAC Address is %s\r\n\r\n", eth.getMACAddress()); 00054 while(1){ 00055 // TCP socket connect to openweather server 00056 //TCPSocketConnection sock; 00057 char send_data[1024]; 00058 int CDS_data=3000; 00059 sock.connect("api.thingspeak.com", 80); 00060 00061 sprintf(send_data, "GET http://api.thingspeak.com/update?key=0Q8S3KCULT7GUDVR&field1=%d HTTP/1.0\n\n",CDS_data); 00062 // GET method, to request weather forecast 00063 // char http_cmd[] = "GET /update?api_key=0Q8S3KCULT7GUDVR&field1=2000 HTTP/1.0\n\n"; 00064 00065 00066 sock.send_all(send_data, sizeof(send_data)-1); 00067 00068 // get data into buffer 00069 char buffer[2048]; 00070 int ret; 00071 while (true) { 00072 ret = sock.receive(buffer, sizeof(buffer)-1); 00073 if (ret <= 0) 00074 break; 00075 buffer[ret] = '\0'; 00076 printf("Received %d chars from server: %s\n", ret, buffer); 00077 } 00078 printf("\r\n\r\n"); 00079 } 00080 }
Generated on Sat Jul 16 2022 18:57:18 by
1.7.2