Go Down

Topic: What am I doing wrong? (Read 1 time) previous topic - next topic

alanblinkers

Hey guys, I'm new to Arduino and the Yun is my first, so far I'm really enjoying it and have been learning a lot. I am having an issue with Bridge. I'm trying to send a simple command like http://192.168.1.185/arduino/strobe to run a function, however when I go to the web address nothing happens. I have REST password off, I'm at a loss at this point as I've read through the whole forum and the examples, and I'm still not sure what stupid error I'm making. Thanks for any help!

Code: [Select]

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#include <Adafruit_NeoPixel.h>

#define PIN2 2
#define PIN3 3
#define PIN4 4
#define PIN5 5
#define PIN6 6
#define PIN7 7
#define PIN8 8
#define PIN9 9


YunServer server;

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(10, PIN2, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(10, PIN3, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(10, PIN4, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(10, PIN5, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip5 = Adafruit_NeoPixel(10, PIN6, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip6 = Adafruit_NeoPixel(10, PIN7, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip7 = Adafruit_NeoPixel(10, PIN8, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip8 = Adafruit_NeoPixel(10, PIN9, NEO_RGB + NEO_KHZ800);


void setup() {
  // Bridge startup
  pinMode(13,OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);


  server.listenOnLocalhost();
  server.begin();
 
  strip1.begin();
  strip2.begin();
  strip3.begin();
  strip4.begin();
  strip5.begin();
  strip6.begin();
  strip7.begin();
  strip8.begin();
  strip1.show();
  strip2.show();
  strip3.show();
  strip4.show();
  strip5.show();
  strip6.show();
  strip7.show();
  strip8.show();
}

void loop() {
 
  YunClient client = server.accept();

 
  if (client) {
   
    process(client);

   
    client.stop();
  }

  delay(50);
}

void process(YunClient client) {
 
  String command = client.readStringUntil('/');

 
  if (command == "strobe") {
    colorStrobe(strip1.Color(0,0,255), 50, 100);
  }
}

void colorStrobe(uint32_t c, uint8_t wait, uint8_t bright) {
  strip1.setBrightness(bright);
  strip2.setBrightness(bright);
  strip3.setBrightness(bright);
  strip4.setBrightness(bright);
  strip5.setBrightness(bright);
  strip6.setBrightness(bright);
  strip7.setBrightness(bright);
  strip8.setBrightness(bright);
  for (int i = 0; i < 10; i++){
    strip1.setPixelColor(i,c);
    strip2.setPixelColor(i,c);
    strip3.setPixelColor(i,c);
    strip4.setPixelColor(i,c);
    strip5.setPixelColor(i,c);
    strip6.setPixelColor(i,c);
    strip7.setPixelColor(i,c);
    strip8.setPixelColor(i,c);
  }
  strip1.show();
  strip2.show();
  strip3.show();
  strip4.show();
  strip5.show();
  strip6.show();
  strip7.show();
  strip8.show();
      delay(wait);
  for (int i = 0; i < 10; i++){
    strip1.setPixelColor(i,strip1.Color(0,0,0));
    strip2.setPixelColor(i,strip1.Color(0,0,0));
    strip3.setPixelColor(i,strip1.Color(0,0,0));
    strip4.setPixelColor(i,strip1.Color(0,0,0));
    strip5.setPixelColor(i,strip1.Color(0,0,0));
    strip6.setPixelColor(i,strip1.Color(0,0,0));
    strip7.setPixelColor(i,strip1.Color(0,0,0));
    strip8.setPixelColor(i,strip1.Color(0,0,0));
  }
  strip1.show();
  strip2.show();
  strip3.show();
  strip4.show();
  strip5.show();
  strip6.show();
  strip7.show();
  strip8.show();
      delay(wait);
}

federicofissore

Print the command to the serial monitor with
Code: [Select]

String command = client.readStringUntil('/');
Serial.print("'"); //single quote
Serial.print(command);
Serial.println("'"); //single quote with ending new line

Double check if you are receiving the expected command
Also try using readString instead of readStringUntil (since you command "strobe" is not ending with a / ). Take a look at TemperatureWebPanel example

alanblinkers

The issue seems to have been resolved by adding:
Code: [Select]
command.trim();

This was what was coming out of the serial monitor prior to adding that code:
Quote
'strobe
'
'strobe
'

alanblinkers

Sorry, and thanks for your help!

Go Up