i use this code:
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#define LED_PIN 9
YunServer server;
void setup() {
// init LED PIN
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
// start the Bridge library
Bridge.begin();
// init serial connection and wait until it's available
Serial.begin(9600);
while (!Serial);
// listen for incoming connections from localhost only
server.begin();
server.listenOnLocalhost();
Serial.println("Accepting commands...");
}
void loop() {
// try to accept a new connection
YunClient client = server.accept();
// a client was accepted?
if(client) {
// read the command and trim spaces
String command = client.readString();
command.trim();
// print the received command on the console
Serial.print("New command -> ");
Serial.println(command);
if(command == "1") {
client.println("spara 1");
}
// perform the requested action
if(command == "on") {
digitalWrite(LED_PIN, HIGH);
client.println("LED acceso");
}
if(command == "off") {
digitalWrite(LED_PIN, LOW);
client.println("LED spento");
}
// close the connection
client.stop();
}
}
This works only if the Arduino is connected to PC:
- I connect Arduino to PC-A for power supply. (work)
- wi-fi connect PC-B to YUN (work)
- I can turn on/off led by PC-B
If I connect Arduino to external power supply:
- I connect Arduino to external power supply. (work)
- wi-fi connect PC-B to YUN (work)
- I can turn on/off led by PC-B or PC-A (problem)
What should I do to get this project ?
my second is steep connect two Arduino yun together via wifi (one client and one server ) if anyone has a working example I thank him...