Firmata over Ethernet: Einbindung in Arduino

Begonnen von CaptBlaubaer, 27 Oktober 2013, 00:44:58

Vorheriges Thema - Nächstes Thema

strauch

Zitat von: sackCfix am 10 Februar 2014, 16:57:30
Ok,

habe jetzt mal Version 1.03 genommen, mal schauen ob es damit besser läuft.

@strauch: Welche Hardware verwendest du denn, ebenfalls Nano+ENC?

Andreas

Ja Nano und Enc. Hab aber version 1.01 mal schauen ob ich auf 1.55 wechsel. @Nobert: Dürfte die besser beim reconnecten sein? Wobei als ich heute mein raspberrypi mit neuer Stromversorgung versehen habe, klappte auch die Verbindung nach dem einstecken.
FHEM 5.6 VMware mit Debian. 1 CUL für FS20 und HMLAN für Homematic, HM-CC-RT-DN, HM-LC_Sw1PBU-FM, HM-LC-Bl1PBU-FM,  HM-SEC-SC, HM-SEC-SC-2, HM-LC-Sw1-Pl2, HM-Sec-RHS, ASH2200, FHT80B, S20KSE, Sonos, XBMC, FB_Callmonitor, SMLUSB, Arduino Firmata, uvm.

ntruchsess

#61
Zitat von: strauch am 10 Februar 2014, 23:05:18mal schauen ob ich auf 1.55 wechsel. @Nobert: Dürfte die besser beim reconnecten sein?
Ja, ich denke schon. Gegenüber der Version 1.01 ist u.a. dieser Fix in der UIPClient.connected()-methode reingekommen, der direkten Einfluss auf den Reconnect hat.

Arduino_1.5.5 ist übrigens keine Versionsangabe der Library, sondern der Name des betreffenden Branches. Bezieht sich auf die Version der Arduino-IDE, für die dieser Branch da ist ;-)
Aktuell verbirgt sich darin Version 1.52+ein paar Fixes.

Gruß,

Norbert
while (!asleep()) {sheep++};

sackCfix

Hmm,
1.03 hat´s auch nicht gebracht, dann teste ich mal die neue Version. Die Kommunikation mit dem Arduino scheint FHEM abzuschiessen, ist mir eben erst im Log aufgefallen. Solange die Verbindung da ist:

