Skip to content

Commit

Permalink
day19+20
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepMartiElias committed Dec 19, 2023
1 parent dc14275 commit fd4c62b
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 0 deletions.
Binary file added docs/images/Day19.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Day191.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Day20.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ hide:
1. Check this [API](https://openweathermap.org/api)

!!! note annotate "19. Let's party! (1)"
[Day 19](solutions/19/19.md)
1. :ping_pong:

!!! tip annotate "20. Change my name (1)"
[Day 20](solutions/20/20.md)
1. How should I be called in the future?

!!! bug annotate "21. ChatGPT can you help me write a Cristmas card? (1)"
Expand Down
109 changes: 109 additions & 0 deletions docs/solutions/18/18.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,116 @@ You can try to use the [SmartCitizen API](https://developer.smartcitizen.me/)
### Arduino code

```c++
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
#include <Adafruit_NeoPixel.h>

#define PIN 38
#define NUMPIXELS 1

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// Replace with your network credentials
const char* ssid = "IJ";
const char* password = "drroux51";

const char* serverName = "https://api.smartcitizen.me/v0/devices/16866/readings?sensor_id=55&rollup=1h";

const int but = 0;

bool pressed = false;

double temp;

void setup() {
pinMode(but, INPUT);
pixels.begin();
pixels.setBrightness(100);
Serial.begin(115200);
Serial.println();
// Initialize Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
}

void loop() {

if (!digitalRead(but) && !pressed) {
pressed = true;
WiFiClientSecure* client = new WiFiClientSecure;
if (client) {
// set secure client without certificate
client->setInsecure();
//create an HTTPClient instance
HTTPClient https;

//Initializing an HTTPS communication using the secure client
Serial.print("[HTTPS] begin...\n");
if (https.begin(*client, serverName)) { // HTTPS
Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
// print server response payload
String payload = https.getString();
//Serial.println(payload);
JSONVar myObject = JSON.parse(payload);

if (JSON.typeof(myObject) == "undefined") {
Serial.println("Parsing input failed!");
}

temp = myObject["readings"][0][1];
Serial.print("Temperature = ");
Serial.print(temp);
Serial.print(" Measured: ");
Serial.println(myObject["readings"][0][0]);

if (temp < 10){
pixels.setPixelColor(0,pixels.Color(0,0,255));
}
else if (temp < 15){
pixels.setPixelColor(0,pixels.Color(0,255,255));
}
else if (temp < 20){
pixels.setPixelColor(0,pixels.Color(0,255,0));
}
else if (temp < 25){
pixels.setPixelColor(0,pixels.Color(255,255,0));
}
else if (temp < 20){
pixels.setPixelColor(0,pixels.Color(255,0,0));
}
pixels.show();

}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
}
} else {
Serial.printf("[HTTPS] Unable to connect\n");
}
}
else if (digitalRead(but) && pressed){
pressed = false;
}
}
```
## Hero shot
Expand Down
9 changes: 9 additions & 0 deletions docs/solutions/19/19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Day nineteen:

Come with your Barduino to the Algo-ping-pong-tournament! If you can, join us today!

![Day19](../../images/Day191.jpeg)

## Hero shot

![Day19](../../images/Day19.jpeg)
9 changes: 9 additions & 0 deletions docs/solutions/20/20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Day twenty:

Let's find a new name for the Barduino! Today is simple, just propose a new name for the board 🥳

I propose **GUSPIRA** 💥, that it means Spark in Catalan

![Day19](../../images/Day20.jpeg)


Binary file added docs/video/day18.mp4
Binary file not shown.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ nav:
- Day 16: solutions/16/16.md
- Day 17: solutions/17/17.md
- Day 18: solutions/18/18.md
- Day 19: solutions/19/19.md
- Day 20: solutions/20/20.md
- Solution template:
- template.md

Expand Down

0 comments on commit fd4c62b

Please sign in to comment.