Advertisement
Guest User

GUI + all functions

a guest
Oct 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.65 KB | None | 0 0
  1. #include <lvgl.h>
  2. #include <Ticker.h>
  3. #include <TFT_eSPI.h>
  4.  
  5. #include <WiFi.h>
  6. #include "HX711.h"
  7. #include <Wire.h>
  8. #include <Adafruit_Sensor.h>
  9. #include <Adafruit_BME280.h>
  10. #include <Preferences.h>
  11.  
  12. #define TINY_GSM_MODEM_SIM800
  13. #include <TinyGsmClient.h>
  14. #include <HTTPClient.h>
  15.  
  16. #define ConversionSeconds 1000000 // Conversion factor for micro seconds to seconds //
  17. #define SleepTime 10 // Time ESP32 will go to sleep (in seconds)
  18. #define NTP_SERVER "de.pool.ntp.org"
  19. #define TZ_INFO "WEST-1DWEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00" // Western European Time
  20. #define BME_SCL 22 // Pin Define BME280
  21. #define BME_SDA 21 // Pin Define BME280
  22. #define SEALEVELPRESSURE_HPA (1013.25)
  23. #define BUTTON 12 // Pin Define for a Button to set the scale to Tare
  24.  
  25. Adafruit_BME280 bme; // I2C BME 280
  26. //SHT21 SHT21;
  27.  
  28.  
  29. #define SerialMon Serial
  30. #define RX2 16 // Pin Define für GSM Modul SIM800L
  31. #define TX2 17 // Pin Define für GSM Modul SIM800L
  32. #define SerialAT Serial2
  33. #define TINY_GSM_RX_BUFFER 1024
  34. #define TINY_GSM_DEBUG SerialMon
  35. #define GSM_PIN ""
  36.  
  37. const int relaisPin = 13; //Pin Define relais 3.3 Volt hx711 + bme180
  38. const int relaisPin1 = 02; //Pin Define relais 4.1 Volt Sim800L
  39. const int relaisPin2 = 15; //Pin Define relais 5v hx711
  40.  
  41. const int LOADCELL_DOUT_PIN = 35; // Define for HX711 Scale Pins
  42. const int LOADCELL_SCK_PIN = 32; // Define for HX711 Scale Pins
  43. int buttonState = 0;
  44. bool buttonPressed = false;
  45. HX711 scale; //setting hx711 as scale in library
  46. Preferences preferences; // Methode for saving Tare Results
  47.  
  48. unsigned long delayTime;
  49.  
  50. const int wdtTimeout = 20000; //time in ms to trigger the watchdog
  51. hw_timer_t *timer = NULL;
  52.  
  53. RTC_DATA_ATTR int BootCounter = 0; // Variables that stays in RTC memory after reset
  54. RTC_DATA_ATTR float Tare;
  55. RTC_DATA_ATTR float temperature = 0;
  56. RTC_DATA_ATTR float pressure = 0;
  57. RTC_DATA_ATTR float approx_altitude = 0;
  58. RTC_DATA_ATTR float humidity = 0;
  59. //RTC_DATA_ATTR float g_temperature = 0;
  60.  
  61.  
  62.  
  63. #define LVGL_TICK_PERIOD 60
  64. Ticker tick; /* timer for interrupt handler */
  65. TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
  66. static lv_disp_buf_t disp_buf;
  67. static lv_color_t buf[LV_HOR_RES_MAX * 10];
  68. static void create_tab1(lv_obj_t * parent);
  69. static void create_tab2(lv_obj_t * parent);
  70. static void create_tab3(lv_obj_t * parent);
  71. lv_obj_t * slider_label;
  72. int screenWidth = 480;
  73. int screenHeight = 320;
  74.  
  75.  
  76.  
  77. #if USE_LV_LOG != 1
  78. /* Serial debugging */
  79. void my_print(lv_log_level_t level, const char * file, uint32_t line, const char * dsc)
  80. {
  81.  
  82. Serial.printf("%s@%d->%s\r\n", file, line, dsc);
  83. delay(100);
  84. }
  85. #endif
  86.  
  87. /* Display flushing */
  88. void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
  89. {
  90. uint16_t c;
  91.  
  92. tft.startWrite(); /* Start new TFT transaction */
  93. tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1)); /* set the working window */
  94. for (int y = area->y1; y <= area->y2; y++) {
  95. for (int x = area->x1; x <= area->x2; x++) {
  96. c = color_p->full;
  97. tft.writeColor(c, 1);
  98. color_p++;
  99. }
  100. }
  101. tft.endWrite(); /* terminate TFT transaction */
  102. lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */
  103. }
  104.  
  105. bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
  106. {
  107. uint16_t touchX, touchY;
  108.  
  109. bool touched = tft.getTouch(&touchX, &touchY, 600);
  110.  
  111. if(!touched)
  112. {
  113. return false;
  114. }
  115.  
  116. if(touchX>screenWidth || touchY > screenHeight)
  117. {
  118. Serial.println("Y or y outside of expected parameters..");
  119. Serial.print("y:");
  120. Serial.print(touchX);
  121. Serial.print(" x:");
  122. Serial.print(touchY);
  123. }
  124. else
  125. {
  126.  
  127. data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
  128.  
  129. /*Save the state and save the pressed coordinate*/
  130. //if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y);
  131.  
  132. /*Set the coordinates (if released use the last pressed coordinates)*/
  133. data->point.x = touchX;
  134. data->point.y = touchY;
  135.  
  136. Serial.print("Data x");
  137. Serial.println(touchX);
  138.  
  139. Serial.print("Data y");
  140. Serial.println(touchY);
  141.  
  142. }
  143.  
  144. return false; /*Return `false` because we are not buffering and no more data to read*/
  145. }
  146.  
  147. /* Interrupt driven periodic handler */
  148. static void lv_tick_handler(void)
  149. {
  150.  
  151. lv_tick_inc(LVGL_TICK_PERIOD);
  152. }
  153.  
  154.  
  155.  
  156. void IRAM_ATTR resetModule() //Function to Reboot ESP through Watchdog
  157. {
  158. ets_printf("reboot durch watchdog\n");
  159. esp_restart();
  160. }
  161.  
  162.  
  163.  
  164. void configureWatchdog()
  165. {
  166. timer = timerBegin(0, 80, true); //timer 0, div 80
  167. timerAttachInterrupt(timer, &resetModule, true); //attach callback
  168. timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us
  169. timerAlarmEnable(timer); //enable interrupt
  170. Serial.println("Watchdog durchlaufen");
  171. }
  172.  
  173.  
  174.  
  175. void FirstStart()
  176. {
  177. Serial.println("Good mooooorning Vieeeetnaaam");
  178. delay(300); // Delay for preventing boot bug
  179. WiFi.mode(WIFI_STA);
  180. WiFi.begin("xxxxxxxx", "xxxxxxxxx"); // Start wifimode
  181. Serial.println("");
  182.  
  183. while (WiFi.status() != WL_CONNECTED) //
  184. {
  185. delay(500);
  186. Serial.print(".");
  187. }
  188. Serial.println("");
  189. Serial.print("IP Address: ");
  190. Serial.println(WiFi.localIP());
  191. Serial.println("Fetching NTP Time");
  192. struct tm local;
  193. configTzTime(TZ_INFO, NTP_SERVER); // Sync systemtime timezone with NTP
  194. getLocalTime(&local, 1000); // Sync local time for 1 seconds
  195. //WiFi.disconnect();
  196. //WiFi.mode(WIFI_OFF); //End wifimode
  197. Serial.println("First start done");
  198. }
  199.  
  200.  
  201.  
  202. void setup() {
  203.  
  204. esp_sleep_wakeup_cause_t wakeup_cause; // Variable for wakeup reason
  205. setenv("TZ", TZ_INFO, 1); // Setting timezone after reset
  206. tzset();
  207.  
  208.  
  209. pinMode (relaisPin, OUTPUT); //switching relais on for 3.3V power (Display + Touch, HX711 Scale, BME Sensor)
  210. digitalWrite (relaisPin, HIGH); //switching relais on for 3.3V power (Display + Touch, HX711 Scale, BME Sensor)
  211. delay(500);
  212. pinMode (relaisPin2, OUTPUT); //switching relais on for 4.1V power (SIM800l GSM Modul)
  213. digitalWrite (relaisPin2, HIGH); //switching relais on for 4.1V power (SIM800l GSM Modul)
  214. delay(500);
  215. pinMode (relaisPin1, OUTPUT); //switching relais on for 5.0V power (HX711 Scale)
  216. digitalWrite (relaisPin1, HIGH); //switching relais on for 5.0V power (HX711 Scale)
  217. delay(500);
  218. pinMode(BUTTON, INPUT_PULLUP); // define mode for tara button
  219. Serial.println("button");
  220. pinMode (4, OUTPUT); // define mode for led display backlight
  221. digitalWrite (4, HIGH); // define mode for led display backlight
  222. delay(500);
  223.  
  224. ledcSetup(10, 5000/*freq*/, 10 /*resolution*/);
  225. ledcAttachPin(32, 10);
  226. analogReadResolution(10);
  227. ledcWrite(10,768);
  228. //const char test = '9' ;
  229. #define MAX_STRING_SIZE 5
  230. float test = 52.4;
  231. char test2[MAX_STRING_SIZE];
  232. snprintf(test2, MAX_STRING_SIZE, "%f", test);
  233.  
  234.  
  235. Serial.begin(115200); /* prepare for possible serial debug */
  236. Serial.println("Setup start");
  237. //configureWatchdog();
  238. ++BootCounter;
  239.  
  240. Serial.println("Going to lv_init");
  241. delay(500);
  242.  
  243.  
  244. lv_init();
  245.  
  246. #if USE_LV_LOG != 0
  247. lv_log_register_print(my_print); /* register print function for debugging */
  248. #endif
  249.  
  250. tft.begin(); /* TFT init */
  251. tft.setRotation(1);
  252.  
  253. uint16_t calData[5] = { 275, 3620, 264, 3532, 1 };
  254. tft.setTouch(calData);
  255.  
  256. lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  257.  
  258. /*Initialize the display*/
  259. lv_disp_drv_t disp_drv;
  260. lv_disp_drv_init(&disp_drv);
  261. disp_drv.hor_res = 320;
  262. disp_drv.ver_res = 240;
  263. disp_drv.flush_cb = my_disp_flush;
  264. disp_drv.buffer = &disp_buf;
  265. lv_disp_drv_register(&disp_drv);
  266.  
  267. lv_indev_drv_t indev_drv;
  268. lv_indev_drv_init(&indev_drv); /*Descriptor of a input device driver*/
  269. indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/
  270. indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/
  271. lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
  272.  
  273.  
  274. /*Initialize the touch pad*/
  275. // lv_indev_drv_t indev_drv;
  276. //lv_indev_drv_init(&indev_drv);
  277. //indev_drv.type = LV_INDEV_TYPE_ENCODER;
  278. //indev_drv.read_cb = read_encoder;
  279. //lv_indev_drv_register(&indev_drv);
  280.  
  281. /*Initialize the graphics library's tick*/
  282. tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
  283.  
  284. //Set the theme..
  285. lv_theme_t * th = lv_theme_material_init(210, NULL); //Set a HUE value and a Font for the Night Theme
  286. lv_theme_set_current(th);
  287.  
  288. lv_obj_t * scr = lv_cont_create(NULL, NULL);
  289. lv_disp_load_scr(scr);
  290.  
  291.  
  292.  
  293.  
  294.  
  295. /*Create a Tab view object*/
  296. lv_obj_t *tabview;
  297. tabview = lv_tabview_create(lv_scr_act(), NULL);
  298.  
  299. /*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/
  300. lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Uebersicht");
  301. lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Visualisierung");
  302. lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Einstellungen");
  303.  
  304.  
  305.  
  306.  
  307. /*Create a normal cell style*/
  308. static lv_style_t style_cell1;
  309. lv_style_copy(&style_cell1, &lv_style_plain);
  310. style_cell1.body.border.width = 2;
  311. style_cell1.body.border.color = LV_COLOR_BLACK;
  312.  
  313. /*Crealte a header cell style*/
  314. static lv_style_t style_cell2;
  315. lv_style_copy(&style_cell2, &lv_style_plain);
  316. style_cell2.body.border.width = 2;
  317. style_cell2.body.border.color = LV_COLOR_BLACK;
  318. style_cell2.body.main_color = LV_COLOR_SILVER;
  319. style_cell2.body.grad_color = LV_COLOR_SILVER;
  320.  
  321. lv_obj_t * table = lv_table_create(tab1, NULL);
  322. lv_table_set_style(table, LV_TABLE_STYLE_CELL1, &style_cell1);
  323. lv_table_set_style(table, LV_TABLE_STYLE_CELL2, &style_cell2);
  324. lv_table_set_style(table, LV_TABLE_STYLE_BG, &lv_style_transp_tight);
  325. lv_table_set_col_cnt(table, 2);
  326. lv_table_set_row_cnt(table, 5);
  327. lv_obj_align(table, NULL, LV_ALIGN_CENTER, -18, 0);
  328.  
  329. /*Make the cells of the first row center aligned */
  330. lv_table_set_cell_align(table, 0, 0, LV_LABEL_ALIGN_CENTER);
  331. lv_table_set_cell_align(table, 0, 1, LV_LABEL_ALIGN_CENTER);
  332.  
  333. /*Make the cells of the first row TYPE = 2 (use `style_cell2`) */
  334. lv_table_set_cell_type(table, 0, 0, 2);
  335. lv_table_set_cell_type(table, 0, 1, 2);
  336.  
  337.  
  338.  
  339. /*Fill the first column*/
  340. lv_table_set_cell_value(table, 0, 0, "Sensor");
  341. lv_table_set_cell_value(table, 1, 0, "Gewicht" );
  342. lv_table_set_cell_value(table, 2, 0, "Temperatur");
  343. lv_table_set_cell_value(table, 3, 0, "Luftfeuchtigkeit");
  344. lv_table_set_cell_value(table, 4, 0, "Luftdruck");
  345. /*Fill the second column*/
  346. lv_table_set_cell_value(table, 0, 1, "Wert");
  347. lv_table_set_cell_value(table, 1, 1, test2 );
  348. lv_table_set_cell_value(table, 2, 1, "0");
  349. lv_table_set_cell_value(table, 3, 1, "0");
  350. lv_table_set_cell_value(table, 4, 1, "0");
  351. //Width of cell
  352. lv_table_set_col_width(table, 0, 130);
  353. // Cell grows not with words
  354. lv_table_set_cell_crop(table, 3, 0, true);
  355.  
  356. /*Add content to the tabs*/
  357. lv_obj_t * label = lv_label_create(tab1, NULL);
  358. lv_label_set_text(label, "");
  359. label = lv_label_create(tab2, NULL);
  360. lv_label_set_text(label, "");
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367. label = lv_label_create(tab3, NULL);
  368. lv_label_set_text(label, "");
  369.  
  370.  
  371.  
  372. // lv_obj_t * label;
  373.  
  374. lv_obj_t * btn1 = lv_btn_create(tab3, NULL);
  375. lv_obj_set_event_cb(btn1, event_handler);
  376. lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
  377.  
  378. label = lv_label_create(btn1, NULL);
  379. lv_label_set_text(label, "Deepsleep");
  380.  
  381. lv_obj_t * btn2 = lv_btn_create(tab3, NULL);
  382. lv_obj_set_event_cb(btn2, event_handler);
  383. lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
  384. lv_btn_set_toggle(btn2, true);
  385. lv_btn_toggle(btn2);
  386. lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT);
  387.  
  388. label = lv_label_create(btn2, NULL);
  389. lv_label_set_text(label, "Handy Nr.");
  390.  
  391.  
  392.  
  393. lv_coord_t w = lv_page_get_scrl_width(tab2);
  394.  
  395. lv_obj_t * chart = lv_chart_create(tab2, NULL);
  396. lv_chart_set_type(chart, LV_CHART_TYPE_AREA);
  397. lv_obj_set_size(chart, w / 1.5, lv_disp_get_ver_res(NULL) / 1.5);
  398. lv_obj_set_pos(chart, LV_DPI / 10, LV_DPI / 10);
  399. lv_chart_series_t * s1 = lv_chart_add_series(chart, LV_COLOR_RED);
  400. lv_chart_set_next(chart, s1, 30);
  401. lv_chart_set_next(chart, s1, 20);
  402. lv_chart_set_next(chart, s1, 10);
  403. lv_chart_set_next(chart, s1, 12);
  404. lv_chart_set_next(chart, s1, 20);
  405. lv_chart_set_next(chart, s1, 27);
  406. lv_chart_set_next(chart, s1, 35);
  407. lv_chart_set_next(chart, s1, 55);
  408. lv_chart_set_next(chart, s1, 70);
  409. lv_chart_set_next(chart, s1, test);
  410.  
  411.  
  412.  
  413. Serial.println("Start Nr.: " + String(BootCounter));
  414. SerialAT.begin(9600, SERIAL_8N1);
  415. delay(1000);
  416. Serial.println("Initializing...SIM800L GSM Modul");
  417. delay(1000);
  418.  
  419. SerialAT.println("AT"); //Once the handshake test is successful, it will back to OK
  420. updateSerialMon();
  421. SerialAT.println("AT+CSQ"); //Once the handshake test is successful, it will back to OK
  422. updateSerialMon();
  423. SerialAT.println("AT+CREG?"); //Once the handshake test is successful, it will back to OK
  424. updateSerialMon();
  425. SerialAT.println("AT+COPS?"); //Once the handshake test is successful, it will back to OK
  426. updateSerialMon();
  427. Serial.println("GSM DONE");
  428.  
  429.  
  430. wakeup_cause = esp_sleep_get_wakeup_cause(); // fetching wakeupreason
  431. if (wakeup_cause != 3) FirstStart(); // new startup after manual reset
  432. Serial.println("Scale begin (void setup) ");
  433.  
  434. Serial.println("Scale Done (void setup)");
  435. // Serial.println("SHT21 test");
  436. //SHT21.begin();
  437.  
  438. delayTime = 1000;
  439. bool status;
  440. // default settings
  441. // (you can also pass in a Wire library object like &Wire2)
  442. Serial.println("Begin I2C BME Sensor (setup)");
  443. status = bme.begin(0x76);
  444. Serial.println("BME started(setup)");
  445. if (!status) {
  446. Serial.println("Could not find a valid BME280 sensor, check wiring!");
  447. while (1);
  448. }
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457. Serial.println("void setup done");
  458.  
  459.  
  460.  
  461.  
  462. }
  463.  
  464. void loop() {
  465.  
  466.  
  467. lv_task_handler(); /* let the GUI do its work */
  468. delay(5);
  469. // timerWrite(timer, 0);
  470. //tm local;
  471. // getLocalTime(&local);
  472. // Serial.println(&local, "Date: %d.%m.%y Local Time from NTP: %H:%M:%S"); // Setting format for print in serial monitor
  473.  
  474. button(); // calling tare button function
  475.  
  476. wiegen(); // calling weight function
  477.  
  478. klima(); // calling temprature and humidity and pressure function
  479.  
  480. Serial.println("Entering Deepsleepmode \r\n \r\n");
  481. Serial.println("Good night sweet prince :* \r\n \r\n");
  482. digitalWrite (relaisPin, LOW);
  483. digitalWrite (relaisPin1, LOW);
  484. digitalWrite (relaisPin2, LOW);
  485. Serial.println("Display OUT");
  486. digitalWrite (4, LOW);
  487.  
  488. esp_sleep_enable_timer_wakeup(SleepTime * ConversionSeconds); // setting time interval for deep sleep
  489. esp_deep_sleep_start(); // starting deep sleep mode
  490. }
  491.  
  492. void button ()
  493. {
  494. Serial.println("Bitte drücken Sie den Tara knopf für 5 sekunden");
  495. delay(500);
  496. buttonState = digitalRead(BUTTON); // define variable for tare button
  497. delay(100);
  498. Serial.println(buttonState); // print 0 if button is pressed otherwise 1
  499. Tare = (scale.get_units(10)); // saves average from 10 measurements
  500. Serial.println(Tare); // saves average from 10 measurements
  501. preferences.begin("Tara", false); // open folder on esp to save tare value to be reset safe
  502. preferences.putFloat("TaraGewicht", Tare); // saving tare value
  503. preferences.end(); // closing folder
  504. }
  505. }
  506.  
  507. void wiegen()
  508. {
  509. Serial.print("Scale set scale (void wiegen)");
  510. scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); // beginig scale hx711 connection with pins from define
  511. Serial.print("Scale begin (void wiegen)");
  512. scale.set_scale(28633.1136); // Scalefactor of the scale
  513. Serial.print("Scale Power UP (void wiegen)");
  514. scale.power_up(); //HX711 ADC booting
  515. float gewicht = 0; // declaration of variable for weight
  516. Serial.print("Einzelablesung:\t");
  517. Serial.print(scale.get_units()); // reading actual wieght without tare result
  518. preferences.begin("Tara", false); // opening a folder for saving and writing tara
  519. Tare = preferences.getFloat("TaraGewicht", 0); // den Geschützten Wert aufrufen und in der Variablen Tare speichern
  520. gewicht = (scale.get_units(10)); // save the average from 10 meassurements
  521. gewicht = (gewicht - Tare); // calculate actual weight
  522. Serial.print(gewicht, 1); // printing result
  523. Serial.print("\t| Schnitt:\t");
  524. Serial.print(gewicht, 2); // printing result
  525. Serial.print("\t| Schnitt:\t");
  526. Serial.println(gewicht, 3); // printing result
  527. preferences.end(); // close folder
  528. scale.power_down(); // put the ADC in sleep mode
  529.  
  530. if (gewicht < 0) //if the result saved in gewicht is to low the alert sms function will be called
  531. {
  532. sms_weight ();
  533. }
  534. }
  535.  
  536. void sms_weight ()
  537. {
  538.  
  539. delay(3000);
  540. SerialAT.println("AT+CSQ"); //Once the handshake test is successful, it will back to OK
  541. updateSerialMon();
  542. SerialAT.println("AT+CMGF=1"); // Configuring TEXT mode
  543. updateSerialMon();
  544. SerialAT.println("AT+CMGS=\"+xxxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
  545. updateSerialMon();
  546. SerialAT.println("ALAAARM!!!Bees have left the Building...Powered by ESP32"); //text content
  547. updateSerialMon();
  548. SerialAT.write(26);
  549. delay(4000);
  550. }
  551.  
  552.  
  553. void klima ()
  554. {
  555. float temperatur = bme.readTemperature(); //define variables for enviroment measurement
  556. float luftdruck = bme.readPressure() / 100.0F; //define variables for enviroment measurement
  557. float luftfeuchtigkeit = bme.readHumidity(); //define variables for enviroment measurement
  558. //float g_temperature = (SHT21.getTemperature()); //define variables for enviroment measurement
  559.  
  560. Serial.print("Temperature = ");
  561. Serial.print(temperatur);
  562. Serial.println(" °C");
  563.  
  564. Serial.print("Pressure = ");
  565. Serial.print(luftdruck);
  566. Serial.println(" hPa");
  567.  
  568. Serial.print("Humidity = ");
  569. Serial.print(luftfeuchtigkeit);
  570. Serial.println(" %");
  571.  
  572.  
  573. // Serial.print("Case Temperature = ");
  574. // Serial.print(g_temperature);
  575. //Serial.println(" *C");
  576.  
  577. Serial.println();
  578. delay(500);
  579. //if connected make a http connection to a php skript on a server to save enviroment values to a mysql database
  580. if ((WiFi.status() == WL_CONNECTED)) {
  581. HTTPClient http;
  582.  
  583. float temperatur = bme.readTemperature();
  584. float luftdruck = bme.readPressure() / 100.0F;
  585. float luftfeuchtigkeit = bme.readHumidity();
  586.  
  587. String url;
  588. url += "xxxxxxxxxxx/writemysql.php?temp=";
  589. url += String(temperatur);
  590. url += "&luftd=";
  591. url += String(luftdruck);
  592. url += "&luftf=";
  593. url += String(luftfeuchtigkeit);
  594.  
  595. http.begin(url);
  596. http.GET();
  597. http.end();
  598. delay(1000);
  599. WiFi.disconnect(true);
  600. } WiFi.mode(WIFI_OFF); //End wifimode
  601. }
  602.  
  603.  
  604.  
  605. void updateSerialMon()
  606. {
  607. delay(500);
  608. while (Serial.available())
  609. {
  610. SerialAT.write(SerialMon.read());//Forward what Serial received to Software Serial Port
  611. }
  612. while(SerialAT.available())
  613. {
  614. SerialMon.write(SerialAT.read());//Forward what Software Serial received to Serial Port
  615. }
  616.  
  617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement