Feedback data usage help

Hey All,

I'm working on writing a program that controls a video replay machine. The control is over IP and is very basic text with simple response. There is no go back a clip or go forward a clip command. What I can do however is say "clips get" and it will respond with all of the clips, their name, and their clip count number (i.e. clip 1, clip 2 etc).

What i am needing is help making a code that will store the feedback of the clips command and then let me go back and forward through the clips. There is no "current clip" so that will have to be stored on the arduino.

Here is the output of the clips get command.

clips get
205 clips info:
clip count: 19
1: Capture0000.mov 00:00:01:25
2: Capture0001.mov 00:00:02:15
3: Capture0002.mov 00:00:04:01
4: Capture0003.mov 00:00:00:23
5: Capture0004.mov 00:00:01:07
6: Capture0005.mov 00:00:20:03
7: Capture0006.mov 00:00:01:08
8: Capture0007.mov 00:00:01:06
9: Capture0008.mov 00:00:05:14
10: Capture0009.mov 00:00:01:06
11: Capture0010.mov 00:00:01:03
12: Capture0011.mov 00:00:02:07
13: Capture0012.mov 00:00:01:00
14: Capture0013.mov 00:00:02:20
15: Capture0014.mov 00:00:06:07
16: Capture0015.mov 00:00:09:13
17: Capture0016.mov 00:00:04:14
18: Capture0017.mov 00:00:03:19
19: Capture0018.mov 00:00:01:23

Is it possible to run that command and store those telling it the current clip is 19. Then if i hit back it will go to 18 then 17 then 16 etc etc. i'd like there to be a way to push the button twice quickly to go to the first clip, but I can add that later.

Thanks!

What i am needing is help making a code that will store the feedback of the clips command

It's not feedback of, it's output from.

Where/how is the clips command executed? Is the Arduino supposed to send that command somewhere?

What code IS running on the Arduino?

You need an array to store the entries, which could just be a text string, or you could parse it
into a struct (the clip-length could be encoded into a long for instance). You will have to
manage the storage for the filename strings at least, if you can guarantee an upper limit
on the length of a filename that will simplify the code a lot.

Bear in mind the very limited RAM available on the Arduino though - it might be better to re-execute
the getclips call everytime you need to find out details for a given clip (is there a call to get details
for just one clip). Then you only need to store the total number of clips and current clip number?

Thanks for the reply,

It’s connected over TCP/IP via an Ethernet Shield. Basically it’s a simply telnet connection. After it establishes a connection I am able to output text commands from the arduino such as “play” or “clips get” etc. The switcher does that appropriate action and then replies over TCP with either an OK code or and OK code and the info I requested (like the list of clips on the unit).

The larger picture is that I have a control surface with a number of buttons that will connect to a USB host shield. I am working on programming the buttons to then send their commands when pressed. The code I have is attached. None of the code that is in what I have is related to the actual clips get because i have no idea how to even start using the info it returns after that command.

#include <SPI.h>
#include <Ethernet.h>
#include <Bounce.h>

#define BUTTON1 2   // Define pins
#define BUTTON2 3   // Define pins
#define BUTTON3 5   // Define pins
#define BUTTON3 6   // Define pins
#define LED 14          // Define pins


Bounce bouncer1 = Bounce( BUTTON1,5 );  // Define debounce
Bounce bouncer2 = Bounce( BUTTON2,5 );  // Define debounce
Bounce bouncer3 = Bounce( BUTTON3,5 );  // Define debounce
Bounce bouncer4 = Bounce( BUTTON4,5 );  // Define debounce

int ledValue = LOW;  //Led starts off
int playSpeed = 100;  // playSpeed starts at 100
String sensorValueString = "speed:";

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(192,168,1,133);  // numeric IP for Google (no DNS)
// server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,177);

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

