2021-EFREI-M1-The Sunset Coverfew Alert ( The SCA)

So now I want you to take a few seconds to imagine that we're facing a new curfew...
that the curfew be at nightfall and not at a fixed time so that the time spent outside will fluctuate with the seasons
that's when our project comes into action.

Slides & Videos

Members

NameContribution
Gaspard THEVENOTThevenot Gaspard:
-research
-Aseembly
-code
-full report
-PowerPoint:
-Oral presentation
-Video Editing
Grégoire Angebaud-Research
-PowerPoint
-Oral presentation
-Report

State of the Art

Business Aspect

Nothing

For the business Aspect, our project doesn’t have any competition with other industries. It’s also because our project is based on event that may never happen

Technical Aspect

Project Description

Problem Definition
Imagine that we leave in a word where the COVID-19 is still here and the coverfew is still imposed to the population. You’ll say it’s the same thing but what if this coverfew is not regulate by an hour but by the sunset. In this it will be because every clock in the world stop to work. So in this eventual world how would you be warned that it will be the time to go home?
Challenges & Motivation
I will now talk about how our project came about.
The final project is not our first idea
indeed our first project which was made of lights was not appreciated by one of our teachers.
He then proposed us a project of data collection for a car which did not interest us much knowing that the data collected would have been on the car and that we did not necessarily intend to use our car during this period.
We then turned to a project which consisted in analyzing the ambient noise in a city and to transcribe these data on a map in the shape of a circle.
unfortunately this project had to be abandoned because the equipment we had couldn't work in France because of the wavelength used by our equipment.
the professor then suggested that we take up a project from last year and improve it.
however this project seemed to us too complicated for the time we had left, counting on the fact that we did not have the necessary equipment.

So we decided to create a project within the time and skill we had. So our project can still have upgrade but to motivate ourselves we wanted to create one at least a little bit funny
Real and Complete Usecases

Technical Description

To realize this project we needed to use: – An esp 32 – a photoresistance – one resistor (10k Ohm) – threads To develop our code we used arduino to send the data to the cloud. To save the data and put it in graph form we used ThingSpeak. Channel ID  : 1281213 for the test Channel ID  : 1281249 for the video (Those channel are on a public access) We also used ThingSpeak’s MatLab Analysis tool to send the email when the brightness drops below a certain threshold.

Hardware

Materials
ImageNamePart NumberPriceCountLink
ESP 110.99€1🛒
resistance (10kOhm)2~0.5€1🛒
Photoresistance30.20€1🛒
jumper wires40.07€3🛒
Schematic

Software

Arduino Code

/*
  WriteSingleField
  
  Description: Writes a value to a channel on ThingSpeak every 20 seconds.
  
  Hardware: ESP32 based boards
   
  Note:
  - Requires installation of EPS32 core. See https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md for details. 
  - Select the target hardware from the Tools->Board menu
  - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
  
  ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 
  analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel.  
  
  Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed.
  See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation.
  
  For licensing information, see the accompanying license file.
  
  Copyright 2018, The MathWorks, Inc.
*/

#include "ThingSpeak.h"
#include "secrets.h"
#include 

char ssid[] = SECRET_SSID;   // your network SSID (name) 
char pass[] = SECRET_PASS;   // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)
WiFiClient  client;

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

int number = 0;

void setup() {
  Serial.begin(115200);  //Initialize serial

  WiFi.mode(WIFI_STA);   
  ThingSpeak.begin(client);  // Initialize ThingSpeak
}

void loop() {

  // Connect or reconnect to WiFi
  if(WiFi.status() != WL_CONNECTED){
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(SECRET_SSID);
    while(WiFi.status() != WL_CONNECTED){
      WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
      Serial.print(".");
      delay(20000);     
    } 
    Serial.println("\nConnected.");
  }

  number = analogRead(36);
  int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);
  if(x == 200){
    Serial.println("Channel update successful.");
  }
  else{
    Serial.println("Problem updating channel. HTTP error code " + String(x));
  }
  
   
  delay(20000); // Wait 20 seconds to update the channel again
}
// Use this file to store all of the private credentials 
// and connection details

#define SECRET_SSID "Tel gaspard"		// replace MySSID with your WiFi network name
#define SECRET_PASS "12345678"	// replace MyPassword with your WiFi password

#define SECRET_CH_ID 1281249			// replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY "095DAVCP2L62E1KG"   // replace XYZ with your channel write API Key
% Store the channel ID for the sensor channel.
channelID = 1281249;

% Provide the ThingSpeak alerts API key.  All alerts API keys start with TAK.
alertApiKey = 'TAKJ0ZPEPG8UU1D5N3PWR';

% Set the address for the HTTTP call
alertUrl="https://api.thingspeak.com/alerts/send";

% webwrite uses weboptions to add required headers.  Alerts needs a ThingSpeak-Alerts-API-Key header.
options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]);

% Set the email subject.
alertSubject = sprintf("warning dude!");

% Read the recent data.
lightData = thingSpeakRead(channelID,'ReadKey','9XCFL555DGOYUBX3','NumDays',30,'Fields',1);

% Check to make sure the data was read correctly from the channel.
if isempty(lightData)
    alertBody = ' No data read . ';      
else
    
    % Get the most recent point in the array of moisture data.
    lastValue = lightData(end); 
    disp(lastValue)

    % Set the outgoing message
    if (lastValue<=2000)
        alertBody = ' it s geeting dark! ';
    else
        alertBody = ' its ok. ';
    end
end
 
 % Catch errors so the MATLAB code does not disable a TimeControl if it fails
try
    webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options);
catch someException
    fprintf("Failed to send alert: %s\n", someException.message);
end

External Services

ThingSpeak

ThingSpeak is a website for IoT project ThingSpeak can be used for data collection and usage ThingSpeak include a MATLAB analysis tool