Byggahus.se

Worx Landroid development

  1. F
    Medlem Nivå 2
  2. miktr
    Medlem Nivå 2
    Yes sure! I use mosquitto as broker as well.
    You can use mosquitto_pub.exe to try the script.
    Let me know if you have any problems.
     
  3. F
    Medlem Nivå 2

    Sounds good, I got stuck immediately though :(

    I git-cloned your repository and modified config.ini.

    Do I need to change anything else in worx-landroid-mqtt.py?
    Is this the startup py btw?
    Scripts stops at import requests with error missing module.

    Also, I use cert together with my mqtt, can I specify that somewhere?

    Example of pub I use today;
    mosquitto_pub --cafile /home/pi/ca.crt -h 192.168.1.111 -p 8883

    I don't use OpenHab or Dweet, I just need to publish the values to mqtt so I can fetch them with Home Assistant

    Thanks!
     
  4. miktr
    Medlem Nivå 2
    Hi,

    I pushed a new commit with a new name of the main script, now "run.py" instead of "worx-landroid-mqtt.py".

    I also added some instructions to READEME.md.
    * Dweet is removed
    * Install the module "requests" (pip install requests)
    * To run "python run.py"

    To test with mosquitto_pub.exe:
    $ ./mosquitto_pub.exe -h 192.168.1.5 -t my_topic/command -m check
     
  5. F
    Medlem Nivå 2

    Thank you miktr
    I did a new clone, updated config.ini, installed requests and ran python run.py

    Sadly I get:
    [Errno 104] Connection reset by peer

    I can access the W796E using a browser and same url as defined in config.

    Config:

    Tested to publish to my broker and that is working (no data though for obvious reason).

    Running script as root if that matters (installation on a rPi)
     
    Redigerat av moderator 17 sep 2016 09:17
  6. F
    Medlem Nivå 2
    Jocke, did you need do modify anything to get the script to connect to the Landroid (except for ip and pin ofc)?

    I still can't connect to the mower but ping works fine from same server.
    I also get json response when using browser
     
  7. miktr
    Medlem Nivå 2
    Which version of python are you running?
    I'm can't reproduce you fault you get. I usually run Python 3.5, but I tried yesterday on a RPi with python 2.7 and it worked fine.
     
  8. F
    Medlem Nivå 2
    I was using 2.7, now I tried with python3 and got another error

    Maybe I need paho installed anyhow. I'll test some more.
     
  9. miktr
    Medlem Nivå 2
    Oh yes you do.
    I've totally missed that you didn't install that. That the client library to send and receive mqtt messages.
     
  10. F
    Medlem Nivå 2

    Ok, I did some more testing this evening.
    I cloned your repository to the same rPi running the broker.
    This way I could use localhost and 1883 for connection.

    When running python3 run.py I now get " Connected with result code0" which I assume is good?
    So the connection error was not to the landroid but to the broker.

    Anyway. when running;
    "mosquitto_pub -h localhost -t my_topic/command -m check" in another window I can see that it is publishing to my broker, however I do not get any landroid stats (which I expected). So It seems that run.py doesn't read the message sent?



    I would prefer to run this on another rPi but it seems that it have issues when you need username/password or cert?

    Thanks
     
    Redigerat 14 sep 2016 21:11
  11. F
    Medlem Nivå 2
    Fredrik Levin;2555979]Ok, I did some more testing this evening.
    I cloned your repository to the same rPi running the broker.
    This way I could use localhost and 1883 for connection.

    When running python3 run.py I now get " Connected with result code0" which I assume is good?
    So the connection error was not to the landroid but to the broker.

    Anyway. when running;
    "mosquitto_pub -h localhost -t my_topic/command -m check" in another window I can see that it is publishing to my broker, however I do not get any landroid stats (which I expected). So It seems that run.py doesn't read the message sent?


    Wild shot since Im no python programmer but arent you missing a ) when using # here?

    https://github.com/trieb/worx-landroid/blob/master/run.py#L24

    I would prefer to run this on another rPi but it seems that it have issues when you need username/password or cert?

    EDIT: reading further I might need to set mqttc.tls_set with my cert path.
    Ill test more tomorrow

    Thanks
     
    Redigerat 14 sep 2016 21:50
  12. miktr
    Medlem Nivå 2
    Hi,

    I assume run.py is started with:
    $python run.py
    >> Connected with result code0

    then, running the following in another terminal
    $ ./mosquitto_pub.exe -h localhost -t my_topic/command -m check

    should result in:
    $ python run.py
    >> Connected with result code0
    >> Received new message
    >> my_topic/command: b'check'
    >> Sending check...

    Where the last three rows indicate that run.py received the message ok, and that a status request was sent to the landroid.

    Just to make sure, in the example above the "BaseTopic" in config.ini is assumed to be set to my_topic.

    I can add some more debugging info to the script later tonight to help find out whats going wrong. Line 24 should however be ok as is is.
     
  13. F
    Medlem Nivå 2

    Hi, yes that's the way I did it.
    Basic topic is unchanged.

    I ended up starting to build a modified version so no need to dig deeper if you don't want to.
    I will use your code for communication to the landroid but instead of subscribing to the broker I will publish the messages directly by replacing your push_message (mqttc.publish) with my mosquitto code.

    I can then just put this in cron for scheduled updates.
    Not as fancy but it is working.

    Thanks for your help and effort.
     
  14. I
    Medlem Nivå 1

    Sending commands without Json

    Hi!
    Does anyone know how I can send a "Start"-command to my Landroid without using Json?
    I've tried this in C#:

    private void button1_Click(object sender, EventArgs e)
    {
    string url = "http://192.168.0.3/jsondata.cgi";
    string username = "admin";
    string password = "0000";
    string postData = @"data=[""settaggi\11,1""]";
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
    request.Headers.Add("Authorization", "Basic " + encoded);
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = byteArray.Length;
    Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();

    WebResponse response = request.GetResponse();
    textBoxReadings.Text = (((HttpWebResponse)response).StatusDescription) + Environment.NewLine;

    dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);

    string responseFromServer = reader.ReadToEnd();

    textBoxReadings.Text = textBoxReadings.Text + (responseFromServer);

    reader.Close();
    dataStream.Close();
    response.Close();
    }
     
  15. A
    Medlem Nivå 1
    Hi!
    I don't know what's wrong, it seems pretty straight forward. But I see that you retrieve the response from the movers webserver. What does it say?