unipi 1.1 - Digital input counters



  • Hi,
    how can I use the digital counters. Do I have to configure it in evok.conf or is it possible to use the evok interface. Is there some documentation about setting and reading counters? This command did not work. (with real data of course)

    conn = http.client.HTTPConnection("your-ip-goes-here:8080")
    
    payload = "{\"debounce\":\"number (optional)\",\"mode\":\"string (optional)\",\"counter\":\"number (optional)\",\"counter_mode\":\"string (optional)\",\"ds_mode\":\"string (optional)\",\"alias\":\"string (optional)\"}"
    
    headers = { 'content-type': "application/json" }
    
    conn.request("POST", "/json/input/%7Bcircuit%7D", payload, headers)
    

  • administrators

    You need to set counter_mode to either "rising" or "falling", as per our documentation (the last version linked in Github):

    counter_mode
    string
    "rising","disabled" and "falling" applies only to the UniPi 1.1
    
    Allowed Values: Disabled, Enabled, rising, falling, disabled
    
    required
    

    https://evok-2.api-docs.io/1.02/rest/get-digital-input-state

    Edited: I think you are using the old version of documentation. Unfortunately api-docs doesn't allow amending older versions for legacy API reasons.

    see below



  • Hi Tomas,

    this funtion works:

        def json_set_relay(self,CIRCUIT,VALUE,TIMEOUT):
            if TIMEOUT == 0:
                payload = '{"value":"%s"}' %(str(VALUE))
            else:
                payload = '{"value":"%s","timeout":"%s"}' %(str(VALUE),str(TIMEOUT))
            with self._lock:          
                self._conn = http.client.HTTPConnection("%s:%s" %(self._host, self._port))
                self._conn.request("POST", "/json/relay/%s" %(str(CIRCUIT)), payload, self._headers) 
                res = self._conn.getresponse()
                data = res.read()
                #print(data.decode("utf-8"))
                self._conn.close()
    

    this does not work:

        def set_input(self,CIRCUIT):
            payload = '{"counter_mode":"rising"}' 
            with self._lock:      
                self._conn = http.client.HTTPConnection("%s:%s" %(self._host, self._port))		
                self._conn.request("POST", "/json/input/%s" %(str(CIRCUIT)), payload, self._headers) 
                res = self._conn.getresponse()
                data = res.read()
                self._conn.close()	
    

    Why?

    It still shows "counter_mode": false


  • administrators

    @juntiedt
    Oh! It does look like the counter_mode is forced to be set from the configuration file for the UniPi 1.1. Apologies for the confusion, I'll add the option of setting it through the API as in Neuron in the next update.



  • Hi Tomas,

    when will the update be done for the counter problem on unipi1.1?

    Also I am still not successful in filtering devices in the evok web-socket interface. I found an example on your web site doing the filtering in the on.open function of web-socket. Unfortunately it does not work.


  • administrators

    @juntiedt

    We are working on it. Currently we have been very busy with other development efforts, so there hasn't been the time to vet the update a little bit. It should be up by the end of the week.



  • counter on unipi1.1 is now working. I had to configure it in etc/evok.conf for rising or falling edge. Done this I could set and read debounce and counter. Still one question left. What is time actually representing. Number of ticks from edge to edge?


  • administrators

    It's the number of milliseconds for which a signal has to hold; there is a good explanation of it here: https://www.kernel.org/doc/Documentation/gpio/driver.txt (section titled
    "GPIOs with debounce support"). The idea being to filter out harmonics which occur due to electro-mechanical interference.