2014.02.11 08:29:57 5: Triggering BMP085 (4 changes)
2014.02.11 08:29:57 5: Notify loop for BMP085 T: 31.1 P: 936.7 P-NN: 1007.3
2014.02.11 08:29:57 4: eventTypes: I2C_BMP180 BMP085 T: 31.1 P: 936.7 P-NN: 1007.3 -> T: .* P: .* P-NN: .*
2014.02.11 08:29:57 4: eventTypes: I2C_BMP180 BMP085 temperature: 31.1 -> temperature: .*
2014.02.11 08:29:57 4: eventTypes: I2C_BMP180 BMP085 pressure: 936.7 -> pressure: .*
2014.02.11 08:29:57 4: eventTypes: I2C_BMP180 BMP085 pressure-nn: 1007.3 -> pressure-nn: .*
2014.02.11 08:29:59 5: >f0,73,01,08,f7
2014.02.11 08:29:59 5: SW: ?s?
2014.02.11 08:29:59 5: >f0,73,24,08,28,1e,19,2c,53,00,00,00,64,09,01,f7
2014.02.11 08:29:59 5: SW: ?s$(,Sd ?
2014.02.11 08:29:59 5: >f0,73,01,08,f7
2014.02.11 08:29:59 5: SW: ?s?
2014.02.11 08:29:59 5: >f0,73,2c,08,28,1e,19,2c,53,00,00,00,64,13,00,50,2b,40,2f,f7
2014.02.11 08:29:59 5: SW: ?s,(,SdP+@/?
2014.02.11 08:29:59 5: <f0,73,43,08,3a,05,7c,03,30,49,51,3f,7f,03,40,70,00,f7
2014.02.11 08:30:00 5: Triggering Temp2 (2 changes)
2014.02.11 08:30:00 5: Notify loop for Temp2 temperature: 7.9375
2014.02.11 08:30:00 4: eventTypes: OWTHERM Temp2 temperature: 7.9375 -> temperature: .*
2014.02.11 08:30:00 4: eventTypes: OWTHERM Temp2 T:  7.94 °C ? -> T:  .* °C ?


Sobald der Arduino nicht mehr erreichbar ist:
2014.02.11 08:49:57 5: Triggering BMP085 (4 changes)
2014.02.11 08:49:57 5: Notify loop for BMP085 T: 31.5 P: 936.7 P-NN: 1007.3
2014.02.11 08:49:57 4: eventTypes: I2C_BMP180 BMP085 T: 31.5 P: 936.7 P-NN: 1007.3 -> T: .* P: .* P-NN: .*
2014.02.11 08:49:57 4: eventTypes: I2C_BMP180 BMP085 temperature: 31.5 -> temperature: .*
2014.02.11 08:49:57 4: eventTypes: I2C_BMP180 BMP085 pressure: 936.7 -> pressure: .*
2014.02.11 08:49:57 4: eventTypes: I2C_BMP180 BMP085 pressure-nn: 1007.3 -> pressure-nn: .*
2014.02.11 13:46:22 1: Including fhem.cfg


Bin momentan bei der normalen OWX-Version, meine aber bei der async und nothread war es genau das gleiche Verhalten. Ich teste mal und überwache den Arduino jetzt mal per Dauermessung am Logicanalyzer, dann weiß ich wenigstens den genauen Zeitpunkt wann er aussteigt.

Andreas

ntruchsess

hast Du auch irgendwo die Ausgabe des perl-prozesses selbst (zur Not von der Kommandozeile aus starten und diese offen lassen...)? Im Log steht ja nur, was geloggt werden soll, aber normalerweise nix, wenn FHEM abstürzt (das schreibt perl nach stdout).

Hab gestern und heute endlich mal 2 schön länger gesuchte Fehler im UIPEthernet gefixed:
1. sporadische Hänger nach wiederholtem client.close()
2. Fehlerhafte ARP-packete beim ersten Versenden von UDP.

Gruß,

Norbert
while (!asleep()) {sheep++};

sackCfix

Nein,
leider noch nicht, leite stdout und stderr jetzt aber in eine Datei um damit ich beim nächsten mal mehr weiß.

Andreas

sackCfix

Ok,
hier mal der Auszug aus stdout:
Use of uninitialized value in concatenation (.) or string at ./FHEM/21_OWCOUNT.pm line 1107.
Use of uninitialized value in concatenation (.) or string at ./FHEM/21_OWCOUNT.pm line 1110.
Use of uninitialized value in concatenation (.) or string at ./FHEM/21_OWCOUNT.pm line 1111.
Use of uninitialized value $text in concatenation (.) or string at fhem.pl line 660.
Argument "" isn't numeric in sprintf at ./FHEM/21_OWCOUNT.pm line 550.
Argument "" isn't numeric in sprintf at ./FHEM/21_OWCOUNT.pm line 550.
Can't call method "packet_onewire_request" on an undefined value at FHEM/lib/Device/Firmata/Platform.pm line 744.


Dabei sind die letzten 3 Zeilen vor dem Fehler entstanden, die anderen beim ersten aufrufen von OWX.


Andreas

sackCfix

So,
die Version 1.5.5 der UIPEthernet scheint stabil zu laufen, nach einem Neustart von FHEM meldet sich der Arduino recht schnell wieder, hat sich seit 5 Tagen auch nicht mehr aufgehängt.
Allerdings habe ich immer noch das Problem Can't call method "packet_onewire_request" on an undefined value at FHEM/lib/Device/Firmata/Platform.pm line 744., FHEM stürzt mir deswegen fast täglich ab, versteh nur nicht was im an Value nicht passt.

Andreas

sackCfix

Hier mal noch wie man stdout und stderr in eine Datei umleitet:
sudo service fhem start &> log.txt

Falls man auch noch Datum/Uhrzeit will:
sudo service fhem start &> >( while read line; do echo "$(date): $(line)"; done > log.txt)

Achja, mein Problem mit FHEM liegt klar an OWCOUNT, folgende Fehler habe ich:
-Use of uninitialized value in concatenation (.) or string at ./FHEM/21_OWCOUNT.pm line 1108
-Argument "" isn't numeric in sprintf at ./FHEM/21_OWCOUNT.pm line 550.
-Illegal division by zero at ./FHEM/21_OWCOUNT.pm line 490.


Andreas

strauch

Danke für die Info das kann ich gut gebrauchen

Gesendet von meinem Nexus 4 mit Tapatalk

FHEM 5.6 VMware mit Debian. 1 CUL für FS20 und HMLAN für Homematic, HM-CC-RT-DN, HM-LC_Sw1PBU-FM, HM-LC-Bl1PBU-FM,  HM-SEC-SC, HM-SEC-SC-2, HM-LC-Sw1-Pl2, HM-Sec-RHS, ASH2200, FHT80B, S20KSE, Sonos, XBMC, FB_Callmonitor, SMLUSB, Arduino Firmata, uvm.

Olly

Hallo,

ich Teste zur Zeit auch einen Arduino mit Firmata. Zum Einsatz kommt bei mir ein Uno R3 mit Wiznet W5100 basierendem Ethernet-Shield.
Zuerst habe ich etwas mit 1-Wire getestet, aber da wurde FHEM auf meinem Raspberry zu undefinierten Zeiten beendet, meist klappte aber schon die Kommunikation mit dem Arduino nicht. Das mag vielleicht auch daran gelegen haben, dass ich ganz normal OWX verwendet habe und nicht die spezielle non-blocking Methode.
Aktuell habe ich einen LM335Z (Temperatursensor) an einem analogen Pin des Arduino. Was mir hier jetzt auffällt ist, dass ich im Sekunden-Takt die AD-Werte des Pins übermittelt bekomme. Kann man das Zeitintervall irgendwo konfigurieren, oder wird vom Arduino immer dann gesendet, wenn sich der gelesene Wert ändert??
Der gelesene Wert scheint mir auch zu hoch zu sein (entspricht ca. 30°C), was durch eine Eigenerwärmung durch das ständige Lesen des AD-Wertes zustande kommen könnte.

Weiterhin erhalte ich im FHEM-Log immer mal wieder die Meldung, dass das Firmata-Device disconnected und auf ein "reappear" gewartet wird, was dann auch geschieht. Ist das normal, oder gibt's hier auch noch ein Problem? Für Ethernet mit W5100 brauche ich ja nicht den UIPEthernet zu verwenden, richtig?

Hoffe ihr könnt mir ein wenig weiter helfen.

Gruß

     Olly
BananaPi 1GB;NetCSM 868MHz, miniCUL 433MHz, LaCrosseGateway, 2x SignalESP; FHEM 6.2

strauch

Zitat von: Olly am 21 Februar 2014, 10:39:41
Aktuell habe ich einen LM335Z (Temperatursensor) an einem analogen Pin des Arduino. Was mir hier jetzt auffällt ist, dass ich im Sekunden-Takt die AD-Werte des Pins übermittelt bekomme. Kann man das Zeitintervall irgendwo konfigurieren, oder wird vom Arduino immer dann gesendet, wenn sich der gelesene Wert ändert??

Du kannst FHEM sagen, das er nur alle X Sekunden auslesen soll z.B:
attr xx_Temperatur event-min-interval .*:540

.* heißt in dem Fall alle Werte und 540 sind die Sekunden (also alle 9min).
statt .* kannst du auch besstime Readings oder States angeben, dann wird alles andere immer ausgelesen und nur dieser eine Wert alle 9min.
FHEM 5.6 VMware mit Debian. 1 CUL für FS20 und HMLAN für Homematic, HM-CC-RT-DN, HM-LC_Sw1PBU-FM, HM-LC-Bl1PBU-FM,  HM-SEC-SC, HM-SEC-SC-2, HM-LC-Sw1-Pl2, HM-Sec-RHS, ASH2200, FHT80B, S20KSE, Sonos, XBMC, FB_Callmonitor, SMLUSB, Arduino Firmata, uvm.

fhainz

Hallo!

Ich schaffe es einfach nicht meine Arduino Mega per Lan in FHEM einzubinden. Via USB klappt alles wunderbar.
Wenn ich in meinen Router schaue wird der arduino mit der zugewiesenen ip als verbunden angeführt aber in fhem steht immer disconnected.
Ethernet Shield hab ich dieses hier

Sketch:
/*
* Firmata is a generic protocol for communicating with microcontrollers
* from software on a host computer. It is intended to work with
* any host computer software package.
*
* To download a host software package, please click on the following link
* to open the download page in your default browser.
*
* http://firmata.org/wiki/Download
*/

/*
  Copyright (C) 2006-2008 Hans-Christoph Steiner.  All rights reserved.
  Copyright (C) 2010-2011 Paul Stoffregen.  All rights reserved.
  Copyright (C) 2009 Shigeru Kobayashi.  All rights reserved.
  Copyright (C) 2009-2013 Jeff Hoefs.  All rights reserved.
  Copyright (C) 2013 Norbert Truchsess. All rights reserved.
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  See file LICENSE.txt for further informations on licensing terms.

  formatted using the GNU C formatting and indenting
*/


#include <Firmata.h>

/*
* by default Firmata uses the Serial-port (over USB) of Arduino.
* ConfigurableFirmata may also comunicate over ethernet using tcp/ip.
* To configure this 'Network Firmata' to use the original WIZ5100-based
* ethernet-shield or Arduino Ethernet uncomment the includes of 'SPI.h' and 'Ethernet.h':
*/

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

/*
* To configure 'Network Firmata' to use an ENC28J60 based board include
* 'UIPEthernet.h' (no SPI.h required). The UIPEthernet-library can be downloaded
* from: https://github.com/ntruchsess/arduino_uip
*/

//#include <UIPEthernet.h>

#if defined ethernet_h || defined UIPETHERNET_H
/*==============================================================================
* Network configuration for Network Firmata
*============================================================================*/
#define NETWORK_FIRMATA
//replace with ip of server you want to connect to, comment out if using 'remote_host'
#define remote_ip IPAddress(10,0,0,40)
//replace with hostname of server you want to connect to, comment out if using 'remote_ip'
//#define remote_host "server.local"
//replace with the port that your server is listening on
#define remote_port 3030
//replace with arduinos ip-address. Comment out if Ethernet-startup should use dhcp
#define local_ip IPAddress(10,0,0,56)
//replace with ethernet shield mac. It's mandatory every device is assigned a unique mac
const byte mac[] = {0x90,0xA2,0xDA,0x0D,0x07,0x02};
#endif

// To configure, save this file to your working directory so you can edit it
// then comment out the include and declaration for any features that you do
// not need below.

// Also note that the current compile size for an Arduino Uno with all of the
// following features enabled is about 22.4k. If you are using an older Arduino
// or other microcontroller with less memory you will not be able to include
// all of the following feature classes.

#include <utility/DigitalInputFirmata.h>
DigitalInputFirmata digitalInput;

#include <utility/DigitalOutputFirmata.h>
DigitalOutputFirmata digitalOutput;

#include <utility/AnalogInputFirmata.h>
AnalogInputFirmata analogInput;

#include <utility/AnalogOutputFirmata.h>
AnalogOutputFirmata analogOutput;

#include <Servo.h> //wouldn't load from ServoFirmata.h in Arduino1.0.3
#include <utility/ServoFirmata.h>
ServoFirmata servo;

#include <Wire.h> //wouldn't load from I2CFirmata.h in Arduino1.0.3
#include <utility/I2CFirmata.h>
I2CFirmata i2c;

#include <utility/OneWireFirmata.h>
OneWireFirmata oneWire;

#include <utility/StepperFirmata.h>
StepperFirmata stepper;

#include <utility/FirmataExt.h>
FirmataExt firmataExt;

#include <utility/FirmataScheduler.h>
FirmataScheduler scheduler;


// dependencies. Do not comment out the following lines
#if defined AnalogOutputFirmata_h || defined ServoFirmata_h
#include <utility/AnalogWrite.h>
#endif

#if defined AnalogInputFirmata_h || defined I2CFirmata_h
#include <utility/FirmataReporting.h>
FirmataReporting reporting;
#endif

// dependencies for Network Firmata. Do not comment out.
#ifdef NETWORK_FIRMATA
#if defined remote_ip && defined remote_host
#error "cannot define both remote_ip and remote_host at the same time!"
#endif
#include <utility/EthernetClientStream.h>
EthernetClient client;
#if defined remote_ip && !defined remote_host
#ifdef local_ip
  EthernetClientStream stream(client,local_ip,remote_ip,NULL,remote_port);
#else
  EthernetClientStream stream(client,IPAddress(0,0,0,0),remote_ip,NULL,remote_port);
#endif
#endif
#if !defined remote_ip && defined remote_host
#ifdef local_ip
  EthernetClientStream stream(client,local_ip,IPAddress(0,0,0,0),remote_host,remote_port);
#else
  EthernetClientStream stream(client,IPAddress(0,0,0,0),IPAddress(0,0,0,0),remote_host,remote_port);
#endif
#endif
#endif

/*==============================================================================
* FUNCTIONS
*============================================================================*/

void systemResetCallback()
{
  // initialize a defalt state

  // pins with analog capability default to analog input
  // otherwise, pins default to digital output
  for (byte i=0; i < TOTAL_PINS; i++) {
    if (IS_PIN_ANALOG(i)) {
#ifdef AnalogInputFirmata_h
      // turns off pullup, configures everything
      Firmata.setPinMode(i, ANALOG);
#endif
    } else if (IS_PIN_DIGITAL(i)) {
#ifdef DigitalOutputFirmata_h
      // sets the output to 0, configures portConfigInputs
      Firmata.setPinMode(i, OUTPUT);
#endif
    }
  }

#ifdef FirmataExt_h
  firmataExt.reset();
#endif
}

/*==============================================================================
* SETUP()
*============================================================================*/

void setup()
{
#ifdef NETWORK_FIRMATA
#ifdef local_ip
  Ethernet.begin((uint8_t*)mac,local_ip);  //start ethernet
#else
  Ethernet.begin((uint8_t*)mac); //start ethernet using dhcp
#endif
  delay(1000);
#endif
  Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);

#if defined AnalogOutputFirmata_h || defined ServoFirmata_h
  /* analogWriteCallback is declared in AnalogWrite.h */
  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
#endif

  #ifdef FirmataExt_h
#ifdef DigitalInputFirmata_h
  firmataExt.addFeature(digitalInput);
#endif
#ifdef DigitalOutputFirmata_h
  firmataExt.addFeature(digitalOutput);
#endif
#ifdef AnalogInputFirmata_h
  firmataExt.addFeature(analogInput);
#endif
#ifdef AnalogOutputFirmata_h
  firmataExt.addFeature(analogOutput);
#endif
#ifdef ServoFirmata_h
  firmataExt.addFeature(servo);
#endif
#ifdef I2CFirmata_h
  firmataExt.addFeature(i2c);
#endif
#ifdef OneWireFirmata_h
  firmataExt.addFeature(oneWire);
#endif
#ifdef StepperFirmata_h
  firmataExt.addFeature(stepper);
#endif
#ifdef FirmataReporting_h
  firmataExt.addFeature(reporting);
#endif
#ifdef FirmataScheduler_h
  firmataExt.addFeature(scheduler);
#endif
#endif
  /* systemResetCallback is declared here (in ConfigurableFirmata.ino) */
  Firmata.attach(SYSTEM_RESET, systemResetCallback);

  // Network Firmata communicates with Ethernet-shields over SPI. Therefor all
  // SPI-pins must be set to IGNORE. Otherwise Firmata would break SPI-communication.
  // add Pin 10 and configure pin 53 as output if using a MEGA with Ethernetshield.
  // No need to ignore pin 10 on MEGA with ENC28J60, as here pin 53 should be connected to SS:
#ifdef NETWORK_FIRMATA
  // ignore SPI and pin 4 that is SS for SD-Card on Ethernet-shield
  for (byte i=0; i < TOTAL_PINS; i++) {
    if (IS_PIN_SPI(i)
        || 4==i
        // || 10==i //explicitly ignore pin 10 on MEGA as 53 is hardware-SS but Ethernet-shield uses pin 10 for SS
        ) {
      Firmata.setPinMode(i, IGNORE);
    }
  }
//  pinMode(PIN_TO_DIGITAL(53), OUTPUT); configure hardware-SS as output on MEGA
  pinMode(PIN_TO_DIGITAL(4), OUTPUT); // switch off SD-card bypassing Firmata
  digitalWrite(PIN_TO_DIGITAL(4), HIGH); // SS is active low;

  // start up Network Firmata:
  Firmata.begin(stream);
#else
  // start up the default Firmata using Serial interface:
  Firmata.begin(57600);
#endif
  systemResetCallback();  // reset to default config
}

/*==============================================================================
* LOOP()
*============================================================================*/
void loop()
{
#ifdef DigitalInputFirmata_h
  /* DIGITALREAD - as fast as possible, check for changes and output them to the
   * stream buffer using Firmata.write()  */
  digitalInput.report();
#endif

  /* STREAMREAD - processing incoming messagse as soon as possible, while still
   * checking digital inputs.  */
  while(Firmata.available()) {
    Firmata.processInput();
#ifdef FirmataScheduler_h
    if (!Firmata.isParsingMessage()) {
      goto runtasks;
    }
  }
  if (!Firmata.isParsingMessage()) {
runtasks: scheduler.runTasks();
#endif
  }

  /* SEND STREAM WRITE BUFFER - TO DO: make sure that the stream buffer doesn't go over
   * 60 bytes. use a timer to sending an event character every 4 ms to
   * trigger the buffer to dump. */

#ifdef FirmataReporting_h
  if (reporting.elapsed()) {
#ifdef AnalogInputFirmata_h
    /* ANALOGREAD - do all analogReads() at the configured sampling interval */
    analogInput.report();
#endif
#ifdef I2CFirmata_h
    // report i2c data for all device with read continuous mode enabled
    i2c.report();
#endif
  }
#endif
#ifdef StepperFirmata_h
  stepper.update();
#endif
#if defined NETWORK_FIRMATA && !defined local_ip
  if (Ethernet.maintain())
    {
      stream.maintain(Ethernet.localIP());
    }
#endif
}


FHEM:
define FIRMATA FRM 10.0.0.56 3030 global
attr FIRMATA sampling-interval 1000
attr FIRMATA verbose 3


Die im Sketch angegebenen Server IP stimmt und in beiden Dateien steht der gleich port aber Verbindung kommt leider keine zustande.

Hat jemand eine Idee?

Grüße

Olly

#72
Hallo fhainz,

ich glaube deine Firmata Definition ist nicht richtig, die Angabe der IP-Adresse ist zu viel. Ich habe das so definiert:


define FIRMATA FRM 3030 global


Gruß

      Olly
BananaPi 1GB;NetCSM 868MHz, miniCUL 433MHz, LaCrosseGateway, 2x SignalESP; FHEM 6.2

fhainz

Danke!!
Das hab ich anscheinend übersehen. Nun funktionierst :)

Grüße

strauch

Zitat von: ntruchsess am 10 Februar 2014, 23:48:36
Ja, ich denke schon. Gegenüber der Version 1.01 ist u.a. dieser Fix in der UIPClient.connected()-methode reingekommen, der direkten Einfluss auf den Reconnect hat.

Hi Norbert,

Ich hab die neue Version vor ein paar Tagen in mein Arduino eingespielt und seit dem verbindet er sich auch direkt wieder wenn ich viel eingespielt habe.

Danke

Gesendet von meinem Nexus 4 mit Tapatalk

FHEM 5.6 VMware mit Debian. 1 CUL für FS20 und HMLAN für Homematic, HM-CC-RT-DN, HM-LC_Sw1PBU-FM, HM-LC-Bl1PBU-FM,  HM-SEC-SC, HM-SEC-SC-2, HM-LC-Sw1-Pl2, HM-Sec-RHS, ASH2200, FHT80B, S20KSE, Sonos, XBMC, FB_Callmonitor, SMLUSB, Arduino Firmata, uvm.