bom galera, to com um grande problema..
o arduino não quer interpretar o comando enviado pelo programa..
meu code..
#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>
// ethernet configuration
byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
byte ip[] = { 169, 254, 143, 10 }; // ip do arduino na rede--------------------------------
EthernetServer server(80);
//OSC configuration
byte destIP[] = {169,254,143,50}; // ip do controlador osc---------------------
int serverPort = 80;
int destPort = 9000;
OSCServer oserver;
OSCClient oclient;
//pins defines
byte LED1 = 44;
byte LED2 = 45;
byte BOT1 = 41;
byte BOT2 = 30;
// Variaveis
boolean botstate1 = 0;
boolean botstate2 = 0;
char c = 0;
char command[6] = "\0";
void setup(){
Ethernet.begin(mac, ip);
server.begin();
oserver.begin(serverPort);
oserver.addCallback("/led1", &func1);
oserver.addCallback("/led2", &func2);
//setup dos pinos
pinMode(LED1, OUTPUT);
pinMode(BOT1, INPUT);
digitalWrite(BOT1,1);
pinMode(LED2, OUTPUT);
pinMode(BOT2, INPUT);
digitalWrite(BOT2,1);
}
void loop(){
if(oserver.aviableCheck()>0){}
if(digitalRead(BOT1)==LOW){
botstate1 = !botstate1;
OSCMessage txMes;
txMes.setAddress(destIP,destPort);
txMes.beginMessage("/led1");
txMes.addArgFloat(botstate1);
oclient.send(&txMes);
digitalWrite(LED1,botstate1);
delay(200);
}
if(digitalRead(BOT2)==LOW){
botstate2 = !botstate2;
digitalWrite(LED2,botstate2);
OSCMessage txMes;
txMes.setAddress(destIP,destPort);
txMes.beginMessage("/led2");
txMes.addArgFloat(botstate2);
oclient.send(&txMes);
delay(200);
}
EthernetClient client = server.available();
// detect if current is the first line
boolean current_line_is_first = true;
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// auto reload webpage every 5 second
//client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");
// webpage title
client.println("<center><p><h1>Arduino + Ethernet Shield Application v1.0</h1></p><center><hr>
");
// read analog pin 1 for the value of photocell
// button led1 functions
client.println("<center><p><h2>Led 1</h1></p><center>
");
client.println("<form method=get name=form>");
client.println("<button name=b value=1 type=submit style=height:80px;width:150px>LED On</button>");
client.println("<button name=b value=2 type=submit style=height:80px;width:150px>LED Off</button>");
client.println("</form><hr>
");
// button led2 functions
client.println("<center><p><h2>Led 2</h1></p><center>
");
client.println("<form method=get name=form>");
client.println("<button name=b value=3 type=submit style=height:80px;width:150px>LED On</button>");
client.println("<button name=b value=4 type=submit style=height:80px;width:150px>LED Off</button>");
client.println("</form>
");
// button todas as leds functions
client.println("<center><p><h2>Todas leds</h1></p><center>
");
client.println("<form method=get name=form>");
client.println("<button name=b value=5 type=submit style=height:80px;width:150px>LED On</button>");
client.println("<button name=b value=6 type=submit style=height:80px;width:150px>LED Off</button>");
client.println("</form>
");
// webpage footer
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_first = false;
current_line_is_blank = true;
}
else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
// get the first http request
if (current_line_is_first && c == '=') {
for (int i = 0; i < 1; i++) {
c = client.read();
command[i] = c;
}
// LED1 web control
if (!strcmp(command , "1")) {
botstate1 = 1;
}
else if (!strcmp(command, "2") ) {
botstate1 = 0;
}
// LED2 web control
if (!strcmp(command , "3")) {
botstate2 = 1;
}
else if (!strcmp(command, "4") ) {
botstate2 = 0;
}
// todas LED web control
if (!strcmp(command , "5")) {
botstate1 = 1;
botstate2 = 1;
}
else if (!strcmp(command, "6") ) {
botstate1 = 0;
botstate2 = 0;
}
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
digitalWrite(LED1,botstate1);
digitalWrite(LED2,botstate2);
}
void func1(OSCMessage *_mes){
int value = (int)_mes->getArgFloat(0);
digitalWrite(LED1, value);
}
void func2(OSCMessage *_mes){
int value = (int)_mes->getArgFloat(0);
digitalWrite (LED2, value);
}
o html e o botão estão funcionando..
mas o osc nem sinal, ja tentei de tudo..
e agora?