Page 1 of 1

re: spurious values with java and SBC

Posted: Mon Mar 18, 2013 6:19 pm
by dstockman
I am new to java and phidget coding. I am using the phidget to record data from my renewable energy system and various environmental sensors. I want to sample the RE system every second (for this test code, every 5 minutes). I have written code using 3 different methods, but I run into spurious data from around 9 pm until 6 am with all 3 methods. One method just used a Thread.sleep(1000) and sampled after the sleep. Another method relied on analog sensor changes to trigger a sampling event. The third approach used a time-based listener. I have created code below to make this as simple as possible to recreate the error (which it does). I am hoping one of you can point me to my error in coding.

Thanks,

Doug

anemCount - this is a homemade anemometer based on a magnetic switch that is read by a digital input
Bvolt raw - voltage divider feeds into an analog input. It reads a 48 volt battery (potential ranges of voltage 44-64 volts, but brought down to mid-range 0-5 v for phidget)
Bvolt is just basic math to get the actual voltage.

Code

Code: Select all

package tshootphidge;

import com.phidgets.*;
import com.phidgets.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;


public class TShootPhidge {

static InterfaceKitPhidget ik = null;
static Calendar cal = Calendar.getInstance();
static Long cTime = 0L;
static int anemCount=0;
static Long startTime = 0L;

    public static void main(String[] args) throws PhidgetException, InterruptedException {
 
            ik = new InterfaceKitPhidget();
            ik.open(250564, "phidgetsbc");
            ik.waitForAttachment();
            System.out.println("Attached to Phidget");

        startTime = cTime = System.currentTimeMillis();
       
        // ----------- this counts anemometer revolutions (times 2) ----------
           ik.addInputChangeListener(new InputChangeListener() {
                @Override
                public void inputChanged(InputChangeEvent ice) {
                    anemCount++;
                }
            }
            );
       
        // ---------- about every 5 minutes this code executes  ----------
           javax.swing.Timer t = new javax.swing.Timer(300000, new ActionListener() {  // every 5 minutes get data
                @Override
                public void actionPerformed(ActionEvent e) {
                   try {

                       System.out.println("Time = " + Calendar.getInstance().getTime() + "    Bvolt raw = " + ik.getSensorValue(7) + "   Bvolt = " +  ik.getSensorValue(7)/13.35 + "   anemCOunt = " + anemCount);
                       anemCount = 0;
                   } catch (PhidgetException ex) {
                       Logger.getLogger(TShootPhidge.class.getName()).log(Level.SEVERE, null, ex);
                   }
 
                }
           }
           );
           
           t.start();
           // we need to sit here and wait, 8 days of waiting  // changed to 1 days for testing
           while ((System.currentTimeMillis() < (startTime + ( 1 * 86400000)))){
               Thread.sleep(1000);           
       //        cal2 = Calendar.getInstance();
           }
        t.stop();       
       
       
          ik.close();
          ik = null;
        System.out.println("detatched from Phidget");       
       
       
    }
   
   
}



Phidget output
Attached to Phidget
Time = Sun Mar 17 20:48:28 EDT 2013 Bvolt raw = 680 Bvolt = 50.936329588014985 anemCOunt = 37
Time = Sun Mar 17 20:53:28 EDT 2013 Bvolt raw = 679 Bvolt = 50.86142322097378 anemCOunt = 69
Time = Sun Mar 17 20:58:28 EDT 2013 Bvolt raw = 676 Bvolt = 50.63670411985019 anemCOunt = 172
Time = Sun Mar 17 21:03:28 EDT 2013 Bvolt raw = 467176 Bvolt = 1.2394284411985019E8 anemCOunt = 92
Time = Sun Mar 17 21:08:28 EDT 2013 Bvolt raw = 467176 Bvolt = 34994.456928838954 anemCOunt = 0
Time = Sun Mar 17 21:13:28 EDT 2013 Bvolt raw = 467176 Bvolt = 34994.456928838954 anemCOunt = 0

