#include #include #include //#include #include #include //#include #include //Includes - Libraries needed #include #include //#include #include #include #include #include #include //----------------------------------------------------------------- // Hardware Connected // OLED Display #define OLED_CS 4 #define OLED_DC 11 #define OLED_CLK 10 #define OLED_DATA 9 #define OLED_RESET 13 // pins used for the connection with the sensor the others you need are controlled by the SPI library): const int NICReady = 6; //const int chipSelectPin = 7; //----------------------------------------------------------------- // Variables #define oneminute 60000 // 60,000 millis per minute char spin ; //Used as a spinning wheel indicator on the screen int l; //spin counter char world_status = '?'; //Comms port ready? R, char client_status = '?'; //Client connected char serial_status = '?'; //Serial port connected? //crude Layout of screen, start of column for a 64x128 OLED int col0 = 0; int col1 = 16; int col2 = 32; int col3 = 48; int col4 = 64; unsigned long windowStartTime; // assign a MAC address for the ethernet controller. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // assign a STATIC IP address for the controller: IPAddress ip(192,168,1,20); IPAddress gateway(192,168,1,1); IPAddress subnet(255, 255, 255, 0); //----------------------------------------------------------------- // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); // and the OLED Adafruit_SSD1306 OLED_display(OLED_DATA, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); //----------------------------------------------------------------- void setup() { delay(5000); wdt_enable(WDTO_8S); // if controller hangs for more than 8 seconds, then resets! setTime(0,0,0,1,1,12); //timer determines how often stuff happens Alarm.timerRepeat(2, OLED_Activity); // The spinning wheel on the screen goes round and round //Alarm.timerRepeat(2, OLED_Report_Status); //interrupt and call Alternate display to display other channel every 5 seconds Alarm.timerRepeat(5, reset_client_status); //Pin Init pinMode(SS, OUTPUT); digitalWrite(SS, HIGH); //pinMode(led, OUTPUT); //pinMode(btnSTAT_RESET, INPUT); //pinMode(btnAUX_RESET, INPUT); // initalize the data ready and chip select pins: pinMode(NICReady, INPUT); // pinMode(chipSelectPin, OUTPUT); pinMode(OLED_RESET, OUTPUT); pinMode(OLED_CS, OUTPUT); // OLED Init digitalWrite(OLED_RESET, LOW); Alarm.delay(2); digitalWrite(OLED_RESET, HIGH); OLED_display.begin(SSD1306_SWITCHCAPVCC); //OLED_display.setRotation(2); //If your case requires the OLED display flipped OLED_display.display(); // Lets Begin... windowStartTime = millis(); //serial_status = 'N'; //Serial.begin(9600); // while (!Serial) { // ; // wait for serial port to connect. Needed for Leonardo only // } serial_status = 'Y'; // Serial.println("Starting..."); // start the SPI library: SPI.begin(); Alarm.delay(500); OLED_Welcome(); // start the Ethernet connection and the server: //#if defined(WIZ550io_WITH_MACADDRESS) // Ethernet.begin(ip); //#else // Ethernet.begin(mac, ip); //#endif while (!digitalRead(NICReady)) { ; // wait for nic port to connect. // Serial.println("Waiting for NIC to be ready......"); } if (digitalRead(NICReady) == HIGH) { Ethernet.begin( ip, subnet, gateway); Alarm.delay(2000); server.begin(); Alarm.delay(2000); } //Serial.print("Server is listening on "); // Serial.println(Ethernet.localIP()); } void loop() { if (digitalRead(NICReady) == HIGH) { //getData(); world_status = 'Y'; listenForEthernetClients(); // listen for incoming Ethernet connections: } else { world_status = '-'; // client_status = '-'; } Alarm.delay(500); //wait at least 2 sec between reading the DHT sensor OLED_Report_Status(); wdt_reset(); // watchdog timer set back to zero } void reset_client_status(){ client_status = '-'; } void getData() { //Serial.println("Getting reading"); //Read the temperature data } void listenForEthernetClients() { // listen for incoming clients EthernetClient client = server.available(); //Serial.println("Listen..."); if (client) { client_status = 'Y'; // Serial.println("Got a client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { client_status = 'Y'; if (client.available()) { char c = client.read(); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); // print the current readings, in HTML format: client.print("IPAddress: "); client.print(ip); client.print(" Test "); client.println("
"); client.print("Test2: " ); client.print(" ?"); client.println("
"); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data Alarm.delay(2); // close the connection: client.stop(); } } void OLED_Activity() { l = l + 1; switch (l) { case 1: spin = '\\'; break; case 2: spin = '|'; break; case 3: spin = '/'; break; case 4: spin = '-'; break; default: l=0; } } void OLED_Report_Status() { //Delete previous display OLED_display.clearDisplay(); OLED_display.setTextSize(1); OLED_display.setCursor(0,0); OLED_display.print(spin); OLED_display.print(" Web Server:"); OLED_display.setTextSize(1); OLED_display.setCursor(0, 8); OLED_display.print(Ethernet.localIP()); OLED_display.setCursor(0, 16); OLED_display.print("Nic Ready"); OLED_display.setCursor(110, 16); OLED_display.print("["); OLED_display.print(world_status); OLED_display.print("]"); OLED_display.setTextSize(1); OLED_display.setCursor(0,24); OLED_display.print("Serial Avail:"); OLED_display.setCursor(110, 24); OLED_display.print("["); OLED_display.print(serial_status); OLED_display.print("]"); OLED_display.setCursor(0,32); OLED_display.print("Client Connected:"); OLED_display.setCursor(110, 32); OLED_display.print("["); OLED_display.print(client_status); OLED_display.print("]"); OLED_display.display(); } void OLED_Welcome() { // OLED_display.OLED_display(); // show splashscreen OLED_display.clearDisplay(); OLED_display.setTextColor(WHITE); OLED_display.setTextSize(1); OLED_display.setCursor(0,0); OLED_display.print("Web Server"); OLED_display.setCursor(0,8); OLED_display.print(ip); OLED_display.setCursor(0,25); OLED_display.print("A Jordaan"); OLED_display.setTextSize(1); OLED_display.setCursor(0,40); OLED_display.print("Ver 1.0.1"); OLED_display.setCursor(0,48); OLED_display.print("elektor"); OLED_display.display(); Alarm.delay(2000); OLED_display.clearDisplay(); //OLED_display.display(); }