der-conrad-adventskalender-iot-2016

Shorten the waiting time for Christmas with exciting and enjoyable experiments done with the Internet of things. Thereby send push messages on your smartphone or build an alarm system with a motion sensor that informs you of suspicious movements. Learn how to use various web services, such as Twitter, and use the protocol for the Internet of things: MQTT. The Internet-of-things advent calendar contains all construction pieces for 24 experiments, including a uniquely developed hardware board with integrated WLAN-module which can be progammed via the free Arduino IDE. ...

08.09.2017 · 2 min · Fabian Kainka

Day 24: Gift box

With the last test in this Advent, we get really Christmasy. We’re building a reusable gift box with which you can delight your relatives. Every time someone opens the present, the contents are lit up in an individual colour, and a Christmas sound plays. Behind today’s door is a retro-reflective sensor. This is actually two components, an IR transmitter diode and a phototransistor. It’s not very easy to see which way the elements have to be connected in terms of polarity. For this reason, it’s best if you connect the photoelectric sensor with the connection cables according to the example shown. Then you won’t be able to switch the polarity as easily. ...

24.12.2016 · 6 min · Fabian Kainka

Day 23: MQTT Climate

Behind the door for today is a battery clip for a 9 V block, with which you can make the entire system moveable. An alternative to a battery is a power bank (a rechargeable battery pack, normally for mobile phones). You can see in today’s layout picture how to connect a 9 V battery correctly. This is how you can connect a 9 V battery to today's layout Climate data should be captured again today. But this time they are published through the MQTT broker and are thus accessible worldwide. The data could thus be called up via a plug-in and stored in a database. ...

23.12.2016 · 5 min · Fabian Kainka

Day 22: MQTT Cheerlights

Today’s trial is about MQTT and a global project that was presented last year: the Cheerlights Project by Hans Schaaler. For everyone who doesn’t know the project: It’s about globally networked coloured lights that can be simultaneously controlled through Twitter commands. Another version of this project was part of last year’s Advent calendar. This year we have the version with MQTT and expanded functions. Behind today’s door is a 1-kohm resistor. The layout consists of the RGB LED with series resistors and a button. ...

22.12.2016 · 6 min · Fabian Kainka

Day 21: House automation

In today’s test, we’ll illuminate the characteristics and possibilities of MQTT in more detail by creating a practical scenario. In the example, there is a building with two rooms, each of which has a light switch, a light and an alarm sensor. The light switch switches the light of the respective room on or off. The alarm sensors activate a building-wide alarm. Normally, seven different devices would be used here, which are all connected to each other through an MQTT broker. But since we probably have only one NanoESP, this will simulate all devices. For this reason, today’s layout looks somewhat complicated. The LED D3 is used today as the second light. Therefore, today it won’t show you whether you’re connected to the WLAN. The tilt sensors are used on the extension cables as alarm sensors. A person could, for example, attach them to doors or windows so that they trigger an alarm if the entry opens. Behind today’s door is the second sensor. ...

21.12.2016 · 5 min · Fabian Kainka

Day 20: MQTT (Message Queue Telemetry Transport)

For the last days of this Advent, you’ll now become familiar with a subject that plays a large role in the realm of the IoT. We’re dealing with the messaging protocol MQTT, which was specially developed for the communication from machine to machine (M2M). The protocol is thus so brilliant because e.g. control data, measurement data or texts can be exchanged very easily and compactly. The overhead (data that’s transferred alongside the actual user data) is much lower than with HTTP and can be processed readily even by embedded devices, meaning microcontrollers like our NanoESP. At the same time, the controller doesn’t constantly have to establish a connection and query whether there’s been a change; instead, the connection is continually maintained and the client automatically gives information about changes. ...

20.12.2016 · 5 min · Fabian Kainka

Day 19: Configuration page for the NanoESP

Behind today’s door is another cable. With the two cables it’s possible, for example, to place the RGB LED apart from the board. We’ll need the RGB LED today because the test is about a website with which you can adjust its colours. But that’s not the main aspect: To make the configuration of the NanoESP board especially easy not just for programmers, there is a configuration page through which the WLAN data of the module can be adjusted. But first to the set-up. You see it in the following picture. ...

19.12.2016 · 5 min · Fabian Kainka

Day 18: Weather monitoring

Behind today’s door is a very special component, namely a humidity sensor. Together with the phototransistor and the NTC, it creates a weather station for at-home use. The following layout is necessary for this purpose: The layout with all sensors (resistors 1 kohm) Today’s layout is a bit fiddly. Especially at the point where the potentiometer on the right of the image sits, it touches the NanoESP. But that’s not really a problem as long as the contact on the left of the image is plugged firmly into the board. ...

18.12.2016 · 4 min · Fabian Kainka

Day 17: Wake Up Light

