void setupEthernet() { lcd.printf("Setup Ethernet...\r\n"); // Starting eth.init(); // Initialize while (eth.connect()) { // timeout and loop until connected lcd.printf("Connect timeout\r\n"); }; lcd.printf("IP Address is %s\r\n", eth.getIPAddress()); // successful connect }
void handleBigDeal(string opptyName,string opptyAmount) { lcd2.cls(); //Reset LEDs led1=0; led2=0; led3=0; led4=0; //Display Big Deal Message lcd2.cls(); lcd2.locate(0,0); lcd2.printf(BIG_DEAL_ALERT,opptyName.c_str(),opptyAmount.c_str()); //Flash Big Deal Alert LED sequence for(int i=0; i < NUM_FLASHES; i++) { led1=1; wait(0.1); led1=0; led2=1; wait(0.1); led2=0; led3=1; wait(0.1); led3=0; led4=1; wait(0.1); led4=0; led3=1; wait(0.1); led3=0; led2=1; wait(0.1); led2=0; led1=1; wait(0.1); led1=0; } //Reset LCD screen lcd2.cls(); lcd2.locate(0,0); lcd2.printf("Listening for requests.\n"); return; }
int main() { int i=0; FILE *fp = fopen( "/msc/msctest.csv", "w"); if ( fp == NULL ) { error("Could not open file for write\n"); } fprintf(fp,"Time, Latitude, Longitude, Acc X, Acc Y, Acc Z\n"); if(MMA.testConnection()) { myled2 = 1; } while (1) { lcd.cls(); lcd.locate(0,0); lcd.printf("Waiting..."); if (gps.sample()) { myled = myled ? 0 : 1; lcd.cls(); lcd.locate(3,3); lcd.printf("Position Locked"); float longitude = gps.longitude - 0.663; fprintf(fp,"%d, %f, %f, %.2f, %.2f, %.2f\n", i, gps.latitude, longitude, MMA.x(), MMA.y(), MMA.z()); i++; wait(1); } if (i == 30) { fclose(fp); break; } } }
int main() { setbuf(stdout, NULL); // no buffering for this filehandle char json[1024]; int content_length; int response_code; char buf[1024]; float amb_temp; setupEthernet(); // set time lcd.printf("Reading Time... "); ntp.setTime("time-c.nist.gov"); lcd.printf("Time set"); while(1) { // Loop char streamName[] = "amb-temp"; // Set value for stream you are using // GET Stream value response_code = getStream(streamName, json); content_length = readContentLength(json); pc.printf("GET Stream\r\nResponse: %d\r\nContent Length: %d\r\njson: %s\r\n\r\n", response_code, content_length, json); Thread::wait(5000); ///// // PUT value to Strem amb_temp = tmp.read(); sprintf(json, "{\"value\":\"%0.2f\"}", amb_temp); response_code = putStream(streamName, json); content_length = readContentLength(json); pc.printf("PUT Stream\r\nResponse: %d\r\nContent Length: %d\r\njson: %s\r\n\r\n", response_code, content_length, json); Thread::wait(5000); ////// // POST value(s) to Stream time_t seconds; seconds = time(NULL); // get current time from mbed RTC strftime(buf,40, "%Y-%m-%dT%H:%M:%S%z", localtime(&seconds)); amb_temp = tmp.read(); sprintf(json, "{ \"values\": [ {\"at\": \"%s\", \"value\":\"%0.2f\"} ] }", buf, amb_temp); response_code = postStream(streamName, json); content_length = readContentLength(json); pc.printf("POST Stream\r\nResponse: %d\r\nContent Length: %d\r\njson: %s\r\n\r\n", response_code, content_length, json); Thread::wait(5000); /////// // PUT Location to Feed sprintf(json, "{ \"name\": \"%s\", \"latitude\": \"%0.8f\", \"longitude\": \"%0.8f\", \"elevation\": \"%0.2f\" }", LOC_NAME, LOC_LAT, LOC_LONG, LOC_ELEV); response_code = putLocation(json); content_length = readContentLength(json); pc.printf("PUT Location\r\nResponse: %d\r\nContent Length: %d\r\njson: %s\r\n\r\n", response_code, content_length, json); Thread::wait(5000); /////// // GET Location of Feed response_code = getLocation(json); content_length = readContentLength(json); pc.printf("GET Location\r\nResponse: %d\r\nContent Length: %d\r\njson: %s\r\n\r\n", response_code, content_length, json); Thread::wait(5000); } eth.disconnect(); while(1) {} }