// Initialize sensors

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);   /Begin Serial Communication
  pinMode(BUTTON1,INPUT);  //define input or output
  pinMode(BUTTON2,INPUT);  //define input or output
  pinMode(BUTTON3,INPUT);  //define input or output
  pinMode(BUTTON4,INPUT);  //define input or output
  pinMode(LED,OUTPUT);  //define input or output

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 9993)) {
    Serial.println("connected");
    Serial.println(client.read());
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  bouncer1.update ( );  // Update bounce state with library
  bouncer2.update ( );  // Update bounce state with library
  bouncer3.update ( );  // Update bounce state with library
  bouncer4.update ( );  // Update bounce state with library
  
  
  int buttonValue1 = bouncer1.read();  // Read button state
  int buttonValue2 = bouncer2.read();  // Read button state
  int buttonValue3 = bouncer3.read();  // Read button state
  int buttonValue4 = bouncer4.read();  // Read button state
  
    if (buttonValue3 == HIGH) {  // if button 3 is pressed
    client.println("record");       // start recording
    delay(150);                         // wait so you don't get multiple presses
  }
  
    if (buttonValue2 == HIGH) {  // if button 2 is pressed
    client.println("stop");          // stop
    delay(150);                         // wait so you don't get multiple presses
  }
  
   if (buttonValue1 == HIGH) { // if button 1 is pressed
    client.println("play");          // play
    delay(150);                         // wait so you don't get multiple presses
  }
  
    if (buttonValue4 == HIGH) { // if button 4 is pressed
    client.println("clips get");    // get clip info
    delay(150);                         // wait so you don't get multiple presses
  }
  
  
   if (client.available()) {     // if a reply is available from the HyperDeck
    char c = client.read();    // read it and print it so serial.
    Serial.print(c);
    delay(5);
  }
  
  if (!client.connected()) {  // if client isn't connected stop the client.
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
     }

Thanks!

None of the code that is in what I have is related to the actual clips get because i have no idea how to even start using the info it returns after that command.

To start with, just printing it is useless:

   if (client.available()) {     // if a reply is available from the HyperDeck
    char c = client.read();    // read it and print it so serial.
    Serial.print(c);
    delay(5);
  }

Waiting 5 milliseconds after printing a character is extra useless.

You need to store the data in a char array, followed by a NULL, one character at a time, until the end of record marker arrives. Then, parse that array, storing the data of interest in other places. Repeat until the end-of-message marker arrives.

The fact that the Arduino has little memory to store data is going to limit how much you can store.

Thanks for that PaulS. I got that delay taken out, not sure why it was there.

The shield has a SD card that is available for storage. Would I be able to use that to store that data?

Any idea if there is any sample code for what I'm trying to do that I could go off of?
Thanks!

Would I be able to use that to store that data?

Yes.

Any idea if there is any sample code for what I'm trying to do that I could go off of?

You have code that reads a stream of data, one character at a time.

Creating an array to store that data in is trivial. Creating an index is trivial. Testing that the character is not the end of record marker is trivial. Storing the character in the array, at the index position is trivial. Incrementing the index is trivial. Storing a NULL at the new position is trivial.

If the character is the end of record marker, writing the array to the file on the SD card is trivial. Resetting the index variable is trivial. Storing a NULL at the new position is trivial.

The project you have chosen is not a "blink one LED" type project. Knowing something about string processing, arrays, reading and writing from streams, etc. is essential for what you are doing. Copying and pasting code someone else wrote is NOT the way to develop your project.

Thanks Paul.

I came to this forum looking for help on a project that is admittedly above my programming level. However without challenging myself I will never be able to learn. I came here thinking that someone may be able to help me along though this part of it..

I apologize for wasting your bandwidth.

I apologize for wasting your bandwidth.

I'm not trying to discourage you. It's just that nothing you want to do is very difficult, and there are examples of serial data reception all over the place. The fact that your data comes from a client connection, rather than a serial port, matters not.

Get an Ethernet shield with an SD slot, put in an SD card, and start testing using the SD examples in the arduino IDE. Work on each part of your project one at a time. Your terms like "if i hit back" need to be defined in technical terms of hardware actions, control commands, and such. Below sums up some in the forum that can only offer up how easy thing are. :wink:

"It's easy to sit there and say you'd like to have more money. And I guess that's what I like about it. It's easy. Just sitting there, rocking back and forth, wanting that money." - Deep Thoughts by Jack Handy

Thanks Zoomkat, your response was very informative. I do need to remember i'm on a programming forum where people seem to think much more logically and directly than some of the other forums so I do need to use technical terms referring to inputs and outputs etc. I'll try to do better at that next time.

The ethershield I have does have the micro sd onboard and I happened to save the 16gb card from my old Droid phone which will work perfectly. I"ll get to work on testing with that sample code and see where I can get.

If only someone telling me it's easy magically made me know how to do it. lol

If only someone telling me it's easy magically made me know how to do it. lol

What part of it looks remotely difficult? You are given building blocks. Build something. If that something doesn't do exactly what you want, post the code, and explain the problem.

If you want someone else to use your building blocks to build something, you won't learn a thing. And, you are in the wrong part of the forum for that. The Gigs and Collaboration forum is where you get your wallet out and offer to hire someone.

Expecting other people to write your code for you, for free, is expecting too much.

Thanks for your help so far. I"ve been able to get the input from the ethernet stored in a text file on the SD card.

The input from the ethernet is really filled with a lot of information that I don't need. I think all I really need is total clips from the second line of input. Is there a way to get just that piece of information stored as a variable?

I think if I can get the total clips I could then use it to move back and forward through the clips.

Thanks!

There is a library called Textfinder that might do what you need. Example code below.

//
// Read Yahoo Weather API XML
// 03.09.2012
// http://arduino-praxis.ch


#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAD };
byte ip[] = { 192, 168, 1, 102 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

// Server Yahoo
IPAddress server(87,248,122,181);

EthernetClient client;
TextFinder  finder( client );  

char place[50];
char hum[30];


void setup()
{
  // Start Ehternet
  Ethernet.begin(mac, ip);
  // Start Serial Port
  Serial.begin(9600);
  Serial.println("Setup...");
}


void loop()
{
  if (client.connect(server, 80))
  {
    // Call Wetter-API
    // w: ID from your City
    // http://weather.yahooapis.com/forecastrss?w=12893459&u=c
    ///
    Serial.println("Connect to Yahoo Weather...");
    client.println("GET /forecastrss?w=12893459&u=c HTTP/1.0");
    client.println("HOST:weather.yahooapis.com\n\n");
    client.println();
    Serial.println("Connected...");
  } 
  else
  {
    Serial.println(" connection failed");
  } 
 

  if (client.connected())
  {
    
    // Humidity
   if ( (finder.getString("<yweather:atmosphere humidity=\"", "\"",hum,4)!=0) )
   {
     Serial.print("Humidity:  ");
     Serial.println(hum);
   } 
   else
   {
     Serial.print("No Humidity Data");
   }
    
    
    // Place/City
    if ( (finder.getString("<title>Conditions for ", " ",place,50)!=0) )
    {
      Serial.print("City:  ");
      Serial.println(place);
    }
    
    
    // Temperature
    if(finder.find("temp=") )
    {
     int temperature = finder.getValue();
     Serial.print("Temp C:  ");
     Serial.println(temperature);
   }
   else
   {
     Serial.print("No Temperature Data");
   }
   
         
  // END XML
  }
  else
  {
    Serial.println("Disconnected"); 
  }
 
  client.stop();
  client.flush();
  delay(60000); 
}

Awesome, thanks!

I’ll get to work on that.

I already have that up and working. It was exactly what I needed.

Thanks for the direction zoomkat. I never would have known that existed.

I’m having some issues. I have that code working well. However when i use my code to set it to a integer it will work for one run and then the integer resets to 0. I thought that integers stayed set until you changed them.

Could you help me figure out why the integer is resetting to 0? intigers clipsGet and currentClip both are set to the number of clips in the function clipsGet however they do not hold their values after being set.

#include <SPI.h>
#include <Ethernet.h>
#include <Bounce.h>
#include <TextFinder.h>
 
#define BUTTON1 14
#define BUTTON2 15
#define BUTTON3 16
#define rLED 17
#define gLED 18

Bounce bouncer1 = Bounce( BUTTON1,5 );
Bounce bouncer2 = Bounce( BUTTON2,5 );
Bounce bouncer3 = Bounce( BUTTON3,5 );


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 };
byte ip[] = { 192, 168, 1, 30 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
IPAddress server(192,168,1,21);
EthernetClient client;
TextFinder  finder( client ); 

int rledValue = LOW;
int gledValue = LOW;
int playSpeed = 100;
String sensorValueString = "speed:";

int clipsGet = 0;
int currentClip = 0;

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON1,INPUT);
  pinMode(BUTTON2,INPUT);
  pinMode(BUTTON3,INPUT);
  pinMode(rLED,OUTPUT);
  pinMode(gLED,OUTPUT); 
  
  Ethernet.begin(mac, ip);
  delay(1000);   // give the Ethernet shield a second to initialize:
  Serial.println("connecting...");  
  
  if (client.connect(server, 9993)) {    // if you get a connection, report back via serial:
    Serial.println("connected");
    Serial.println(client.read());
  } 
  else {  // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}
  
void loop()  {
  
  bouncer1.update ( );
  bouncer2.update ( );
  bouncer3.update ( );
  
  
  int buttonValue1 = bouncer1.read();
  int buttonValue2 = bouncer2.read();
  int buttonValue3 = bouncer3.read();
  
if (client.connected()) {
  
     if (buttonValue1 == HIGH) {
        client.println("clips get");
         if(finder.find("clip count: ") ) {
         int clipsGet = finder.getValue();
         int currentClip = clipsGet;
         Serial.println(currentClip);
         client.flush();
       } else {
        Serial.print("No Clip Data");      
       }
    delay(150); 
     } 
     
  
     if (buttonValue2 == HIGH) {
       funBackClip();
       delay(150); 
     }     
     
      if (client.available()) {
        char c = client.read();
        Serial.print(c);
       }


} else { 
  Serial.println();
  Serial.println("disconnecting.");
  client.stop();
  while(true);
  }
}

bump