Thermometer connected to internet

Dependencies:   BME280 EthernetInterface FXOS8700Q HTTPClient-wolfSSL NTPClient NetworkAPI OAuth4Tw TSL2561_I2C eCompass_FPU_Lib mbed-rtos mbed wolfSSL

Fork of TCP_Server_Example by Roy van Dam

Committer:
zeus3110
Date:
Sun Sep 27 11:04:54 2015 +0000
Revision:
12:12369ee344ab
Parent:
11:90554d22ade5
Network thermometer test program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:bb128f0e952f 1 #include "mbed.h"
zeus3110 12:12369ee344ab 2 #include "rtos.h"
donatien 0:bb128f0e952f 3 #include "EthernetInterface.h"
zeus3110 12:12369ee344ab 4
zeus3110 12:12369ee344ab 5 #include "Port.h"
zeus3110 12:12369ee344ab 6 #include "EnvServer.h"
zeus3110 12:12369ee344ab 7 #include "StatusLED.h"
zeus3110 12:12369ee344ab 8 #include "Sensor.h"
zeus3110 12:12369ee344ab 9 #include "Twitter.h"
zeus3110 12:12369ee344ab 10
zeus3110 12:12369ee344ab 11 extern EthernetInterface eth;
zeus3110 12:12369ee344ab 12 extern Serial pc;
zeus3110 12:12369ee344ab 13
zeus3110 12:12369ee344ab 14 Serial pc(USBTX, USBRX);
zeus3110 12:12369ee344ab 15 EthernetInterface eth;
zeus3110 12:12369ee344ab 16
zeus3110 12:12369ee344ab 17 int main()
NegativeBlack 6:33b57f606f2b 18 {
zeus3110 12:12369ee344ab 19 int ret;
zeus3110 12:12369ee344ab 20
zeus3110 12:12369ee344ab 21 // Timer for Hearbeat LED
zeus3110 12:12369ee344ab 22 RtosTimer HBLEDTickTimer(HBLedTicker,osTimerPeriodic);
zeus3110 12:12369ee344ab 23
zeus3110 12:12369ee344ab 24 // Initialize COM Port
zeus3110 12:12369ee344ab 25 pc.baud(115200);
zeus3110 12:12369ee344ab 26
zeus3110 12:12369ee344ab 27 // Initialize Status LED
zeus3110 12:12369ee344ab 28 pOBStatusLED=new StatusLED(new DigitalOut(LED_G),new DigitalOut(LED_R),new DigitalOut(LED_B));
zeus3110 12:12369ee344ab 29
zeus3110 12:12369ee344ab 30 // Initialize Sensor with I2C port
zeus3110 12:12369ee344ab 31 pSensor=new BME280(PTE25, PTE24);
zeus3110 12:12369ee344ab 32 pLumSensor=new TSL2561_I2C(PTE25, PTE24);
zeus3110 12:12369ee344ab 33 pLumSensor->enablePower();
zeus3110 12:12369ee344ab 34
zeus3110 12:12369ee344ab 35 //Initialize ethernet interface
zeus3110 12:12369ee344ab 36 eth.init(); //Use DHCP
zeus3110 12:12369ee344ab 37 printf("Initialized, MAC: %s\n", eth.getMACAddress());
zeus3110 12:12369ee344ab 38 while ((ret = eth.connect()) != 0) {
zeus3110 12:12369ee344ab 39 printf("Error eth.connect() - ret = %d\n", ret);
NegativeBlack 10:9e8d5928537a 40 }
zeus3110 12:12369ee344ab 41 printf("Connected, IP: %s, MASK: %s, GW: %s\n",
zeus3110 12:12369ee344ab 42 eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
zeus3110 12:12369ee344ab 43
zeus3110 12:12369ee344ab 44 // Correct internal RTC by connecting NTP Server
zeus3110 12:12369ee344ab 45 updateTime();
zeus3110 12:12369ee344ab 46
zeus3110 12:12369ee344ab 47 // Start Heartbeat LED Tick Thread
zeus3110 12:12369ee344ab 48 HBLEDTickTimer.start(HBLED_CYCLE);
zeus3110 12:12369ee344ab 49
zeus3110 12:12369ee344ab 50 // Start Server Thread
zeus3110 12:12369ee344ab 51 Thread ThServer(EnvServer);
zeus3110 12:12369ee344ab 52
zeus3110 12:12369ee344ab 53 // Start Twitter Client Thread
zeus3110 12:12369ee344ab 54 Thread TwetterClientTh(TwitterClient,NULL,osPriorityNormal,16384);
zeus3110 12:12369ee344ab 55
zeus3110 12:12369ee344ab 56 // wait forever
zeus3110 12:12369ee344ab 57 Thread::wait(osWaitForever);
NegativeBlack 6:33b57f606f2b 58 }