Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1
- #include <SPI.h>
- #include <TFT_eSPI.h>
- TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
- #define COLORT1 TFT_BLACK
- #define COLORT2 TFT_GREEN
- #define COLORT3 TFT_RED
- float bmpT,bmpP,bmpH;
- #include <Wire.h>
- //I2C
- #include <Adafruit_BME280.h>
- Adafruit_BME280 bme;
- void setup() {
- Serial.begin(115200);
- delay(1000);
- tft.init();
- tft.setRotation(0);
- tft.fillScreen(COLORT1);
- tft.setTextSize(2);
- Serial.println();
- Serial.print("TFT Init OK");
- Serial.begin(115200);
- delay(1000);
- if (!bme.begin()) {
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- }
- else {
- Serial.println("BME280 sensor OK");
- bmpT=bme.readTemperature();
- bmpH=bme.readHumidity();
- bmpP=bme.readPressure()/100.0;
- Serial.print("Temperature : "); Serial.println(bmpT);
- Serial.print("Humidity = "); Serial.println(bmpH);
- Serial.print("Pressure = "); Serial.println(bmpP);
- }
- }
- void loop() {
- uint16_t counter = 0;
- while(1) {
- tft.drawRect(-5,-5, 200, 20, COLORT2);
- tft.drawRect(195,-5, 50, 20, COLORT2);
- // POMIARY
- tft.drawRect(-5,15, 130, 30, COLORT2);
- tft.drawRect(125,15, 130, 30, COLORT2);
- // CONTENT
- tft.drawRect(-5,45, 130, 220, COLORT2);
- tft.drawRect(125,45, 130, 220, COLORT2);
- tft.setTextColor(COLORT3);
- tft.drawString("Laboratorium 2",30,280, 2);
- tft.setTextColor(COLORT2);
- tft.drawString("Pomiar 1",10,23, 1);
- counter++;
- bmpT=bme.readTemperature();
- bmpH=bme.readHumidity();
- bmpP=bme.readPressure()/100.0;
- char napis[20];
- sprintf(napis, "%.2f", bmpT);
- char napis2[20];
- sprintf(napis2, "%.2f", bmpH);
- char napis3[20];
- sprintf(napis3, "%.2f", bmpP);
- tft.drawString(napis,10,60, 1);
- tft.drawString("C",70,60, 1);
- tft.drawString(napis2,10,80, 1);
- tft.drawString("%",70,80, 1);
- tft.drawString(napis3,10,100, 1);
- tft.drawString("hPa",85,100, 1);
- char nap[20];
- sprintf(nap, "%d", counter);
- tft.drawString(nap,135,23, 1);
- delay(2000);
- tft.fillScreen(COLORT1);
- }
- }
- //2.1
- #include <SPI.h>
- #include <TFT_eSPI.h>
- TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
- #define COLORT1 TFT_BLACK
- #define COLORT2 TFT_GREEN
- #define COLORT3 TFT_RED
- float bmpT,bmpP,bmpH;
- #include <Wire.h>
- //I2C
- #include <Adafruit_BME280.h>
- Adafruit_BME280 bme;
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- DS18B20 ds(14); // pin GPIO14
- uint8_t address[8];
- void setup() {
- Serial.begin(115200);
- delay(1000);
- tft.init();
- tft.setRotation(0);
- tft.fillScreen(COLORT1);
- tft.setTextSize(2);
- Serial.println();
- Serial.print("TFT Init OK");
- Serial.begin(115200);
- delay(1000);
- if (!bme.begin()) {
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- }
- else {
- Serial.println("BME280 sensor OK");
- bmpT=bme.readTemperature();
- bmpH=bme.readHumidity();
- bmpP=bme.readPressure()/100.0;
- Serial.print("Temperature : "); Serial.println(bmpT);
- Serial.print("Humidity = "); Serial.println(bmpH);
- Serial.print("Pressure = "); Serial.println(bmpP);
- }
- }
- void loop() {
- uint16_t counter = 0;
- while(1) {
- tft.drawRect(-5,-5, 200, 20, COLORT2);
- tft.drawRect(195,-5, 50, 20, COLORT2);
- // POMIARY
- tft.drawRect(-5,15, 130, 30, COLORT2);
- tft.drawRect(125,15, 130, 30, COLORT2);
- // CONTENT
- tft.drawRect(-5,45, 260, 220, COLORT2);
- tft.setTextColor(COLORT3);
- tft.drawString("Laboratorium 4",30,280, 2);
- counter++;
- tft.setTextColor(COLORT2);
- tft.drawString("Pomiar:",10,23, 1);
- char nap[20];
- sprintf(nap, "%d", counter);
- tft.drawString(nap,95,23, 1);
- float temp = ds.getTempC();
- char tempS[20];
- sprintf(tempS, "%.2f", temp);
- tft.drawString(tempS,20,60, 1);
- tft.drawString("C",85,60, 1);
- uint8_t add[8];
- ds.getAddress(add);
- tft.setCursor(20, 80, 1);
- for (byte i = 0; i < 8; i++) {
- tft.print(add[i],HEX);
- }
- delay(2000);
- tft.fillScreen(COLORT1);
- }
- }
- //2.2
- #include <SPI.h>
- #include <TFT_eSPI.h>
- TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
- #define COLORT1 TFT_BLACK
- #define COLORT2 TFT_GREEN
- #define COLORT3 TFT_RED
- float bmpT,bmpP,bmpH;
- #include <Wire.h>
- //I2C
- #include <Adafruit_BME280.h>
- Adafruit_BME280 bme;
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- DS18B20 ds(14); // pin GPIO14
- uint8_t address[8];
- void setup() {
- Serial.begin(115200);
- delay(1000);
- tft.init();
- tft.setRotation(0);
- tft.fillScreen(COLORT1);
- tft.setTextSize(2);
- Serial.println();
- Serial.print("TFT Init OK");
- Serial.begin(115200);
- delay(1000);
- if (!bme.begin()) {
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- }
- else {
- Serial.println("BME280 sensor OK");
- bmpT=bme.readTemperature();
- bmpH=bme.readHumidity();
- bmpP=bme.readPressure()/100.0;
- Serial.print("Temperature : "); Serial.println(bmpT);
- Serial.print("Humidity = "); Serial.println(bmpH);
- Serial.print("Pressure = "); Serial.println(bmpP);
- }
- }
- void loop() {
- uint16_t counter = 0;
- while(1) {
- tft.drawRect(-5,-5, 200, 20, COLORT2);
- tft.drawRect(195,-5, 50, 20, COLORT2);
- // POMIARY
- tft.drawRect(-5,15, 130, 30, COLORT2);
- tft.drawRect(125,15, 130, 30, COLORT2);
- // CONTENT
- tft.drawRect(-5,45, 260, 220, COLORT2);
- tft.setTextColor(COLORT3);
- tft.drawString("Laboratorium 4",30,280, 2);
- counter++;
- tft.setTextColor(COLORT2);
- tft.drawString("Pomiar:",10,23, 1);
- char nap[20];
- sprintf(nap, "%d", counter);
- tft.drawString(nap,95,23, 1);
- float temp = ds.getTempC();
- char tempS[20];
- sprintf(tempS, "%.2f", temp);
- tft.drawString(tempS,20,60, 1);
- tft.drawString("C",85,60, 1);
- uint8_t add[8];
- ds.getAddress(add);
- tft.setCursor(20, 80, 1);
- for (byte i = 0; i < 8; i++) {
- tft.print(add[i],HEX);
- }
- ds.selectNext();
- ds.getAddress(add);
- tft.setCursor(20, 130, 1);
- for (byte i = 0; i < 8; i++) {
- tft.print(add[i],HEX);
- }
- delay(2000);
- tft.fillScreen(COLORT1);
- }
- }
- //3
- #define tms 10000000
- RTC_DATA_ATTR int bootCount = 0;
- void setup(){
- Serial.begin(115200);
- delay(1000); //Take some time to open up the Serial Monitor
- ++bootCount;
- Serial.println("Boot number: " + String(bootCount));
- print_wakeup_reason();
- esp_sleep_enable_ext0_wakeup(GPIO_NUM_2,1);
- esp_sleep_enable_ext0_wakeup(GPIO_NUM_15,1);//1 = High, 0 = Low
- esp_sleep_enable_timer_wakeup(tms);
- Serial.println("Going to sleep now");
- delay(1000);
- Serial.flush();
- esp_deep_sleep_start();
- Serial.println("This will never be printed");
- }
- void loop(){
- //This is not going to be called
- }
- void print_wakeup_reason(){
- esp_sleep_wakeup_cause_t w_r;
- w_r = esp_sleep_get_wakeup_cause();
- switch(w_r)
- {
- case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup using RTC_GPIO");
- break;
- case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup using RTC_CNTL");
- break;
- case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer");
- break;
- case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
- case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program");
- break;
- default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",w_r);
- break;
- }
- }
- //4
- #include <WiFi.h>
- #include <ESPAsyncWebServer.h>
- #include <ArduinoJson.h>
- #include <SPIFFS.h>
- AsyncWebServer server(80);
- const char* ssid = "realme GT 5G _";
- const char* password = "essa42069";
- void setup() {
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- if (WiFi.waitForConnectResult() != WL_CONNECTED) {
- Serial.printf("WiFi Failed!\n");
- return;
- }
- if (!SPIFFS.begin()) {
- Serial.println("SPIFFS Mount Failed, formatting!");
- SPIFFS.format();
- if (!SPIFFS.begin()) {
- Serial.println("SPIFFS Mount Failed after formatting, throw.");
- return;
- }
- }
- Serial.print("IP Address: ");
- Serial.println(WiFi.localIP());
- server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
- request->send(200, "text/html", listFiles());
- });
- server.on("/update", HTTP_GET, [](AsyncWebServerRequest * request) {
- DynamicJsonDocument doc(512);
- File f;
- if (SPIFFS.exists("/data.json")) {
- f = SPIFFS.open("/data.json", "r");
- deserializeJson(doc, f);
- f.close();
- }
- JsonObject e = doc.createNestedObject();
- e["timestamp"] = millis();
- e["data"] = random(0, 100);
- f = SPIFFS.open("/data.json", "w");
- serializeJson(doc, f);
- f.close();
- request->send(200, "text/plain", "OK");
- });
- server.on("/upload", HTTP_GET, [](AsyncWebServerRequest * request) {
- request->send(200, "text/html", "<form method='POST' action='/upload' enctype='multipart/form-data'><input type='file' name='upload'><input type='submit' value='upload'></form>");
- });
- server.on("/upload", HTTP_POST, [](AsyncWebServerRequest * request) {
- request->send(200);
- }, handleUpload);
- server.on("/file", HTTP_GET, [](AsyncWebServerRequest * request) {
- request->send(SPIFFS, "/data.json", "application/json");
- });
- server.serveStatic("/www/", SPIFFS, "/");
- server.begin();
- }
- void loop() {
- }
- void appendFile(fs::FS &fs, const char * path, const char * message) {
- Serial.printf("Appending to file: %s\r\n", path);
- File file = fs.open(path, FILE_APPEND);
- if (!file) {
- Serial.println("- failed to open file for appending");
- return;
- }
- if (file.print(message)) {
- Serial.println("- message appended");
- } else {
- Serial.println("- append failed");
- }
- file.close();
- }
- void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
- String logmessage = "Client:" + request->client()->remoteIP().toString() + " " + request->url();
- Serial.println(logmessage);
- if (!index) {
- logmessage = "Upload Start: " + String(filename);
- // open the file on first call and store the file handle in the request object
- request->_tempFile = SPIFFS.open("/" + filename, "w");
- Serial.println(logmessage);
- }
- if (len) {
- // stream the incoming chunk to the opened file
- request->_tempFile.write(data, len);
- logmessage = "Writing file: " + String(filename) + " index=" + String(index) + " len=" + String(len);
- Serial.println(logmessage);
- }
- if (final) {
- logmessage = "Upload Complete: " + String(filename) + ",size: " + String(index + len);
- // close the file handle as the upload is now done
- request->_tempFile.close();
- Serial.println(logmessage);
- request->redirect("/");
- }
- }
- // Make size of files human readable
- // source: https://github.com/CelliesProjects/minimalUploadAuthESP32
- String humanReadableSize(const size_t bytes) {
- if (bytes < 1024) return String(bytes) + " B";
- else if (bytes < (1024 * 1024)) return String(bytes / 1024.0) + " KB";
- else if (bytes < (1024 * 1024 * 1024)) return String(bytes / 1024.0 / 1024.0) + " MB";
- else return String(bytes / 1024.0 / 1024.0 / 1024.0) + " GB";
- }
- String listFiles() {
- String returnText = "";
- Serial.println("Listing files stored on SPIFFS");
- File root = SPIFFS.open("/");
- File foundfile = root.openNextFile();
- returnText += "<table><tr><th align='left'>Name</th><th align='left'>Size</th></tr>";
- while (foundfile) {
- returnText += "<tr align='left'><td><a href=\"/www/" + String(foundfile.name()) + "\">" + String(foundfile.name()) + "</a></td><td>" + humanReadableSize(foundfile.size()) + "</td></tr>";
- foundfile = root.openNextFile();
- }
- returnText += "</table>";
- returnText += "<br><a href=\"/upload\">Upload new file...</a>";
- root.close();
- foundfile.close();
- return returnText;
- }
- //5.2
- #include <BLEDevice.h>
- #include <BLEUtils.h>
- #include <BLEServer.h>
- #include <BLE2902.h>
- #define SERVICE_UUID BLEUUID((uint16_t)0x180F)
- #define CHARACTERISTIC_UUID BLEUUID((uint16_t)0x2A19)
- #define DESCRIPTOR_UUID BLEUUID((uint16_t)0x2901)
- BLECharacteristic BatteryLevelCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);
- BLEDescriptor BatteryLevelDescriptor(DESCRIPTOR_UUID);
- void setup()
- {
- Serial.begin(115200);
- Serial.println("Starting BLE work!");
- BLEDevice::init("QwertyAvatar");
- BLEServer *pServer = BLEDevice::createServer();
- BLEService *pService = pServer->createService(SERVICE_UUID);
- pService->addCharacteristic(&BatteryLevelCharacteristic);
- BatteryLevelDescriptor.setValue("Percentage 0 - 100");
- BatteryLevelCharacteristic.addDescriptor(&BatteryLevelDescriptor);
- BatteryLevelCharacteristic.addDescriptor(new BLE2902());
- pService->start();
- BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
- pAdvertising->addServiceUUID(SERVICE_UUID);
- pAdvertising->setScanResponse(true);
- pAdvertising->setMinPreferred(0x06);
- pAdvertising->setMinPreferred(0x12);
- BLEDevice::startAdvertising();
- Serial.println("Advertisement started!");
- }
- uint8_t level = 3;
- void loop()
- {
- BatteryLevelCharacteristic.setValue(&level, 1);
- BatteryLevelCharacteristic.notify();
- delay(5000);
- level -= 1;
- if(level == 0) {
- level = 100;
- }
- }
- /// 5.3
- #include <BLEDevice.h>
- #include <BLEUtils.h>
- #include <BLEScan.h>
- #include <BLEAdvertisedDevice.h>
- int scanTime = 5; // In seconds
- BLEScan *pBLEScan;
- class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
- {
- void onResult(BLEAdvertisedDevice advertisedDevice)
- {
- Serial.printf("Advertised Device: %s, address: %s, signal strength: %s dBm\n", advertisedDevice.getName().c_str(), advertisedDevice.getAddress().toString().c_str(), String(advertisedDevice.getRSSI()));
- }
- };
- void setup()
- {
- Serial.begin(115200);
- Serial.println("Scanning...");
- BLEDevice::init("QwertyAvatar");
- pBLEScan = BLEDevice::getScan();
- pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
- pBLEScan->setActiveScan(true);
- pBLEScan->setInterval(100);
- pBLEScan->setWindow(99);
- }
- void loop()
- {
- BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
- Serial.print("Devices found: ");
- Serial.println(foundDevices.getCount());
- Serial.println("Scan done!");
- pBLEScan->clearResults();
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement