Sample program for Multi IoT Board

Dependencies:   MultiIoTBoardLib mbed

Committer:
jksoft
Date:
Fri Jul 28 02:27:13 2017 +0000
Revision:
0:6681a776924f
First edition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:6681a776924f 1 #include "mbed.h"
jksoft 0:6681a776924f 2 #include "mbed.h"
jksoft 0:6681a776924f 3 #include "HTTPClient.h"
jksoft 0:6681a776924f 4 #include "ESP8266Interface.h"
jksoft 0:6681a776924f 5 #include "TCPSocketConnection.h"
jksoft 0:6681a776924f 6 #include "SB1602E.h"
jksoft 0:6681a776924f 7 #include "BME280.h"
jksoft 0:6681a776924f 8 #include "mitb.h"
jksoft 0:6681a776924f 9
jksoft 0:6681a776924f 10 ESP8266Interface wifi(MITB_WIFI_TX,MITB_WIFI_RX,MITB_WIFI_RST,"ssid","pass",115200); // TX,RX,Reset,SSID,Password,Baud
jksoft 0:6681a776924f 11 SB1602E lcd(I2C_SDA,I2C_SCL); //SDA, SCL
jksoft 0:6681a776924f 12 BME280 sensor(I2C_SDA,I2C_SCL); //SDA, SCL
jksoft 0:6681a776924f 13 DigitalOut myled(MITB_LED);
jksoft 0:6681a776924f 14 Serial pc(USBTX,USBRX);
jksoft 0:6681a776924f 15
jksoft 0:6681a776924f 16 int main() {
jksoft 0:6681a776924f 17 HTTPClient http;
jksoft 0:6681a776924f 18 char str[512];
jksoft 0:6681a776924f 19
jksoft 0:6681a776924f 20 lcd.contrast(0x30);
jksoft 0:6681a776924f 21
jksoft 0:6681a776924f 22 lcd.printf( 0, "WiFi..");
jksoft 0:6681a776924f 23
jksoft 0:6681a776924f 24 wifi.init(); //Reset
jksoft 0:6681a776924f 25 wifi.connect(); //Use DHCP
jksoft 0:6681a776924f 26
jksoft 0:6681a776924f 27 lcd.printf( 1, "OK");
jksoft 0:6681a776924f 28 pc.printf("IP Address is %s\n", wifi.getIPAddress());
jksoft 0:6681a776924f 29
jksoft 0:6681a776924f 30 wait(2.0);
jksoft 0:6681a776924f 31
jksoft 0:6681a776924f 32 //GET
jksoft 0:6681a776924f 33 lcd.printf( 0, "HTTP GET");
jksoft 0:6681a776924f 34 pc.printf("\nTrying to fetch page using GET...\n\r");
jksoft 0:6681a776924f 35 int ret = http.get("http://jksoft.cocolog-nifty.com/msg.txt", str, 512);//IP address is httpbin.org/get
jksoft 0:6681a776924f 36
jksoft 0:6681a776924f 37 if (ret == 0) {
jksoft 0:6681a776924f 38 lcd.printf( 1, "OK");
jksoft 0:6681a776924f 39 pc.printf("Page fetched successfully - read %d characters\n\r", strlen(str));
jksoft 0:6681a776924f 40 pc.printf("Result: %s\n\r", str);
jksoft 0:6681a776924f 41 } else {
jksoft 0:6681a776924f 42 lcd.printf( 1, "NG");
jksoft 0:6681a776924f 43 pc.printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode());
jksoft 0:6681a776924f 44 }
jksoft 0:6681a776924f 45
jksoft 0:6681a776924f 46 while(1) {
jksoft 0:6681a776924f 47 float temperature = sensor.getTemperature();
jksoft 0:6681a776924f 48 float humidity = sensor.getHumidity();
jksoft 0:6681a776924f 49 float pressure = sensor.getPressure();
jksoft 0:6681a776924f 50
jksoft 0:6681a776924f 51 pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", temperature, pressure, humidity);
jksoft 0:6681a776924f 52 lcd.clear();
jksoft 0:6681a776924f 53 lcd.printf( 0, "%2.2f",temperature);
jksoft 0:6681a776924f 54 lcd.printf( 1, "%2.2f",humidity);
jksoft 0:6681a776924f 55 myled = !myled;
jksoft 0:6681a776924f 56 wait(1.0);
jksoft 0:6681a776924f 57 }
jksoft 0:6681a776924f 58 }