DTU

GRUPPE6

41030 MECHATRONICS ENGINEERING DESIGN

Merging code pt.1

To best make use of our manpower, we decided to split up into smaller groups and let each group work on a part of the code. One group was in charge of the NodeRed (signup/login of the locker using username and password), another group was in charge of the weather function and the OLED-screen, and the final group was in charge of the RFID code.

When the weather/OLED code and the RFID-code was finished, we decided to merge these codes, and clean up.

The functions to be used were split up into different tabs:

  • Main script: including initiations, setup void and loop void
  • WIFI: These functions connect the MCU to a wifi
  • OLED: A switch function for the OLED-screen, so that it will display specific messages depending on which integer the ”state” variable is set to
               (state=1 -> run case 1, state=2 -> run case 2, …)
  • MQTT: a callback function which is run if there is an incoming message from the MQTT-server
  • RFID_RC522: This code is able to read the rfid-code of new cards, save this info, and check if it is the same card used to unlock the locker. There is also a ”master key” that can unlock all lockers (for the janitor). This is the blue chip in our Arduino-kit.
  • WEATHER: This function gets weather forecast data for Copenhagen from http://api.openweathermap.org using an API-key. The data we are interested in (temperature, weather description and time/date) are saved under variables, and can later be displayed on the OLED-screen using the oled-function. Each weather forecast (after 3, 6 or 9 hours) has its own state in the oled function. Collecting fresh weather data (i.e. calling the weather function) happens every 5 minutes.

All delays in the code were replaced with the use of millis(), to make sure the MCU can receive messages from the RFID or MQTT.
‍

Next time, we want to replace the NodeRed signal that changes the weather forecast that the oled displays to a arduino built in timer that changes the oled. Also, the NodeRed still needs to be incorporated into this code