Today’s project deals with a well-known lamp from Phillips, the Wake Up Light. This is an alarm clock that, instead of making a loud noise, slowly increases the brightness. This creates a type of sunrise, and one wakes up in a natural manner. Behind today’s door is another potentiometer, which is important for tomorrow’s test. The following layout is required today: The RGB LED with series resistors The sketch: A16_P17_WakeUpLight.ino /* TCP-Server: Wakeup light Change SSID and PASSWORD. RGB-Led (common cathode) on Pins 3,5,6 */ #include <NanoESP.h> #include <NanoESP_HTTP.h> #include <SoftwareSerial.h> #include "Websites.h" #include <math.h> #include <Time.h> #define SSID "YourSSID" #define PASSWORD "YourPassword" #define LED_WLAN 13 #define RED 3 #define GREEN 5 #define BLUE 6 #define GND 4 #define BUTTON 7 NanoESP nanoesp = NanoESP(); NanoESP_HTTP http = NanoESP_HTTP(nanoesp); //String timeServerIP = ; // time.nist.gov NTP server address String ntpServerName = "195.145.119.188";//"time.nist.gov"; const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets int alarmHour = 0, alarmMinute = 2; bool alarm; byte cRed = 0, cBlue = 0, cGreen = 0; unsigned long previousMillis = 0; // will store last time a msg was send unsigned long interval = 78; // void setup() { Serial.begin(19200); nanoesp.init(); pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT); pinMode(GND, OUTPUT); digitalWrite(GND, LOW); pinMode(BUTTON, INPUT); //Only Station Mode for TimeSync nanoesp.configWifiMode(STATION); //delay(1000); // Wait till Connected to WiFi if (nanoesp.wifiConnected())digitalWrite(LED_WLAN, HIGH); else Serial.println(F("Error WLAN Connect")); //Start TCP Server if (nanoesp.startTcpServer(80)) Serial.println(F("TCP Server Activ")); else Serial.println(F("TCP Server Error")); //Print IP in Terminal Serial.println(nanoesp.getIp()); setSyncProvider(getNtpTime); Show_Time(); } time_t getNtpTime() { //convert to time_t , Paramter: connectionId, ServerAdress, Timezone return (time_t)getNTPpacket(4, ntpServerName, 2); } void loop() { String method, ressource, parameter; int id ; if (http.recvRequest(id, method, ressource, parameter)) { Serial.println("New Request from id :" + String(id) + ", method: " + method + ", ressource: " + ressource + " parameter: " + parameter); if (ressource == "/") { http.sendFromFlash(id, index, sizeof(index)); nanoesp.closeConnection(id); } if (ressource == "/settimer") { if (parameter != "") { //timer=02%3A03& String sHour = parameter.substring(parameter.indexOf('=') + 1, parameter.indexOf('%')); String sMin = parameter.substring(parameter.indexOf('A') + 1, parameter.indexOf('&')); String sDuration = parameter.substring(parameter.indexOf('&') + 1); sDuration = sDuration.substring(sDuration.indexOf('=') + 1, sDuration.indexOf('&')); alarmHour = sHour.toInt(); alarmMinute = sMin.toInt(); int iDuration = sDuration.toInt(); interval *= iDuration; Serial.println("Timer: " + String(alarmHour) + ":" + String(alarmMinute) + " Duartion: " + String (iDuration) ); Show_Time(); } nanoesp.closeConnection(id); } if (ressource == "/turnoff") { alarm = false; cRed = 0; cBlue = 0; cGreen =0; analogWrite(RED,cRed); analogWrite(BLUE,cBlue);analogWrite(GREEN,cGreen); } else { http.sendFromFlash(id, error404, sizeof(error404)); nanoesp.closeConnection(id); } } else { if (hour() == alarmHour) { if (minute() == alarmMinute) { if (!alarm) alarm = true; } } if (alarm) wakeUp(); } } void MorningAlarm() { Serial.println("Alarm: - turn lights off"); } void wakeUp() { if (millis() - previousMillis >= interval) { previousMillis = millis(); if (cRed == 0) Show_Time(); if (cRed < 255) { cRed++; analogWrite(RED, cRed ); } else { if (cGreen < 255) { cGreen++; analogWrite(GREEN, cGreen); } else { if (cBlue < 255) { cBlue++; analogWrite(BLUE, cBlue ); if (cBlue == 255) Show_Time(); } } } } } // prepare an NTP request to the time server and send to the given bool sendNTPpacket(int id, String address) { // set all bytes in the buffer to 0 memset(packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request // (see URL above for details on the packets) packetBuffer[0] = 0b11100011; // LI, Version, Mode packetBuffer[1] = 0; // Stratum, or type of clock packetBuffer[2] = 6; // Polling Interval packetBuffer[3] = 0xEC; // Peer Clock Precision // 8 bytes of zero for Root Delay & Root Dispersion packetBuffer[12] = 49; packetBuffer[13] = 0x4E; packetBuffer[14] = 49; packetBuffer[15] = 52; // // if we need a cr/lf // packetBuffer[NTP_PACKET_SIZE ] = 0x0D; packetBuffer[NTP_PACKET_SIZE + 1] = 0x0A; // all NTP fields have been given values, now // you can send a packet requesting a timestamp: if ( nanoesp.sendRaw(id, packetBuffer, NTP_PACKET_SIZE)) return true; return false; } long getNTPpacket(int id, String address, int timeZone) { unsigned long secsSince1900; byte offset = 40; if (!nanoesp.newConnection(id, UDP, address, 123)) Serial.println ("no connection ntp server"); //NTP requests are to port 123 delay(100); if (!sendNTPpacket(id, address)) { Serial.println("No time request send"); return 0; } nanoesp.setTimeout(2000); if (nanoesp.find("+IPD,")) { int vid = nanoesp.parseInt(); nanoesp.find(","); int len = nanoesp.parseInt(); //Serial.println(String(len)); byte buffer[len]; nanoesp.find(":"); nanoesp.readBytes(buffer, 48); // for (int i = 0; i <= NTP_PACKET_SIZE; i++) { // Serial.print(buffer[i], HEX); // } // convert four bytes starting at location 40 to a long integer secsSince1900 = (unsigned long)buffer[offset + 0] << 24; secsSince1900 |= (unsigned long)buffer[offset + 1] << 16; secsSince1900 |= (unsigned long)buffer[offset + 2] << 8; secsSince1900 |= (unsigned long)buffer[offset + 3]; nanoesp.find("OK\r\n"); nanoesp.closeConnection(id); // return secsSince1900 + timeZone * SECS_PER_HOUR; // NTP Date return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR; // UNIX Date } else { Serial.println("no time recieved"); nanoesp.closeConnection(id); return 0; } } void Show_Time() { String shour, sminute, ssecond; Serial.print("Date: "); Serial.print(day()); Serial.print("."); Serial.print(month()); Serial.print("."); Serial.println(year()); if (hour() <= 9) shour = "0" + String(hour()); else shour = String(hour()); // adjust for 0-9 if (minute() <= 9) sminute = "0" + String(minute()); else sminute = String(minute()); if (second() <= 9) ssecond = "0" + String(second()); else ssecond = String(second()); Serial.println( "Time: " + shour + ":" + sminute + ":" + ssecond ); } (The former Arduino Create embed is no longer available; the code is taken from the download of all sketches.) ...