this continues overnight, then reverts to ok values

Time = Mon Mar 18 06:23:30 EDT 2013 Bvolt raw = 467176 Bvolt = 34994.456928838954 anemCOunt = 0
Time = Mon Mar 18 06:28:30 EDT 2013 Bvolt raw = 467176 Bvolt = 34994.456928838954 anemCOunt = 0
Time = Mon Mar 18 06:33:30 EDT 2013 Bvolt raw = 467176 Bvolt = 34994.456928838954 anemCOunt = 0
Time = Mon Mar 18 06:38:30 EDT 2013 Bvolt raw = 671 Bvolt = 50.262172284644194 anemCOunt = 591
Time = Mon Mar 18 06:43:30 EDT 2013 Bvolt raw = 693 Bvolt = 51.91011235955056 anemCOunt = 958
Time = Mon Mar 18 06:48:30 EDT 2013 Bvolt raw = 678 Bvolt = 50.78651685393258 anemCOunt = 950
Time = Mon Mar 18 06:53:30 EDT 2013 Bvolt raw = 659 Bvolt = 49.36329588014981 anemCOunt = 855

Re: re: spurious values with java and SBC

Posted: Tue Mar 19, 2013 11:00 am
by Patrick
Hi,

We have just discovered that the Java library isn't throwing exceptions. I'm thinking that you are getting garbage values where an exception should be thrown. You may want to add attach and detach handlers to see if your interfacekit is detaching for some reason.

We will be issuing a new library soon with Exceptions re-enabled.

-Patrick

Re: re: spurious values with java and SBC

Posted: Thu Mar 21, 2013 5:55 am
by dstockman
Patrick:

Thank you. I used a detach listener and it is detaching around 9:30 - 10 pm. Do you have any idea why this is happening? Also, why does it automatically reattach at around 6 am?

Inside the detach handler, is it ok to repeat the ik.open and ik.waitForAttachment in an effort to reattach to the phidget?

I need to collect data 24 hrs/day and am looking for a solution.

Thanks for your help.

Doug

Re: re: spurious values with java and SBC

Posted: Thu Mar 21, 2013 10:08 am
by Patrick
If this is consistent every day, I would guess that it has something to do with your network setup. Are you able to access the SBC web interface after the detach happens?

Re-opening the device won't help. If it detaches, this means that either the network is down, the webservice is down, or the SBC is down.

Something which may give you a clue is enabling logging in the library: Phidget.enableLogging(Phidget.PHIDGET_LOG_INFO, "filename");

-Patrick

Re: re: spurious values with java and SBC

Posted: Sun Mar 24, 2013 2:24 pm
by dstockman
Patrick:

We turn our wireless off nightly (teenagers in the house). Does this cause the SBC to stop running programs that are on the SBC (or disconnect)? I am placing the programs on the SBC and having them only write data to SBC memory and an SBC-mounted USB memory stick. If this is the cause of the problem (see error dump below), is there a work-around. It appears others are able to run free-standing programs on the SBC and still have them collect data when not communicating over a network. Ideally, I would connect and disconnect wirelessly as needed. Thanks for any help you can offer.

Doug



