109 lines
2.4 KiB
Arduino
109 lines
2.4 KiB
Arduino
|
#include "WiFlyUDP.h"
|
||
|
#include "TimerOne.h"
|
||
|
#include <EEPROM.h>
|
||
|
|
||
|
uint16_t remote_Port = 8000;
|
||
|
uint16_t local_Port = 9000;
|
||
|
char ip_host[16] = "";
|
||
|
#define DEFAULT_ip_host "192.168.0.1"
|
||
|
#define ssid "VDOSSIER"
|
||
|
#define pass "VDOSSIER"
|
||
|
boolean read_serial = false;
|
||
|
|
||
|
byte VER = 0x02;
|
||
|
|
||
|
char test_message[] = { // Message template commands
|
||
|
'/', 'L', 'u', 'Z', // ANALOG OUT TEMPLATE
|
||
|
B0 , B0 , B0, B0,
|
||
|
',', 'i', B0, B0,
|
||
|
B0 , B0 , B0, B0 // 4 analog outs = 4 integers
|
||
|
};
|
||
|
|
||
|
char incomming_message[] = { // Message template commands
|
||
|
'/', 'L', 'u', 'Z', // ANALOG OUT TEMPLATE
|
||
|
B0 , B0 , B0, B0,
|
||
|
',', 'i', B0, B0,
|
||
|
B0 , B0 , B0, B0 // 4 analog outs = 4 integers
|
||
|
};
|
||
|
|
||
|
byte incomming_count = 0;
|
||
|
|
||
|
WiFlyUDP udp(&Serial);
|
||
|
network_results networks;
|
||
|
|
||
|
void timerIsr()
|
||
|
{
|
||
|
if(read_serial)
|
||
|
{
|
||
|
if(Serial.available()>0)
|
||
|
{
|
||
|
char inByte;
|
||
|
inByte = Serial.read();
|
||
|
test_ip(inByte);
|
||
|
test_incoming(inByte);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
|
||
|
{
|
||
|
asm volatile (" jmp 0");
|
||
|
}
|
||
|
|
||
|
void ini()
|
||
|
{
|
||
|
Serial.begin(115200);
|
||
|
if (EEPROM.read(0x30) == VER)
|
||
|
{
|
||
|
for(int i=0; i<16; i++) ip_host[i]='\x00'; //Limpia memoria
|
||
|
for(int i=0; i<16; i++) ip_host[i] = EEPROM.read(i);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
for(int i=0; i<16; i++) ip_host[i]='\x00'; //Limpia memoria
|
||
|
for(int i=0; i<16; i++) EEPROM.write(i,'\x00'); //Limpia memoria
|
||
|
for(int i=0; i<strlen(DEFAULT_ip_host); i++) ip_host[i] = DEFAULT_ip_host[i];
|
||
|
for(int i=0; i<strlen(ip_host); i++) EEPROM.write(i, ip_host[i]);
|
||
|
EEPROM.write(0x30,VER);
|
||
|
}
|
||
|
udp.begin(ssid, pass, ip_host, remote_Port, local_Port);
|
||
|
while(!udp.join());
|
||
|
Timer1.initialize(500); // set a timer of length 1000000 microseconds (or 1 sec - or 1Hz)
|
||
|
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
|
||
|
}
|
||
|
|
||
|
void setup() {
|
||
|
pinMode(9, OUTPUT);
|
||
|
pinMode(10, OUTPUT);
|
||
|
pinMode(11, OUTPUT);
|
||
|
analogWrite(9, 0);
|
||
|
analogWrite(10, 0);
|
||
|
analogWrite(11, 0);
|
||
|
ini();
|
||
|
delay(1000);
|
||
|
read_serial=true;
|
||
|
|
||
|
//udp.baudrate(115200);
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
// if(read_serial)
|
||
|
// {
|
||
|
// if(Serial.available()>0)
|
||
|
// {
|
||
|
// char inByte;
|
||
|
// inByte = Serial.read();
|
||
|
// //Serial.write(inByte);
|
||
|
// //Serial.println(inByte);
|
||
|
// test_ip(inByte);
|
||
|
// test_incoming(inByte);
|
||
|
// }
|
||
|
// }
|
||
|
if (incomming_count==16) analogWrite(11, incomming_message[15]);
|
||
|
//delay(100);
|
||
|
//Serial.println("Conectado!!");
|
||
|
}
|
||
|
|
||
|
|
||
|
|