17.12.2016 · 5 min · Fabian Kainka

Day 16: A web server piano

Behind today’s door is a piezo sound transducer. It’s possible to generate sounds with it, which will become clear in today’s test. Today you’re building a type of piano that can be used via a website. See the following picture for the layout: The correct connection of the piezo sound transducer The sketch: A16_P16_WebserverPiano.ino /* TCP-Server Piano Change SSID and PASSWORD. */ #include <NanoESP.h> #include <NanoESP_HTTP.h> //special library for http-connection #include <SoftwareSerial.h> #include "Websites.h" //websites in a special file as progmem #define SSID "YourSSID" #define PASSWORD "YourPassword" #define LED_WLAN 13 NanoESP nanoesp = NanoESP(); NanoESP_HTTP http = NanoESP_HTTP(nanoesp); void setup() { Serial.begin(19200); nanoesp.init(); //! Only if you want to change the ACCESPOINT configuration //nanoesp.configWifi(ACCESSPOINT, "NanoESP", ""); //! Only if you use a new Network // nanoesp.configWifi(DUAL, SSID, PASSWORD); //Dual Mode nanoesp.configWifiMode(DUAL); //delay(1000); // Wait till Connected to WiFi if (nanoesp.wifiConnected())digitalWrite(LED_WLAN, HIGH); else Serial.println(F("Error WLAN Connect")); //Start TCP Server if (nanoesp.startTcpServer(80)) Serial.println(F("TCP Server Activ")); else Serial.println(F("TCP Server Error")); //Print IP in Terminal Serial.println(nanoesp.getIp()); } void loop() { String method, ressource, parameter; int id; if (http.recvRequest(id, method, ressource, parameter)) { //Incoming request, parameters by reference Serial.println("New Request from id :" + String(id) + ", method: " + method + ", ressource: " + ressource + " parameter: " + parameter); if (ressource == "/") { http.sendFromFlash(id, index, sizeof(index)); nanoesp.closeConnection(id); } else if (ressource == "/dataonly") { //only data is recieved on this url, no need to send a website nanoesp.closeConnection(id); } else { http.sendFromFlash(id, error404, sizeof(error404)); nanoesp.closeConnection(id); } if (parameter != "") //the request included parameters { String strTone; if (method == GET) strTone = parameter.substring(6); else strTone = parameter.substring(5); //get note values noTone(8); tone(8, strTone.toInt(), 200); //play note for 200ms } } } (The former Arduino Create embed is no longer available; the code is taken from the download of all sketches.) ...

16.12.2016 · 3 min · Fabian Kainka