Comments (11)
I've had quite a productive night shift, so the first preliminary version of my script is done.
It's just ~50 lines of code. My first Python script ever, but I can already tell I quite like it.
Things can be done really fast with it.
Took me just a couple of hours to put this together, even as a complete noob. ;)
Right now, all my script does is listen to port 9501 and send ACK (ASCII 6) if data is received according to specifications, NAK (ASCII 21) if it's not. Excel Timestamps are incorporated in the CSV output per default. Connection won't be dropped by the server by default, however, this would just be a matter of uncommenting a line or two inside the code.
For now, it then just appends the data to a CSV file.
The filename is generated from "name" and "ID" of the JSON input, so it should be thread-safe under normal circumstances, even if two or more spindles try to connect at the same time.
The TCP listener forks accordingly.
No external libraries are required, it all "just works" in plain vanilla Python 2.7 or later.
Configuration still means editing the file itself. No big deal, though.
I've attached it, so you can play with it when you find some time.
Cheers
Stephan
from ispindel.
Awesome!
Had no time to test your work but I did my part as well! :)
Please try https://github.com/universam1/iSpindel/raw/genericTCP/bin/testing/iSpindel.3.6.0.bin
There is currently no testing against your response, but it's printed to Serial for your debugging.
You will be able to select as API now "TCP".
Let me know how things go, you can check the code at the "genericTCP" branch.
from ispindel.
OK I've had some trouble flashing the firmware from my mac, (Windows inside a VM didn't work) and had to use native Windows in Bootcamp, which worked...
After that, during configuration, the Wemos crashed a few times.
Can't reproduce that now, however, it seems to work now.
Also, switching to TCP mode at first still showed the Ubidots token as input field, only when switching to it for a second time, it showed the ip address and port fields.
Now it works and the good news is I am receiving data.
But:
My script expects the JSON to come in one line.
Looks like the spindle sends the leading "{" first, then the rest of the JSON.
This could of course also be just due to my q&d implementation.
Here's my debug output:
waiting for connection... listening on port: 9501
('192.168.2.28', 25603) received:'{'
('192.168.2.28', 25603) Error: Expecting object: line 1 column 1 (char 0)
('192.168.2.28', 25603) NAK sent. Waiting for Retry.
('192.168.2.28', 25603) received:'"name":"iSpindel01","ID":"14236088","angle":31.09,"temperature":25.25,"battery":4.30}'
('192.168.2.28', 25603) Error: Extra data: line 1 column 7 - line 1 column 86 (char 6 - 85)
('192.168.2.28', 25603) NAK sent. Waiting for Retry.`
EDIT:
Also it seems that the connection is not being closed properly from the client side.
The script keeps forking with every incoming packet.
Easily fixed on my side however, I can simply close the socket from here, if we don't want to use the "handshake" retry on NAK.
from ispindel.
Never mind, I've fixed it.
It will now gather incoming data until it encounters "}" (as it should have in the first place).
The socket is being closed after that (or when it times out).
Works like a charm now. Might want to take a look at the other issues I've mentioned before, though.
Latest version of my tiny lil' script:
iSpindle.py.gz
from ispindel.
Great I will to cache the tcp data before sending if that makes a difference.
Also I wonder what a close signal should be sent.
It is not closing because it is waiting for the reply of your script, I guess that's the reason. Can you ack and close?
from ispindel.
Yes that's what I've done now. I send ACK or NAK and close the connection server side.
I guess the issue can be closed. :)
from ispindel.
Nice, do you mind to add your script and a bit description to the Repo?
from ispindel.
Sure thing! Just been waiting for your OK to do so. Where should I put it?
from ispindel.
Great!
What about this folder https://github.com/universam1/iSpindel/tree/master/tools maybe make a subfolder and add some description in /docs
folder?
Thanks
from ispindel.
Done. Sorry for spamming Pull Requests, I've worked with GIT before but sometimes its features are still a bit elusive... (ashamed smily here)...
from ispindel.
Thats just perfect! Thanks so much, have to link to your work now in the Readme's. If there's something more to do feel free to open.
from ispindel.
Related Issues (20)
- Feature Request - MPU6500 Gyro HOT 15
- Blynk 2.0 Changed the way to connect HOT 2
- InfluxDB Authentication - Token HOT 6
- iSpindel HOT 2
- Doc link do not exist: https://www.ispindel.de/docs/tools/TestServer/Readme.md HOT 4
- Is it possible to reduce the accuracy of "battery" and keep 2-3 digits after the decimal point? HOT 10
- Wemos V4 HOT 10
- Proposition: Have a project able to route the messages HOT 3
- Discussion: What about using a ispindel github org (e.g.: https://github.com/ispindel, ...) ? HOT 5
- Issue with Ubidots API HOT 3
- Create new release :tada: HOT 3
- Firmware 7.2.0 identifies itself as 7.1.4 HOT 2
- History of tilt entity in HA not shown as line graph HOT 5
- Same issue as Issue #571 - Issue with Ubidots API HOT 2
- HTTP404 when clicking "Delete WiFi configuration and reboot" /r HOT 7
- Wrong tilt value HOT 4
- Holder for the PCB card in the container HOT 15
- Changes in ArduinoJson broke Sender.cpp HOT 1
- MQTT topic to force iSpindel in configuration (AP) mode? HOT 6
- Exception (28) on plain modules HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ispindel.