Comments (1)
#include "WiFiEsp.h"
#include "SoftwareSerial.h"
#include <SPI.h>
#include <SD.h>
#define R_PIN 5
#define G_PIN 6
#define B_PIN 7
#define BUTTON_PIN 8
#define SD_ChipSelectPin 4
uint8_t btn_prev;
char ssid[] = "Home"; // your network SSID (name)
char pass[] = "23042002"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.31.160";
const int CHUNK_SIZE = 64; // Adjust the chunk size as needed
char mybuffer[CHUNK_SIZE];
WiFiEspClient client;
SoftwareSerial Serial1(3, 2); // RX, TX
void setRGBColor(int mode) {
switch (mode) {
case 0:
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 0);
break;
case 1:
// Set color for mode 1 (e.g., red)
analogWrite(R_PIN, 255);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 0);
break;
case 2:
// Set color for mode 2 (e.g., green)
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 255);
analogWrite(B_PIN, 0);
break;
case 3:
// Set color for mode 3 (e.g., blue)
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 255);
break;
// Add more cases as needed for different modes
case 4:
// Set color for mode 4 (e.g., purple)
analogWrite(R_PIN, 255);
analogWrite(G_PIN, 0); // Adjust green value for orange
analogWrite(B_PIN, 255);
break;
default:
// Default case (e.g., turn off)
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 0);
break;
}
}
void setup() {
setRGBColor(3);
pinMode(R_PIN, OUTPUT);
pinMode(G_PIN, OUTPUT);
pinMode(B_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
Serial.begin(115200);
Serial1.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (true) setRGBColor(1);
}
Serial.println("initialization done.");
WiFi.init(&Serial1);
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while (true) setRGBColor(1);
}
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
}
setRGBColor(2);
}
void saveAudioToFile() {
File audioFile = SD.open("audio.wav", FILE_WRITE );
if (audioFile) {
while (client.available()) {
int bytesRead = client.readBytes(mybuffer, CHUNK_SIZE);
audioFile.write(mybuffer, bytesRead);
Serial.print(".");
}
Serial.println("Audio saved to SD card.");
audioFile.close();
setRGBColor(2);
} else {
Serial.println("Error opening audio file for saving!");
}
}
void loop() {
uint8_t btn = digitalRead(BUTTON_PIN);
if (btn == LOW && btn_prev == HIGH) {
setRGBColor(4);
/* RECORD SPEECH/ SAVE TO SD/ SEND FROM SD TO SERVER
TO DO
*/
if (client.connect(server, 5000)) {
Serial.println("Connected to server");
int value = 2.5; // an arbitrary value for testing
String content = "{"JSON_key": " + String(value) + "}";
client.println("POST /post HTTP/1.1");
client.println("Host: 192.168.31.160:5000");
client.println("Accept: /");
client.println("Content-Length: " + String(content.length()));
client.println("Content-Type: application/json");
client.println();
client.println(content);
}
if (client.connect(server, 5000)) {
Serial.println("Connected to server");
client.println("GET / HTTP/1.1");
client.println("Host: 192.168.31.160:5000");
client.println("Connection: close");
client.println();
}
}
if(client.available()){
Serial.println(1);
saveAudioToFile();
}
btn_prev = digitalRead(BUTTON_PIN);
}
from wifiesp.
Related Issues (20)
- Warning: Unsupported firmware 3.0.4 HOT 17
- Arduino nano Every compiling error HOT 3
- How can I get data? HOT 5
- consumption time of an API (600ms) HOT 30
- UDP->remotePort() returns incorrect value HOT 3
- UDP link is not valid HOT 4
- REST API Post request to microsoft power bi real time data set HOT 1
- ESP8266 Crashes After UDP Packet Overload HOT 2
- ESP-Now with WiFiEsp library on ESP8266-01 interfaced to Arduino Uno HOT 2
- Connect to Firebase Database using WiFiESP
- The use of Delay() HOT 10
- TIMEOUT in same position every time on large HTTP header HOT 2
- WiFiEsp: Send Post message from Arduino Mega + ESP-01 issue HOT 8
- RingBuffer namespace collision with other libraries
- WebClient example doesn't work anymore
- Invalid "ClientSSL " connection directive HOT 5
- DDNS HOT 1
- Problem with the WebClientSSL example
- UDP + WiFiEspServer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wifiesp.