Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faraday-Proxy Should Handle Lists of POST Data #227

Open
kb1lqc opened this issue Jul 4, 2017 · 2 comments
Open

Faraday-Proxy Should Handle Lists of POST Data #227

kb1lqc opened this issue Jul 4, 2017 · 2 comments
Assignees
Labels

Comments

@kb1lqc
Copy link
Member

kb1lqc commented Jul 4, 2017

Summary

Check and fix any errors associated with sending data lists to Proxy via a POST HTTP message. This will help with Data applications. Initial support has been added for this feature but it is apparently broken.

Problem Explanation

  • Check that Faraday can or cannot handle list data in BASE64 format sent to it.

@kb1lqd

  • If not, fix.

Environment

Software

Faraday Software Master branch

Hardware

Faraday Rev D1

Supporting Information

N/A

@kb1lqc kb1lqc added the bug label Jul 4, 2017
@kb1lqc kb1lqc added this to the Alpha Software milestone Jul 4, 2017
@kb1lqc kb1lqc changed the title Faraday-Proxy Should handle Lists of POST Data Faraday-Proxy Should Handle Lists of POST Data Jul 4, 2017
@kb1lqc
Copy link
Member Author

kb1lqc commented Jul 4, 2017

Confirming that list support still exists. The documentation is poor 🙄. Hehe. Using POSTman in Chrome I was able to confirm that you can send a list of either one payload or multiple. It is important to remember in python you must dump to JSON with json.dumps()!

LED Commands

BASE64 commands to turn the LEDs on and off include:

LED ON

POST  HTTP/1.1
Host: 127.0.0.1:8000?port=2&nodeid=2&callsign=KB1LQC
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 010369e5-d416-732e-bfb6-f4cbe9a8587b

{
	"data":["BQZAAACA/wwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHW"]
}

LED OFF

POST  HTTP/1.1
Host: 127.0.0.1:8000?port=2&nodeid=2&callsign=KB1LQC
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 9d1edba1-b34b-836e-f065-f172f992f9f2

{
	"data":["BQYAAADA/wwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHW"]
}

Python Payload

In Python a valid request would be:

import requests
import json

url = "http://127.0.0.1:8000/"

querystring = {"port":"2","nodeid":"2","callsign":"KB1LQC"}

payload = {"data":["BQZAAACA/wwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHW"]}
payload = json.dumps(payload)
headers = {
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

Multiple Packets

All we need to do is make the dictionary a list in python before using json.dumps(). The code below sends an LED ON command as the first item and an LED OFF command as the second item:

import requests
import json

url = "http://127.0.0.1:8000/"

querystring = {"port":"2","nodeid":"2","callsign":"KB1LQC"}

payload = {"data":[
                    "BQZAAACA/wwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHW",
                    "BQYAAADA/wwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHW"]}
payload = json.dumps(payload)
headers = {
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

@kb1lqc
Copy link
Member Author

kb1lqc commented Jul 4, 2017

FYI @kb1lqd there is currently a maximum length of 100 items in the list. Let me know if this should be changed. Sorta arbitrary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants