I have a small question, what if I would like to send a newline (\n) to the cloud embedded in a string.
Background: I am testing with the Dash Pro Beta, using miniterm.py connected to an FTDI serial-USB converter wired to the Dash (at 9600 baud). I see the usual bootstrap messages, then I can enter a line, hit enter, and it is sent to the cloud. However, what if the string would be multiple lines, can that be handled? Yes, obviously I could use some kind of encoding to avoid this problem, but that seems redundant for my application, since the Webhook (https://content.konekt.io/blog/route-iot-device-data-with-api-webhooks/) already Base64 encodes what I push to the cloud.
By the way, for anyone interested, hereās what it looks like:
*** POST CALLED ***
HEADERS =
Host: mywebsite.us:10123
Content-Length: 564
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate, compress
Accept: */*
User-Agent: python-requests/2.2.1 CPython/2.7.6 Linux/3.13.0-30-generic
BODY =
{'key': ['MyKey'],
'payload': ['{"received": "2015-10-10T22:07:27.855740", "authtype": "otp", "tags": ["_SOCKETAPI_", "_SIMPLESTRING_"], "device_name": "Unnamed Device (35150)", "errorcode": 0, "source": "8944501003151035150", "timestamp": "876", "data": "VGhpcyBpcyBhIGxpbmUgb2YgdGVzdA==", "device_id": 350}'],
'properties': ['{"url": "http://mywebsite.us:10123", "user_id": 1871, "key":"MyKey"}'],
'userid': ['1871']}
REST/JSON =
{u'received': u'2015-10-10T22:07:27.855740', u'authtype': u'otp', u'tags': [u'_SOCKETAPI_', u'_SIMPLESTRING_'], u'timestamp': u'876', u'device_name': u'Unnamed Device (35150)', u'errorcode': 0, u'source': u'8944501003151035150', u'data': u'VGhpcyBpcyBhIGxpbmUgb2YgdGVzdA==', u'device_id': 350}
DATA = This is a line of test
162.242.211.19 - - [10/Oct/2015 17:06:36] "POST / HTTP/1.1" 200 -
The actual message āThis is a line of testā was what I entered. The output above was produced by a simple Python server,
# includes and override of BaseHTTPRequestHandler omitted
def do_POST(self):
print "*** POST CALLED ***"
print "HEADERS =\n", self.headers
Size = int(self.headers.get("Content-Length"))
Body = self.rfile.read(Size)
ParsedBody = urlparse.parse_qs(Body)
print "BODY =\n",ParsedBody
bodystring = ParsedBody["payload"][0]
JsonBody = json.loads(bodystring)
print "REST/JSON =\n", JsonBody
if 'data' in JsonBody:
print "DATA =", base64.b64decode(JsonBody['data'])
self.send_response(200)
self.send_header("Content-type", "application/json")
#self.send_header("Content-length", str(len(R)))
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
self.send_header("Access-Control-Allow-Origin", "*")
#self.send_header("Transfer-Encoding", "chunked")
self.end_headers()
self.wfile.close()