diff --git a/bGeigieCast.code-workspace b/bGeigieCast.code-workspace deleted file mode 100644 index 362d7c2..0000000 --- a/bGeigieCast.code-workspace +++ /dev/null @@ -1,7 +0,0 @@ -{ - "folders": [ - { - "path": "." - } - ] -} \ No newline at end of file diff --git a/bgeigiecast/api_connector.cpp b/bgeigiecast/api_connector.cpp index dab7c3f..ceab900 100644 --- a/bgeigiecast/api_connector.cpp +++ b/bgeigiecast/api_connector.cpp @@ -13,8 +13,7 @@ ApiConnector::ApiConnector(LocalStorage& config) : Handler(), _config(config), - _last_success_send(0), - _current_default_response(e_api_reporter_idle) { + _payload("") { } bool ApiConnector::time_to_send(unsigned offset) const { @@ -45,7 +44,6 @@ bool ApiConnector::activate(bool retry) { } void ApiConnector::deactivate() { - _current_default_response = e_api_reporter_idle; WiFiConnection::disconnect_wifi(); } @@ -54,51 +52,52 @@ int8_t ApiConnector::handle_produced_work(const worker_map_t& workers) { if(!geigie_connector || !geigie_connector->is_fresh()) { // No fresh data - return _current_default_response; + return e_handler_idle; } if(!time_to_send()) { if (time_to_send(6000)) { - // almost time to send, start wifi if not connected yet + // almost time to send, start Wi-Fi if not connected yet activate(true); } - return _current_default_response; + return e_handler_idle; } const auto& reading = geigie_connector->get_data(); - if(reading.valid_reading()) { - if (_config.get_use_home_location() && !reading - .near_coordinates(_config.get_home_latitude(), _config.get_home_longitude(), HOME_LOCATION_PRECISION_KM)) { - // Reading not near home location - DEBUG_PRINTLN("Reading not near configured home location"); - return _current_default_response; - } - const unsigned long time_at_send = millis(); - _current_default_response = send_reading(reading); + if(!reading.valid_reading()) { + return e_handler_idle; + } - if (_current_default_response == e_api_reporter_send_success) { - _last_success_send = time_at_send; - } + if (_config.get_use_home_location() && !reading + .near_coordinates(_config.get_home_latitude(), _config.get_home_longitude(), HOME_LOCATION_PRECISION_KM)) { + // Reading not near home location + DEBUG_PRINTLN("Reading not near configured home location"); + return e_handler_idle; } - return _current_default_response; -} -ApiConnector::ApiHandlerStatus ApiConnector::send_reading(const Reading& reading) { + // All checks good, prep send data + + if(!reading_to_json(reading, _payload)) { + DEBUG_PRINTLN("Unable to send, reading to payload conversion error"); + return e_api_reporter_error_to_json; + } if(!WiFi.isConnected() && !activate(true)) { DEBUG_PRINTLN("Unable to send, lost connection"); return e_api_reporter_error_not_connected; } + return start_task("api_send", 2048 * 4, 3, 0); +} + + +int8_t ApiConnector::handle_async() { + HTTPClient http; char url[100]; - sprintf(url, - "%s?api_key=%s&%s", - API_MEASUREMENTS_ENDPOINT, - _config.get_api_key(), - _config.get_use_dev() ? "test=true" : ""); + sprintf(url, "%s?api_key=%s", API_MEASUREMENTS_ENDPOINT, _config.get_api_key()); //Specify destination for HTTP request if(!http.begin(url)) { @@ -107,34 +106,27 @@ ApiConnector::ApiHandlerStatus ApiConnector::send_reading(const Reading& reading return e_api_reporter_error_remote_not_available; } - char payload[200]; - - if(!reading_to_json(reading, payload)) { - return e_api_reporter_error_to_json; - } - - char content_length[5]; - - sprintf(content_length, "%d", strlen(payload)); + http.setUserAgent(HEADER_API_USER_AGENT); http.addHeader("Host", API_HOST); http.addHeader("Content-Type", HEADER_API_CONTENT_TYPE); - http.addHeader("User-Agent", HEADER_API_USER_AGENT); - http.addHeader("Content-Length", content_length); - int httpResponseCode = http.POST(payload); + int httpResponseCode = http.POST(_payload); + + auto now = millis(); String response = http.getString(); - DEBUG_PRINTF("POST complete, status %d\r\nrepsonse: \r\n\r\n%s\r\n\r\n", httpResponseCode, response.c_str()); + DEBUG_PRINTF("POST complete, status %d\r\nresponse: \r\n\r\n%s\r\n\r\n", httpResponseCode, response.c_str()); http.end(); //Free resources if (!_config.get_wifi_server() && _config.get_send_frequency() != e_api_send_frequency_5_sec) { - // Disconnect from wifi between readings (not needed when sending every 5 seconds) + // Disconnect from Wi-Fi between readings (not needed when sending every 5 seconds) WiFiConnection::disconnect_wifi(); } switch(httpResponseCode) { case 200 ... 204: + _last_success_send = now; return e_api_reporter_send_success; case 400: return e_api_reporter_error_server_rejected_post_400; @@ -172,3 +164,4 @@ bool ApiConnector::reading_to_json(const Reading& reading, char* out) { return true; } + diff --git a/bgeigiecast/api_connector.h b/bgeigiecast/api_connector.h index 86e0684..d9e649e 100644 --- a/bgeigiecast/api_connector.h +++ b/bgeigiecast/api_connector.h @@ -21,7 +21,6 @@ class ApiConnector : public Handler { * Collection of statuses for the api data handling, default is idle. */ enum ApiHandlerStatus { - e_api_reporter_idle, e_api_reporter_send_success, e_api_reporter_error_to_json, e_api_reporter_error_not_connected, @@ -66,18 +65,17 @@ class ApiConnector : public Handler { bool reading_to_json(const Reading& reading, char* out); - private: - /** * Send a reading to the API - * @param reading: reading to send - * @return: true if the API call was successful + * @return: status */ - ApiHandlerStatus send_reading(const Reading& reading); + int8_t handle_async() override; + + private: LocalStorage& _config; + char _payload[200]; uint32_t _last_success_send; - ApiHandlerStatus _current_default_response; }; #endif //BGEIGIECAST_APICONNECTOR_H diff --git a/bgeigiecast/configuration_server.cpp b/bgeigiecast/configuration_server.cpp index dc92a70..0132cda 100644 --- a/bgeigiecast/configuration_server.cpp +++ b/bgeigiecast/configuration_server.cpp @@ -85,8 +85,7 @@ void ConfigWebServer::add_urls() { _config.get_wifi_ssid(), _config.get_wifi_password(), _config.get_api_key(), - _config.get_send_frequency(), - _config.get_use_dev() + _config.get_send_frequency() )); }); @@ -170,9 +169,6 @@ void ConfigWebServer::handle_save() { if(_server.hasArg(FORM_NAME_API_KEY)) { _config.set_api_key(_server.arg(FORM_NAME_API_KEY).c_str(), false); } - if(_server.hasArg(FORM_NAME_USE_DEV)) { - _config.set_use_dev(_server.arg(FORM_NAME_USE_DEV) == "1", false); - } if(_server.hasArg(FORM_NAME_SEND_FREQ)){ _config.set_send_frequency(_server.arg(FORM_NAME_SEND_FREQ).toInt(), false); } diff --git a/bgeigiecast/http_pages.cpp b/bgeigiecast/http_pages.cpp index c17bced..cfd83e7 100644 --- a/bgeigiecast/http_pages.cpp +++ b/bgeigiecast/http_pages.cpp @@ -271,8 +271,7 @@ const char* HttpPages::get_config_connection_page( const char* wifi_ssid, const char* wifi_password, const char* api_key, - uint8_t send_frequency, - bool use_dev + uint8_t send_frequency ) { char ssid[20]; sprintf(ssid, ACCESS_POINT_SSID, device_id); @@ -324,18 +323,6 @@ const char* HttpPages::get_config_connection_page( "We suggest sending data every 5 minutes for stationary sensors" "" - // Use dev - "" - "" - "" - "" - "Use development for testing purposes. Double check your API key when changing this option!" - "" - "
" "" "" @@ -349,8 +336,6 @@ const char* HttpPages::get_config_connection_page( send_frequency == ApiConnector::e_api_send_frequency_5_sec ? "checked" : "", send_frequency == ApiConnector::e_api_send_frequency_1_min ? "checked" : "", send_frequency == ApiConnector::e_api_send_frequency_5_min ? "checked" : "", - use_dev ? "" : "checked", - use_dev ? "checked" : "", display_success ? success_message : "" ); } diff --git a/bgeigiecast/http_pages.h b/bgeigiecast/http_pages.h index 9c2e510..76ae935 100644 --- a/bgeigiecast/http_pages.h +++ b/bgeigiecast/http_pages.h @@ -75,8 +75,7 @@ class HttpPages { const char* wifi_ssid, const char* wifi_password, const char* api_key, - uint8_t send_frequency, - bool use_dev + uint8_t send_frequency ); /** diff --git a/bgeigiecast/local_storage.cpp b/bgeigiecast/local_storage.cpp index c0f7e92..29a910e 100644 --- a/bgeigiecast/local_storage.cpp +++ b/bgeigiecast/local_storage.cpp @@ -7,9 +7,6 @@ #include "bgeigie_connector.h" #include "api_connector.h" -#define D_SAVED_STATE Controller::k_savable_MobileMode -#define D_SEND_FREQUENCY ApiConnector::e_api_send_frequency_5_min - const char* memory_name = "data"; // Keys for config @@ -18,7 +15,6 @@ const char* key_ap_password = "ap_password"; const char* key_wifi_ssid = "wifi_ssid"; const char* key_wifi_password = "wifi_password"; const char* key_api_key = "api_key"; -const char* key_use_dev = "use_dev"; const char* key_send_frequency = "send_frequency"; const char* key_led_color_blind = "led_color_blind"; const char* key_wifi_server = "wifi_server"; @@ -37,7 +33,6 @@ LocalStorage::LocalStorage() : _wifi_ssid(""), _wifi_password(""), _api_key(""), - _use_dev(D_USE_DEV_SERVER), _send_frequency(D_SEND_FREQUENCY), _led_color_blind(D_LED_COLOR_BLIND), _led_color_intensity(D_LED_COLOR_INTENSITY), @@ -57,7 +52,6 @@ void LocalStorage::reset_defaults() { set_wifi_ssid(D_WIFI_SSID, true); set_wifi_password(D_WIFI_PASSWORD, true); set_api_key(D_APIKEY, true); - set_use_dev(D_USE_DEV_SERVER, true); set_send_frequency(D_SEND_FREQUENCY, true); set_led_color_blind(D_LED_COLOR_BLIND, true); set_led_color_intensity(D_LED_COLOR_INTENSITY, true); @@ -107,10 +101,6 @@ bool LocalStorage::get_wifi_server() const { return _wifi_server; } -bool LocalStorage::get_use_dev() const { - return _use_dev; -} - uint8_t LocalStorage::get_send_frequency() const { return _send_frequency; } @@ -195,18 +185,6 @@ void LocalStorage::set_api_key(const char* api_key, bool force) { } } -void LocalStorage::set_use_dev(bool use_dev, bool force) { - if(force || (use_dev != _use_dev)) { - if(_memory.begin(memory_name)) { - _use_dev = use_dev; - _memory.putBool(key_use_dev, use_dev); - _memory.end(); - } else { - DEBUG_PRINTLN("unable to save new value for use_dev"); - } - } -} - void LocalStorage::set_send_frequency(uint8_t send_frequency, bool force) { if(force || (send_frequency != _send_frequency)) { if(_memory.begin(memory_name)) { @@ -343,7 +321,6 @@ bool LocalStorage::activate(bool) { if(_memory.getString(key_api_key, _api_key, CONFIG_VAL_MAX) == 0) { strcpy(_api_key, D_APIKEY); } - _use_dev = _memory.getBool(key_use_dev, D_USE_DEV_SERVER); _send_frequency = _memory.getUChar(key_send_frequency, D_SEND_FREQUENCY); _led_color_blind = _memory.getBool(key_led_color_blind, D_LED_COLOR_BLIND); _led_color_intensity = _memory.getUChar(key_led_color_intensity, D_LED_COLOR_INTENSITY); diff --git a/bgeigiecast/local_storage.h b/bgeigiecast/local_storage.h index 9e2ac3f..a6a25a6 100644 --- a/bgeigiecast/local_storage.h +++ b/bgeigiecast/local_storage.h @@ -26,7 +26,6 @@ class LocalStorage : public Handler { virtual const char* get_wifi_ssid() const final; virtual const char* get_wifi_password() const final; virtual const char* get_api_key() const final; - virtual bool get_use_dev() const final; virtual uint8_t get_send_frequency() const final; virtual bool is_led_color_blind() const final; virtual uint8_t get_led_color_intensity() const final; @@ -43,7 +42,6 @@ class LocalStorage : public Handler { virtual void set_wifi_ssid(const char* wifi_ssid, bool force); virtual void set_wifi_password(const char* wifi_password, bool force); virtual void set_api_key(const char* api_key, bool force); - virtual void set_use_dev(bool use_dev, bool force); virtual void set_send_frequency(uint8_t send_frequency, bool force); virtual void set_led_color_blind(bool led_color_blind, bool force); virtual void set_led_color_intensity(uint8_t led_color_intensity, bool force); @@ -78,7 +76,6 @@ class LocalStorage : public Handler { // API config (to connect to the API) char _api_key[CONFIG_VAL_MAX]; - bool _use_dev; uint8_t _send_frequency; // RGB LED config diff --git a/bgeigiecast/bgeigiecast.ino b/bgeigiecast/main.cpp similarity index 96% rename from bgeigiecast/bgeigiecast.ino rename to bgeigiecast/main.cpp index df0b20c..0c5b99b 100644 --- a/bgeigiecast/bgeigiecast.ino +++ b/bgeigiecast/main.cpp @@ -50,14 +50,12 @@ Contact: Jelle Bouwhuis (email jellebouwhuis@outlook.com) and Rob Oudendijk (rob #include "configuration_server.h" #include "mode_led.h" -#ifndef BGEIGIE_SERIAL -#define BGEIGIE_SERIAL Serial2 -#endif +HardwareSerial& bGeigieSerialConnection = Serial2; LocalStorage config; // Workers -BGeigieConnector bgeigie_connector(BGEIGIE_SERIAL); +BGeigieConnector bgeigie_connector(bGeigieSerialConnection); ConfigWebServer config_server(config); Button mode_button(MODE_BUTTON_PIN); @@ -140,8 +138,8 @@ void setup() { /// Hardware configurations // Start serial connection to bGeigie controller - BGEIGIE_SERIAL.setRxBufferSize(1024); - BGEIGIE_SERIAL.begin(BGEIGIE_CONNECTION_BAUD); + bGeigieSerialConnection.setRxBufferSize(1024); + bGeigieSerialConnection.begin(BGEIGIE_CONNECTION_BAUD); // Set gpio pin configurations gpio_config_t io_conf{ diff --git a/bgeigiecast/mode_led.cpp b/bgeigiecast/mode_led.cpp index 9311727..64d0c51 100644 --- a/bgeigiecast/mode_led.cpp +++ b/bgeigiecast/mode_led.cpp @@ -30,8 +30,8 @@ ModeLED::ModeLED(LocalStorage& config) : {{127, 000, 127}, {127, 000, 127}}, // config {{000, 100, 255}, {000, 100, 255}}, // mobile {{000, 255, 000}, {000, 255, 000}}, // fixed_connected - {{127, 127, 000}, {127, 127, 000}}, // fixed_soft_error - {{255, 000, 000}, {255, 000, 000}}, // fixed_hard_error + {{127, 127, 000}, {127, 127, 000}}, // fixed_connection_error + {{255, 000, 000}, {255, 000, 000}}, // nano_error } { } @@ -47,8 +47,7 @@ void ModeLED::set_color(ModeLED::ModeColor _color) { static ModeColor _last = mode_color_off; if(_color != _last) { _last = _color; - DEBUG_PRINT("Changed LED to "); - DEBUG_PRINTLN(_color); +// DEBUG_PRINTF("Changed LED to %d\n", _color); set(_config.is_led_color_blind() ? _colorTypes[_color].color_blind : _colorTypes[_color].normal); } } @@ -133,6 +132,10 @@ void ModeLED::handle_report(const worker_map_t& workers, const handler_map_t& ha return; } switch(handlers.at(k_handler_api_reporter)->get_status()) { + case ApiConnector::e_handler_processing: + /// Fixed mode - Async sending to api, blink furiously + set_values(mode_color_fixed_connected, 5); + return; case ApiConnector::e_api_reporter_error_not_connected: /// Fixed mode - Lost connection to wifi, blink connected again set_values(mode_color_fixed_connected, 1, 25); @@ -146,12 +149,12 @@ void ModeLED::handle_report(const worker_map_t& workers, const handler_map_t& ha set_values(mode_color_fixed_soft_error); return; case ApiConnector::e_api_reporter_send_success: - default: /// Fixed mode - All good and connected set_values(mode_color_fixed_connected); return; + default: + return; } - return; } case SystemStateId::k_state_ResetState: /// Reset - Display red because its least used diff --git a/bgeigiecast/sm_c_concrete_states.h b/bgeigiecast/sm_c_concrete_states.h index 5b90f2b..03e6731 100644 --- a/bgeigiecast/sm_c_concrete_states.h +++ b/bgeigiecast/sm_c_concrete_states.h @@ -102,4 +102,13 @@ class ResetState : public ControllerState { void handle_event(Event_enum event_id) override; }; + +extern InitializeState InitializeState_i; +extern InitReadingState InitReadingState_i; +extern PostInitializeState PostInitializeState_i; +extern ConfigurationModeState ConfigurationModeState_i; +extern MobileModeState MobileModeState_i; +extern FixedModeState FixedModeState_i; +extern ResetState ResetState_i; + #endif //BGEIGIECAST_SM_C_CONCRETE_STATES_H diff --git a/bgeigiecast/user_config.h b/bgeigiecast/user_config.h index 7bb325b..1385ecc 100644 --- a/bgeigiecast/user_config.h +++ b/bgeigiecast/user_config.h @@ -1,7 +1,7 @@ #ifndef USER_CONFIG_H #define USER_CONFIG_H -#define BGEIGIECAST_VERSION "1.4" +#define BGEIGIECAST_VERSION "1.5" /** System config **/ #define DEBUG_BAUD 115200 @@ -43,12 +43,13 @@ /** Default ESP configurations **/ #define D_DEVICE_ID 0 #define D_ACCESS_POINT_PASSWORD "safecast" -#define D_WIFI_SSID "KittyWood LTE2" -#define D_WIFI_PASSWORD "schatjeyuka" -#define D_APIKEY "q1LKu7RQ8s5pmyxunnDW " -#define D_USE_DEV_SERVER false +#define D_WIFI_SSID "your_wifi_ssid" +#define D_WIFI_PASSWORD "yourwifipassword" +#define D_APIKEY "" #define D_LED_COLOR_BLIND false #define D_LED_COLOR_INTENSITY 30 #define D_WIFI_SERVER false +#define D_SAVED_STATE Controller::k_savable_MobileMode +#define D_SEND_FREQUENCY ApiConnector::e_api_send_frequency_5_min #endif \ No newline at end of file diff --git a/firmware/README.md b/firmware/README.md new file mode 100644 index 0000000..7aa2d08 --- /dev/null +++ b/firmware/README.md @@ -0,0 +1,8 @@ +# bGeigieCast firmware + +## bGeigieCast +This firmware is for the old hardware versions, without M5 stamp + +## stampS3 +This firmware is for the newer hardware versions, _with_ M5 stamp + diff --git a/firmware/firmware-1.2.bin b/firmware/bGeigieCast/firmware-1.2.bin similarity index 100% rename from firmware/firmware-1.2.bin rename to firmware/bGeigieCast/firmware-1.2.bin diff --git a/firmware/firmware-1.2.zip b/firmware/bGeigieCast/firmware-1.2.zip similarity index 100% rename from firmware/firmware-1.2.zip rename to firmware/bGeigieCast/firmware-1.2.zip diff --git a/firmware/firmware-1.3.bin b/firmware/bGeigieCast/firmware-1.3.bin similarity index 100% rename from firmware/firmware-1.3.bin rename to firmware/bGeigieCast/firmware-1.3.bin diff --git a/firmware/bGeigieCast/firmware-1.5.bin b/firmware/bGeigieCast/firmware-1.5.bin new file mode 100644 index 0000000..24e40a2 Binary files /dev/null and b/firmware/bGeigieCast/firmware-1.5.bin differ diff --git a/firmware/firmware 1.4.bin b/firmware/stampS3/firmware-1.4.bin similarity index 100% rename from firmware/firmware 1.4.bin rename to firmware/stampS3/firmware-1.4.bin diff --git a/firmware/stampS3/firmware-1.5.bin b/firmware/stampS3/firmware-1.5.bin new file mode 100644 index 0000000..9640159 Binary files /dev/null and b/firmware/stampS3/firmware-1.5.bin differ diff --git a/platformio.ini b/platformio.ini index c0c62c9..a14a548 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [platformio] src_dir = bgeigiecast -default_envs = bGeigieCast-stamp-pico +default_envs = bGeigieCast-stamps3 [env] platform = espressif32 @@ -23,7 +23,7 @@ test_ignore = test_state_machine test_stability lib_deps = - claypuppet/SensorReporter@^0.3.1 + claypuppet/SensorReporter@^0.6.2 [env:bGeigieCast] board = esp32doit-devkit-v1 @@ -31,9 +31,6 @@ upload_speed = 115200 [env:bGeigieCast-stamps3] -platform_packages = - ; from https://github.com/espressif/arduino-esp32/issues/8185 / https://github.com/espressif/arduino-esp32/pull/8187 - framework-arduinoespressif32@https://github.com/bsergei/arduino-esp32.git#issue-8185 board = m5stack-stamps3 lib_deps = ${env.lib_deps} @@ -49,9 +46,6 @@ build_flags = [env:bGeigieCast-stamp-pico] -platform_packages = - ; Using arduino-esp32 master for latest pico variant - framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git board = m5stack-atom board_build.variant = m5stack_stamp_pico lib_deps = @@ -62,9 +56,8 @@ build_flags = -D USE_FASTLED -D FASTLED_PIN=27 -D MODE_BUTTON_PIN=39 - -D BGEIGIE_SERIAL=Serial - -D SOC_RX0=3 - -D SOC_TX0=1 + -D RX2=3 + -D TX2=1 [env:wrover] diff --git a/temp/main.cpp b/temp/main.cpp deleted file mode 100644 index c935559..0000000 --- a/temp/main.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* bGeigieNano Xbee-ESP32 is a addon for bGeigieNano to be used as a fixed sensor device. Harware is a Xbee socket with ESP32 and some extra compants on it. - * Copyright (c) 2019, Safecast - - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -History Versions: - -Contact:Jelle Bouwhuis (email jellebouwhuis@outlook.com) and Rob Oudendijk (rob@yr-design.biz) - - */ - -void setup() -{ - // put your setup code here, to run once: -} - -void loop() -{ - // put your main code here, to run repeatedly: -} \ No newline at end of file diff --git a/temp/tasks.cpp b/temp/tasks.cpp deleted file mode 100644 index 01a41d7..0000000 --- a/temp/tasks.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -void taskOne(void *parameter) { - for (int i = 0; i < 10; i++) { - - Serial.println("Hello from task 1"); - delay(1000); - } - Serial.println("Ending task 1"); - vTaskDelete(NULL); -} - -void taskTwo(void *parameter) { - for (int i = 0; i < 10; i++) { - Serial.println("Hello from task 2"); - delay(1000); - } - Serial1.println("Ending task 2"); - vTaskDelete(NULL); -} - -void setup() { - Serial.begin(112500); - delay(1000); - xTaskCreate(taskOne, /* Task function. */ - "TaskOne", /* String with name of task. */ - 10000, /* Stack size in bytes. */ - NULL, /* Parameter passed as input of the task */ - 1, /* Priority of the task. */ - NULL); /* Task handle. */ - xTaskCreate(taskTwo, /* Task function. */ - "TaskTwo", /* String with name of task. */ - 10000, /* Stack size in bytes. */ - NULL, /* Parameter passed as input of the task */ - 1, /* Priority of the task. */ - NULL); /* Task handle. */ -} - -void loop() { delay(1000); } diff --git a/temp/webserver 2.cpp b/temp/webserver 2.cpp deleted file mode 100644 index 87bf9a6..0000000 --- a/temp/webserver 2.cpp +++ /dev/null @@ -1,195 +0,0 @@ -//* Made for testing RGB LED on IO32,IO33 and IO25. 2019-02-23 rob - -#include - -#include - -// Please change to Wi-Fi to use and its password -const char *ssid = ""; -const char *password = ""; - -// use port 80 -WiFiServer server(80); - -// Variable to store the HTTP request -String header; - -// Variable used to set value -String valueString = String(5); -int pos1 = 0; -int pos2 = 0; - -//ledpin -const int ledR = A18; -const int ledG = A4; -const int ledB = A5; - -void setup() -{ - //ledc setting - //R - ledcSetup(0, 12800, 8); - // Connect ledR to channel 0 - ledcAttachPin(ledR, 0); - - //G - ledcSetup(1, 12800, 8); - // Connect ledG to channel 1 - ledcAttachPin(ledG, 1); - - //B - ledcSetup(2, 12800, 8); - // Connect ledB to channel 2 - ledcAttachPin(ledB, 2); - - Serial.begin(115200); - - // Connect to Wi-Fi - Serial.print("Connecting to "); - Serial.println(ssid); - WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) - { - delay(500); - Serial.print("."); - } - // Display local IP (Access this IP from smartphone etc.) - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - server.begin(); -} - -void loop() -{ - WiFiClient client = server.available(); // Listen for incoming clients - - if (client) - { // If a new client connects, - Serial.println("New Client."); // print a message out in the serial port - String currentLine = ""; // make a String to hold incoming data from the client - while (client.connected()) - { // loop while the client's connected - if (client.available()) - { // if there's bytes to read from the client, - char c = client.read(); // read a byte, then - Serial.write(c); // print it out the serial monitor - header += c; - if (c == '\n') - { // if the byte is a newline character - // if the current line is blank, you got two newline characters in a row. - // that's the end of the client HTTP request, so send a response: - if (currentLine.length() == 0) - { - // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) - // and a content-type so the client knows what's coming, then a blank line: - client.println("HTTP/1.1 200 OK"); - client.println("Content-type:text/html"); - client.println("Connection: close"); - client.println(); - - // Display the HTML web page - client.println(""); - client.println("ESP32 RGB LED controller"); - client.println(""); - // CSS to style the on/off buttons - // Feel free to change the background-color and font-size attributes to fit your preferences - client.println(""); - client.println(""); - - // Web Page - client.println("

ESP32 bGeigieNano RGBLED

"); - //R slide bar - client.println("

Brightness of R:

"); - client.println(""); - //G slide bar - client.println("

Brightness of G:

"); - client.println(""); - //B slide bar - client.println("

Brightness of B:

"); - client.println(""); - - client.println(""); - - client.println(""); - - // Processing part of HTTP request - //GET /?value=180& HTTP/1.1 - // Convert the value of R to the output of led - if (header.indexOf("GET /?valueR=") >= 0) - { - pos1 = header.indexOf('='); - pos2 = header.indexOf('&'); - valueString = header.substring(pos1 + 1, pos2); - - // LED lit with valueString value - ledcWrite(0, valueString.toInt()); - Serial.println(valueString); - } - // Convert the value of G to the output of led - if (header.indexOf("GET /?valueG=") >= 0) - { - pos1 = header.indexOf('='); - pos2 = header.indexOf('&'); - valueString = header.substring(pos1 + 1, pos2); - - // LED lit with valueString value - ledcWrite(1, valueString.toInt()); - Serial.println(valueString); - } - - // Convert the value of B to led output - if (header.indexOf("GET /?valueB=") >= 0) - { - pos1 = header.indexOf('='); - pos2 = header.indexOf('&'); - valueString = header.substring(pos1 + 1, pos2); - - // LED lit with valueString value - ledcWrite(2, valueString.toInt()); - Serial.println(valueString); - } - // End of HTTP response client.println(); - // Break out of the while loop - break; - } - else - { - currentLine = ""; - } - } - else if (c != '\r') - { - currentLine += c; - } - } - } - // Clear the header variable - header = ""; - // Disconnect connection client.stop(); - Serial.println("Client disconnected."); - Serial.println(""); - } -} \ No newline at end of file diff --git a/temp/webserver.cpp b/temp/webserver.cpp deleted file mode 100644 index 0820146..0000000 --- a/temp/webserver.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include - -/********* - Rui Santos - Complete project details at http://randomnerdtutorials.com -*********/ - -#include "soc/soc.h" -#include "soc/rtc_cntl_reg.h" - - -// Load Wi-Fi library -#include - -// Replace with your network credentials -const char* ssid = ""; -const char* password = ""; - -// Set web server port number to 80 -WiFiServer server(80); - -// Variable to store the HTTP request -String header; - -// Auxiliar variables to store the current output state -String output26State = "off"; -String output27State = "off"; - -// Assign output variables to GPIO pins -const int output26 = 26; -const int output27 = 27; - -void setup() { -WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector - - Serial.begin(115200); - // Initialize the output variables as outputs - pinMode(output26, OUTPUT); - pinMode(output27, OUTPUT); - // Set outputs to LOW - digitalWrite(output26, LOW); - digitalWrite(output27, LOW); - - // Connect to Wi-Fi network with SSID and password - Serial.print("Connecting to "); - Serial.println(ssid); - WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - // Print local IP address and start web server - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - server.begin(); -} - -void loop(){ - WiFiClient client = server.available(); // Listen for incoming clients - - if (client) { // If a new client connects, - Serial.println("New Client."); // print a message out in the serial port - String currentLine = ""; // make a String to hold incoming data from the client - while (client.connected()) { // loop while the client's connected - if (client.available()) { // if there's bytes to read from the client, - char c = client.read(); // read a byte, then - Serial.write(c); // print it out the serial monitor - header += c; - if (c == '\n') { // if the byte is a newline character - // if the current line is blank, you got two newline characters in a row. - // that's the end of the client HTTP request, so send a response: - if (currentLine.length() == 0) { - // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) - // and a content-type so the client knows what's coming, then a blank line: - client.println("HTTP/1.1 200 OK"); - client.println("Content-type:text/html"); - client.println("Connection: close"); - client.println(); - - // turns the GPIOs on and off - if (header.indexOf("GET /26/on") >= 0) { - Serial.println("GPIO 26 on"); - output26State = "on"; - digitalWrite(output26, HIGH); - } else if (header.indexOf("GET /26/off") >= 0) { - Serial.println("GPIO 26 off"); - output26State = "off"; - digitalWrite(output26, LOW); - } else if (header.indexOf("GET /27/on") >= 0) { - Serial.println("GPIO 27 on"); - output27State = "on"; - digitalWrite(output27, HIGH); - } else if (header.indexOf("GET /27/off") >= 0) { - Serial.println("GPIO 27 off"); - output27State = "off"; - digitalWrite(output27, LOW); - } - - // Display the HTML web page - client.println(""); - client.println(""); - client.println(""); - // CSS to style the on/off buttons - // Feel free to change the background-color and font-size attributes to fit your preferences - client.println(""); - - // Web Page Heading - client.println("

bGeigieNano Setup Web Server

"); - - // Display current state, and ON/OFF buttons for GPIO 26 - client.println("

GPIO 26 - State " + output26State + "

"); - // If the output26State is off, it displays the ON button - if (output26State=="off") { - client.println("

"); - } else { - client.println("

"); - } - - // Display current state, and ON/OFF buttons for GPIO 27 - client.println("

GPIO 27 - State " + output27State + "

"); - // If the output27State is off, it displays the ON button - if (output27State=="off") { - client.println("

"); - } else { - client.println("

"); - } - client.println(""); - - // The HTTP response ends with another blank line - client.println(); - // Break out of the while loop - break; - } else { // if you got a newline, then clear currentLine - currentLine = ""; - } - } else if (c != '\r') { // if you got anything else but a carriage return character, - currentLine += c; // add it to the end of the currentLine - } - } - } - // Clear the header variable - header = ""; - // Close the connection - client.stop(); - Serial.println("Client disconnected."); - Serial.println(""); - } -}