Skip to content

Commit

Permalink
day 22
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepMartiElias committed Dec 22, 2023
1 parent c74e4db commit dfc37ef
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ hide:
1. From the Barduino?

!!! example annotate "22. Let's send it to someone (1)"
[Day 22](solutions/22/22.md)
1. From Barduino with love :love_letter:

!!! warning annotate "23. Barduino meets traditions (1)"
Expand Down
93 changes: 93 additions & 0 deletions docs/solutions/22/21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Day twenty one:

Now send the message from yesterday to te Telegram group using a bot! You can use te Bot we created if you want, the token is in the code as the groupID. Have fun!

## Possible solution!

### Arduino code

```c++
#include <ArduinoJson.h>
#include <ArduinoJson.hpp>
#include <WiFiClientSecure.h>
#include <ChatGPT.hpp>
#include <Adafruit_NeoPixel.h>
#include <UniversalTelegramBot.h>


const char* ssid = "yournetwork";
const char* password = "yourpassword";

#define BOTtoken "6851800826:AAFR3MVc8p9a77InL4mVXcwVaMCmfa96kAs"
#define CHAT_ID "-1002075060951"

WiFiClientSecure clientTELEGRAM;
UniversalTelegramBot bot(BOTtoken, clientTELEGRAM);

WiFiClientSecure clientGPT;
ChatGPT<WiFiClientSecure> chat_gpt(&clientGPT, "v1", "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");


#define PIN 38
#define NUMPIXELS 1
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

String result;

void setup() {
Serial.begin(115200);
Serial.print("Connecting to WiFi network: ");
Serial.print(ssid);
Serial.println("'...");
WiFi.begin(ssid, password);
pixels.begin();

while (WiFi.status() != WL_CONNECTED) {
Serial.println("Connecting...");
delay(500);
}
Serial.println("Connected!");

clientGPT.setInsecure();
clientTELEGRAM.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org

//bot.sendMessage(CHAT_ID, "Bot started up", "");
}

void loop() {
int touch = touchRead(2);

if(touch>29000){
pixels.setPixelColor(0, pixels.Color(0, 150, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Pause before next pass through loop
}else{
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Pause before next pass through loop
}

if(touch>300000){
Serial.println(touch);
if (chat_gpt.simple_message("gpt-4", "user", "Can you create for me a Christmas card with an ASCII drawing and a text for the Adventronics participants? Signed with love from Josep, please.", result)) {
Serial.println("===OK===");
Serial.println(result);
bot.sendMessage(CHAT_ID, result, "");
Serial.println("Telegram message sent!");
} else {
Serial.println("===ERROR===");
Serial.println(result);
bot.sendMessage(CHAT_ID, "This is not a ChatGPT message because the API Key is not correct, but Josep's Barduino wish you all HAPPY HOLIDAYS! <3", "");
Serial.println("Telegram message sent!");
}
}
Serial.println(touch);
delay(500);
}
```
## Hero shot
<video controls autoplay loop style="display: block; margin: auto;">
<source src="../../../video/day22.mp4" type="video/mp4">
</video>
Binary file added docs/video/day22.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ nav:
- Day 19: solutions/19/19.md
- Day 20: solutions/20/20.md
- Day 21: solutions/21/21.md
- Day 22: solutions/22/22.md
- Solution template:
- template.md

Expand Down

0 comments on commit dfc37ef

Please sign in to comment.