Go Down

Topic: On/OFF web interface need help! (Read 759 times) previous topic - next topic

polishdude20

Hey guys I was reading this tutorial over here: http://projects.sindrelindstad.com/how-to-led-arduino-php-proc/

I followed that tutorial but there's a problem.

I am using zymichost to host my free website with php enabled and it seems that the php code is working because it DOES change the value in LEDstate.txt when you click on or off. The thing is that in the processing window it keeps saying that it's turning off the LED cause there's no value.  here's the processing code:

Code: [Select]
/*

A simple Processing script for enabling or disabling the LED on an Arduino using a web interface and serial communication.
Author: Sindre Lindstad
Created: 19th of January 2011

http://projects.sindrelindstad.com

*/

import processing.serial.*;
Serial port;

void setup()  {

   /* This part must be altered to fit your local settings. The number in brackets after "Serial.list()" is where you declare what COM port your Arduino is connected to.
      If you get error messages, try a different number starting from 0 (e.g. 0, 1, 2, 3...) . */
    port = new Serial(this,"COM3", 9600);  // Open the port that the Arduino board is connected to, at 9600 baud

}
void draw() {

  String onoroff[] = loadStrings("http://adamlight.zymichost.com/LEDstate.txt"); // Insert the location of your .txt file
  print(onoroff[0]);  // Prints whatever is in the file ("1" or "0")

  if (onoroff[0].equals("1") == true) {
    println(" - TELLING ARDUINO TO TURN LED ON");
    port.write('H'); // Send "H" over serial to set LED to HIGH

  } else {

    println(" - TELLING ARDUINO TO TURN LED OFF");
    port.write('L');  // Send "L" over serial to set LED to LOW
}

  delay(5000); // Set your desired interval here, in milliseconds
}


so basically it's not detecting whether on/off equals true or not.

If you check the website I'm hosting and you type "/LEDstate.txt" on the end then it will show a value of 1 or 0 like it should when you press the buttons. I don't know what is wrong. Here's the website: http://adamlight.zymichost.com/index.html

PaulS

Quote
The thing is that in the processing window it keeps saying that it's turning off the LED cause there's no value.

You are getting an array of strings from the file. How many strings do you get? What is in the strings?

Code: [Select]
  print(onoroff[0]);  // Prints whatever is in the file ("1" or "0")
What does this print?

Code: [Select]
  if (onoroff[0].equals("1") == true) {
What's wrong with a simple
Code: [Select]
if(onoroff[0] == "1")

Where's the Arduino question?

polishdude20

I'm getting the string from a text file online that stores the value of either a 1 or a 0 depending on what the user clicked. The arduino coding is all good and responds to sending an H or L over serial to turn it on and off. The problem is just that processing doesn't seem to read the text file at all.

PaulS

Quote
The problem is just that processing doesn't seem to read the text file at all.

Looking at http://processing.org/reference/loadStrings_.html, does anything in the 2nd or 3rd paragraph under Description apply to you?

polishdude20

i don't think so. Because I copy and pasted the script over so it won't have any data of where it is from. and I'm not getting any error messages or null

PaulS

When I try to run the Processing sketch, I get this:
Code: [Select]
The file "http://adamlight.zymichost.com/LEDstate.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

polishdude20

it happens to you because of that thing in the 2nd paragraph but not for me cause I made the program myself. or idk

polishdude20

okay I got it to work but it is extremely slow to respond. Only about 2-3 minutes after I clock on or off does processing recognize the change. Anyone know a solution?

Go Up