Hello
I have a remote power unit (NP-02E). My use will be to send a telnet on / off command to the unit by Arduino One with Ethernet. My problem:
The code works and I can connect the unit, I get the report from the NP-02 as connected. But the command in my "void loop" works only, when I push the ENTER on the computerkeyboart in the send line of the Serialwindow. I tried out to send a "\n", before the command, after the command, nothing helps.
Who tells me what to do.
Thanks thowiba
Testcode:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF} ;
IPAddress ip(192, 168, 1, 2);
IPAddress server(192, 168, 1, 3);
//command for the NP-02E: pset [port] [0=off, 1=on]
EthernetClient client;
const char* on1 = "pset 1 1";
const char* off1 = "pset 1 0";
const char* on2 = "pset 2 1";
const char* off2 = "pset 2 0";
int oneState = 1;
int twoState = 1;
void setup() {
Ethernet.init(10);
Ethernet.begin(mac, ip);
Serial.begin(9600);
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
}
if (client.connect(server, 23)) {
Serial.println("connected");
}
else {
Serial.println("connection failed");
}
}
void loop() {
if (client.available()) {
char c = client.read();
Serial.print(c);
}
while (Serial.available() > 0) {
char inChar = Serial.read();
if (client.connected()) {
if (oneState == 0){
client.println(on1);
oneState = 1;
}
else {
client.println(off1);
oneState = 0;
}
delay (1000);
if (twoState == 0){
client.println(on2);
twoState = 1;
}
else {
client.println(off2);
twoState = 0;
}
delay (20);
}
}
}
````````````````````````````````````````````````````````````````````````````````````