AutoRemote Send via Local IP w/ Python

Discussion in 'AutoApps' started by syndac, Jan 29, 2016.

  1. syndac

    syndac New Member

    Joined:
    Jan 29, 2016
    Messages:
    6
    Likes Received:
    0
    Bear in mind, I'm new to programming.

    I'm attempting to write a Python script that sends an AutoRemote message. However, I get the following error:

    Code (Text):
    No connection could be made because the target machine actively refused it
    If I send it via the autoremotejoaomgcd.appspot.com address, it works fine. But if I try sending it directly to the local IP (on the same network, connected over WiFi, with port 1817 forwarded), I get that error.

    Here's my code (### represents my actual IP):

    Code (Text):
    import requests

    test_address = 'http://192.168.1.###:1817'
    media_type = 'test'
    state = 'message'
    autoremote_json = {
        "message": 'Test',
        "password": '',
        "ttl": 0,
        "collapsekey": '',
        "key": "RECEIVER_KEY",
        "sender": "SENDER_KEY",
        "communication_base_params": {
            "sender": "SENDER_KEY",
            "type": "Message"
        }
    }
    autoremote_header = {'content-type': 'application/json'}

    print('Notifying AutoRemote')
    response = requests.post(test_address, json=autoremote_json, headers=autoremote_header)
    I wasn't really sure what to put in the *KEY locations, but I tried the one that I can copy/paste from my goo.gl URL. No luck.

    I've also tried a simple:
    Code (Text):
    requests.post('http://192.168.1.###:1817/?message=test')
    I've seen in a forum thread from 2014 that a WiFi service needs to be turned on, but I don't see that option. I'm guessing it's deprecated.

    Any idea what I can do?
     
  2. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,477
    Likes Received:
    806
    Did you enable the AutoRemote Wifi service on your phone? :)
     
  3. syndac

    syndac New Member

    Joined:
    Jan 29, 2016
    Messages:
    6
    Likes Received:
    0
    That's what I meant by
    . Where do I find that? Is it called something other than "Wifi service"?

    Edit: Never mind. Found it in the FAQ. Wow, I feel dumb. There's a whole section in there about sending over local IP, too. Sheesh.

    Also, the message goes through, now, but I'm getting the error:

    Code (Text):
    org.json.JSONException: Value {“message”:”hello”,”sender”:”MY_PERSONAL_KEY”,”ttl”:0,”communication_base_params”:{“type”:”Message”,”fallback”:false,”via”:”Wifi”},”version”:”1.63″} of type java.lang.String cannot be converted to JSONObject.
    Any idea what to do here?

    Edit: Figured that part out, too. I copy/pasted the JSON from the FAQ and it didn't like your quotes ( " ). I don't think they're regular quotes.

     
    Last edited: Jan 29, 2016
  4. syndac

    syndac New Member

    Joined:
    Jan 29, 2016
    Messages:
    6
    Likes Received:
    0
    Here's a question, though. How big of a battery drain is the wifi service? Any reason I can't have it always on?
     
  5. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,477
    Likes Received:
    806
    I don't see any battery drain when I have it on but mileage may vary :) I only keep it on at work for example.

    Glad you got it!
     
  6. syndac

    syndac New Member

    Joined:
    Jan 29, 2016
    Messages:
    6
    Likes Received:
    0
    I may just have it always run, then. Thanks for the help!
     
: local, autoremote

Share This Page