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: Chainable_RGB_LED DHT ESP8266Interface M2XStreamClient jsonlite mbed
main.cpp
00001 #include "mbed.h" 00002 #include "ChainableLED.h" 00003 #include "M2XStreamClient.h" 00004 #include "ESP8266Interface.h" 00005 #include "TCPSocketConnection.h" 00006 00007 DigitalOut myled(LED1); 00008 // ChainableLED(clk, data, number_of_leds) 00009 ChainableLED color_led(D4, D5, 1); 00010 #include "DHT.h" 00011 00012 DHT sensor(D3, DHT11); 00013 DigitalOut relay(D6); 00014 00015 /* 00016 * ESP8266 Wifi Config for nucleo 411 00017 */ 00018 ESP8266Interface wifi(D8,D2,D3,"SouthHackUp","",115200); // TX,RX,Reset,SSID,Password,Baud 00019 00020 // 00021 // Fill these field in from you ATT M2X Account 00022 // 00023 char deviceId[] = "<deviceID>"; // Device you want to push to 00024 char streamName[] = "<streamID>"; // Stream you want to push to 00025 char m2xKey[] = "<deviceAPIKey>"; // Your M2X API Key or Master API Key 00026 00027 00028 int main() { 00029 // dht related 00030 int error = 0; 00031 float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; 00032 00033 00034 printf("Starting...\r\n"); 00035 00036 // connect to wifi 00037 wifi.init(); //Reset 00038 wifi.connect(); //Use DHCP 00039 printf("IP Address is %s \n\r", wifi.getIPAddress()); 00040 00041 while(1) { 00042 // generate random RGB values for LED's 00043 uint8_t R = rand(); 00044 uint8_t G = rand(); 00045 uint8_t B = rand(); 00046 // print message to terminal 00047 //printf("R=%x,G=%x,B=%x,",R,G,B); 00048 00049 // ChainableLED.setColorRGB(index_of_led, red, green, blue) 00050 color_led.setColorRGB(0, R, G, B); 00051 myled = 1; // LED is ON 00052 relay = 1; 00053 00054 wait(1.0); // 200 ms 00055 00056 00057 myled = 0; // LED is OFF 00058 relay = 0; 00059 error = sensor.readData(); 00060 if (0 == error) { 00061 c = sensor.ReadTemperature(CELCIUS); 00062 f = sensor.ReadTemperature(FARENHEIT); 00063 k = sensor.ReadTemperature(KELVIN); 00064 h = sensor.ReadHumidity(); 00065 dp = sensor.CalcdewPoint(c, h); 00066 dpf = sensor.CalcdewPointFast(c, h); 00067 printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\r\n", k, c, f); 00068 printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\r\n", h, dp, dpf); 00069 } else { 00070 printf("Error: %d\n", error); 00071 } 00072 wait(1.0); // 1 sec 00073 } 00074 }
Generated on Sun Jul 31 2022 09:04:02 by
1.7.2