I'm having a problem about how to test arduino when it's connected to other device , I have to program arduino to send order to other device that will be programmed to recieve arduino orders , but I'm having some problem with the arduino , first : how can I see the packet of the message that will be sent throw the network
I have tried to make a trick but it didn't worked , the trick is trying to read the packet by using wireshark I have connect it to my PC then install OpenDhcpServer to give it an IP and I have assigned an IP to my PC , then it worked but the problem is that when I have opened the TCP packet it gaved 00 00 that's mean that there is no data sending which mean I have something missing , but I want to know how can I contact with other device , I want to let the other device wait for the message HIGH for example , if the other device red HIGH from the arduino , then it will do action . the other device should be programmed by using java .I hope this was clear .
#include <SPI.h>
#include<Ethernet.h>
byte mac[] = {0x54, 0x04, 0xA6, 0x55, 0xF7, 0x88}; //physical mac address
IPAddress server(192,168,0,4);//Server1
EthernetClient client; //Client
boolean alreadyConnected = false; // whether or not the client was connected previously
IPAddress ip(192,168,0,5);
IPAddress subnet(255, 255, 255, 0);
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
void setup(){
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(4,OUTPUT);
pinMode(6,OUTPUT);
Ethernet.begin(mac);
}
void loop(){
// start the Ethernet connection:
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
Serial.println("connecting");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;);
}
Serial.println("connected");
if ( client.available()){
if(digitalRead(2)==HIGH){
client.flush();
Serial.println("The state is high");
Serial.println("connected1");
digitalWrite(6,HIGH);
client.println("HIGH");
}
else{
client.flush();
Serial.println("The state is low");
client.println("LOW");
Serial.println("connected2");
digitalWrite(6,LOW);
}
}}
Seems to me that because of this code, your Arduino won't send anything until it receives something:
if ( client.available()){
Is that deliberate?
What is the 'other device' you refer to - is this something you're going to create or does it already exist?
You don't seem to be using any standard protocol. Are you planning just to write an ascii text stream over a TCP socket? Have you got a clear understanding of how communication between the two devices will work? I don't mean how they'll do the sending and receiving - I mean what messages will be sent in what sequence.
I want to use HTTP protocol to contact with the Cisco DMP(Digital Media Player) , I want when I give it HIGH it should show a special video , LOW will act normal , the product that we are trying to develop is used in marketing when someone moves in front of the TV it should show him a special video .
This is my code , and I have put some description for any important part and fix some codes .
Code:
#include <SPI.h>
#include<Ethernet.h>
byte mac[] = {0x54, 0x04, 0xA6, 0x55, 0xF7, 0x88}; //physical mac address
IPAddress server(192,168,0,4);//Server1
EthernetClient client; //Client
boolean alreadyConnected = false; // whether or not the client was connected previously
IPAddress ip(192,168,0,5);
IPAddress subnet(255, 255, 255, 0);
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
void setup(){
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(4,OUTPUT);
pinMode(6,OUTPUT);
Ethernet.begin(mac);
}
void loop(){
// start the Ethernet connection:
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
Serial.println("connecting");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;);
}
Serial.println("connected");
if ( client.available()) //if there is connection then following action
{
digitalWrite(4,HIGH); //if there is connection light ON the green led
digitalWrite(8,LOW); // if there is no connection switch off red led
if(digitalRead(2)==HIGH){
client.flush();
Serial.println("The state is high");
Serial.println("connected1");
digitalWrite(6,HIGH);
client.println("HIGH");
}
else{
client.flush();
Serial.println("The state is low");
client.println("LOW");
Serial.println("connected2");
digitalWrite(6,LOW);
}
}
else{
digitalWrite(8,HIGH); // if there is no connection switch on red led
digitalWrite(4,LOW); // also switch off green led
}
}
fire1:
I want to use HTTP protocol to contact with the Cisco DMP(Digital Media Player) , I want when I give it HIGH it should show a special video , LOW will act normal ,
Does the Cisco DMP enable you to change the video via a URL request? If so, do you know the required syntax for that request? Given that this is a pre-existing product that doesn't know anything about your solution, It would be pretty strange if it was smart enough to recognise the words "HIGH" and "LOW" arriving over a TCP socket as instructions to select a different video.