error dump
Sat Mar 23 06:13:06 2013,1082221680,"clog.c(62)",INFO,"Enabling logging"
Sat Mar 23 22:07:49 2013,1743619184,"linux/zeroconf_avahi.c(553)",INFO,"(Browser) REMOVE: service 'Phidget InterfaceKit 8/8/8 (250564)' of type '_phidget._tcp' in domain 'local'"
Sat Mar 23 22:07:49 2013,1743619184,"linux/zeroconf_avahi.c(767)",INFO,"(Browser) REMOVE: service 'phidgetsbc' of type '_phidget_ws._tcp' in domain 'local'"
Sat Mar 23 22:07:49 2013,1743619184,"linux/zeroconf_avahi.c(688)",INFO,"(Browser) REMOVE: service 'PhidgetSBC (00:1b:0b:10:01:5c)' of type '_phidget_sbc._tcp' in domain 'local'"
Sun Mar 24 05:41:32 2013,1743619184,"linux/zeroconf_avahi.c(668)",INFO,"(Browser) NEW: service 'PhidgetSBC (00:1b:0b:10:01:5c)' of type '_phidget_sbc._tcp' in domain 'local'"
Sun Mar 24 05:41:32 2013,1743619184,"linux/zeroconf_avahi.c(750)",INFO,"(Browser) NEW: service 'phidgetsbc' of type '_phidget_ws._tcp' in domain 'local'"
Sun Mar 24 05:41:32 2013,1743619184,"linux/zeroconf_avahi.c(536)",INFO,"(Browser) NEW: service 'Phidget InterfaceKit 8/8/8 (250564)' of type '_phidget._tcp' in domain 'local'"
Sun Mar 24 05:41:33 2013,1743619184,"linux/zeroconf_avahi.c(464)",INFO,"DNSServiceResolve_SBC_CallBack: Phidget InterfaceKit 8/8/8 (250564)"
Sun Mar 24 05:41:33 2013,1743619184,"linux/zeroconf_avahi.c(472)",INFO,"DNSServiceQueryRecord_Phidget_CallBack: Phidget InterfaceKit 8/8/8 (250564)"
Sun Mar 24 05:41:33 2013,1743619184,"linux/zeroconf_avahi.c(382)",INFO,"DNSServiceResolve_SBC_CallBack: PhidgetSBC (00:1b:0b:10:01:5c)"
Sun Mar 24 05:41:33 2013,1752593520,"csocketopen.c(1093)",INFO,"Want to connect to server: phidgetsbc.local:5001"

Re: re: spurious values with java and SBC

Posted: Mon Mar 25, 2013 8:51 am
by Patrick
If you are running the program on the SBC itself, then why are you using a network open command? I'd recommend opening the Phidgets directly, and not using the webservice at all:

ik.open(250564, "phidgetsbc"); --> ik.open(250564);

If you really need to open using the webservice, then open using 'localhost' because this interface will not go away:

ik.open(250564, "localhost", 5001);

-Patrick

Re: re: spurious values with java and SBC

Posted: Wed Mar 27, 2013 6:18 pm
by MarkS
Patrick,

One of the reasons I open Phidgets using the webservice even though they're local to the SBC is so I can, if needed, launch the UI for a given Phidget from the Bonjour tab on the Phidget Control Panel of my PC, and monitor what's going on with the Phidget. As I understand it, if I open the Phidget directly, I lose that view.

My SBC Java app makes extensive use of the Dictionary - the SBC server app has about 700 key/value pairs, and the PC/Linux client has another 500 or so.

Does your "'localhost' interface will not go away" comment apply to the Dictionary as well as the Phidgets?

Thanks,
Mark

Re: re: spurious values with java and SBC

Posted: Thu Mar 28, 2013 8:46 am
by Patrick
yes, I would just use 'localhost' - this is just the local interface (lo), it will never go away. The problem with using the serverID open call instead of the hostname/port call is that the server ID does not get associated with the localhost (127.0.0.1) address - so that it needs at least one valid other address (lan or wifi) to function.

-Patrick

Re: re: spurious values with java and SBC

Posted: Thu Mar 28, 2013 3:48 pm
by dstockman
Patrick:

Thanks for the advice. Opening as you suggested fixed the problem. Am I correct in assuming I can only have one open call when running on the SBC, as opposed to the multiple opens I can do when connecting via the network?

Doug

Re: re: spurious values with java and SBC

Posted: Thu Mar 28, 2013 4:30 pm
by Patrick
No, you can still use multiple opens - you are still opening using a network open, which uses the webservice.

-Patrick