Initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#include "Arduino.h"
|
||||
#include "Network.h"
|
||||
#include <WiFi.h>
|
||||
|
||||
#define MAX_PACKAGES 100
|
||||
#define TICKS 1000
|
||||
|
||||
const char* SSID="Tenda_32C850";
|
||||
const char* PASSWD="rhLcrMEcY^Xjvq66";
|
||||
// COnfigurar direcciones fijas
|
||||
IPAddress local_ip(192,168,0,150);
|
||||
IPAddress gateway(192,168,0,1);
|
||||
IPAddress subnet(255,255,255,0);
|
||||
IPAddress dns1(192,168,0,100);
|
||||
IPAddress dns2(1,1,1,1);
|
||||
|
||||
NetworkServer server(8080);
|
||||
NetworkClient client = server.accept();
|
||||
|
||||
uint8_t i=0;
|
||||
|
||||
hw_timer_t *timer = NULL;
|
||||
volatile SemaphoreHandle_t timerSemaphore;
|
||||
|
||||
|
||||
void ARDUINO_ISR_ATTR onTimer() {
|
||||
i = (i>=MAX_PACKAGES) ? 0 : i+1;
|
||||
xSemaphoreGiveFromISR(timerSemaphore, NULL);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(230400);
|
||||
|
||||
Network.begin();
|
||||
WiFi.STA.begin();
|
||||
WiFi.STA.config(local_ip,gateway,subnet,dns1,dns2);
|
||||
WiFi.STA.connect(SSID, PASSWD);
|
||||
while (WiFi.STA.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
server.begin();
|
||||
|
||||
// Iniciar y desbloquear la bandera
|
||||
timerSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(timerSemaphore);
|
||||
|
||||
// Configurar la interrupcion ISR
|
||||
timer = timerBegin(1000000);
|
||||
timerAttachInterrupt(timer, &onTimer);
|
||||
timerAlarm(timer, TICKS, true, 0);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!client || !client.connected()) {
|
||||
client = server.accept();
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(timerSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
if (client && client.connected()) {
|
||||
uint8_t imagen=i;
|
||||
client.printf("%03u",imagen);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user