{"id":26308073,"url":"https://github.com/phptuts/esp32introclass","last_synced_at":"2025-03-15T10:17:13.738Z","repository":{"id":280548944,"uuid":"942377346","full_name":"phptuts/esp32introclass","owner":"phptuts","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-04T03:28:27.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T03:29:12.289Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phptuts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-04T02:41:21.000Z","updated_at":"2025-03-04T03:28:31.000Z","dependencies_parsed_at":"2025-03-04T03:29:13.988Z","dependency_job_id":"81f6dcfd-d915-49d7-8709-627e6cd8e98a","html_url":"https://github.com/phptuts/esp32introclass","commit_stats":null,"previous_names":["phptuts/esp32introclass"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2Fesp32introclass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2Fesp32introclass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2Fesp32introclass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2Fesp32introclass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phptuts","download_url":"https://codeload.github.com/phptuts/esp32introclass/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243713338,"owners_count":20335567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-15T10:17:13.089Z","updated_at":"2025-03-15T10:17:13.724Z","avatar_url":"https://github.com/phptuts.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blink ESP-32\n\n## Install Requirements\n\n- [Install Arduino IDE](https://www.arduino.cc/en/software)\n- Install ESP-32 Boards\n  - ![ExampleImage](./install-expressif.png)\n- [Install Nodejs](https://nodejs.org/en)\n- [Visual Studio Code](https://code.visualstudio.com/)\n- Install local tunnel\n\n```bash\nnpm install -g localtunnel\n```\n\n## Uploading to ESP-32\n\nIn Tools \u003e Board Settings, set:\n\nSetting Value\nUpload Speed 115200\nCPU Frequency 240 MHz (WiFi/BT)\nFlash Frequency 80MHz\nFlash Mode QIO\nFlash Size 4MB (32Mb)\nPartition Scheme Default 4MB with spiffs\nPSRAM Disabled (unless your board has it)\n\n## Blink the Internal LED.\n\n```cpp\n#define LED_PIN 2  // Built-in LED or external LED on GPIO2\n\nvoid setup() {\n    pinMode(LED_PIN, OUTPUT); // Set GPIO2 as an output\n}\n\nvoid loop() {\n    digitalWrite(LED_PIN, HIGH); // Turn LED on\n    delay(1000);                 // Wait 1 second\n    digitalWrite(LED_PIN, LOW);  // Turn LED off\n    delay(1000);                 // Wait 1 second\n}\n```\n\n## Create a nodejs server\n\n1. Type in the terminal npm init -y\n2. Create your app.js file.\n\n```js\nconst express = require(\"express\");\nconst app = express();\nconst port = 3000;\nvar state = \"OFF\";\n// Define a GET endpoint\napp.get(\"/\", (req, res) =\u003e {\n  console.log(state, \"Sent State\");\n  res.send(state);\n});\n\napp.get(\"/change/:on\", (req, res) =\u003e {\n  state = req.params.on == \"ON\" ? \"ON\" : \"OFF\";\n  res.send(state);\n});\n// Start the server\napp.listen(port, () =\u003e {\n  console.log(`Server is running on http://localhost:${port}`);\n});\n```\n\n3. run node app.js in the terminal\n4. Run lt --port 3000 in the terminal\n5. Go to your url and enter the password to access it.\n6. Go to the Arduino IDE and create a new file.\n\n```cpp\n#include \u003cWiFi.h\u003e\n#include \u003cHTTPClient.h\u003e\n\n#define LED_PIN 23  // Change if using a different GPIO\n\n// Replace with your WiFi credentials\nconst char* WIFI_SSID = \"Noisebridge\";\nconst char* WIFI_PASSWORD = \"noisebridge\";\n\n// Replace with your API endpoint\nconst char* SERVER_URL = \"http://replace_url.com/\";\n\nvoid setup() {\n    Serial.begin(115200);\n    pinMode(LED_PIN, OUTPUT);\n    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);\n\n    Serial.print(\"Connecting to WiFi...\");\n    while (WiFi.status() != WL_CONNECTED) {\n        delay(1000);\n        Serial.print(\".\");\n    }\n    Serial.println(\"\\nConnected to WiFi!\");\n}\n\nvoid loop() {\n    if (WiFi.status() == WL_CONNECTED) {\n        HTTPClient http;\n        http.begin(SERVER_URL);\n\n        int httpResponseCode = http.GET();\n        if (httpResponseCode \u003e 0) {\n            String response = http.getString();\n            response.trim(); // Remove unwanted spaces/newlines\n\n            Serial.print(\"Server Response: \");\n            Serial.println(response);\n\n            if (response == \"ON\") {\n                digitalWrite(LED_PIN, HIGH);\n            } else if (response == \"OFF\") {\n                digitalWrite(LED_PIN, LOW);\n            }\n        } else {\n            Serial.print(\"Error on HTTP request: \");\n            Serial.println(httpResponseCode);\n        }\n\n        http.end();\n    } else {\n        Serial.println(\"WiFi Disconnected! Reconnecting...\");\n        WiFi.begin(WIFI_SSID, WIFI_PASSWORD);\n    }\n\n    delay(5000);  // Check every 5 seconds\n}\n```\n\n7\\. Upload the code\n\n8\\. Change the state from on to off using the change/ON url.\n\n9\\. Play around with this and see if you can get the arduino to blink as a challenge.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphptuts%2Fesp32introclass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphptuts%2Fesp32introclass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphptuts%2Fesp32introclass/lists"}