Hi,
I am looking into how to add mysql support in the gateway nodejs code.
As a learning project I have been coding a python gateway alternative to receive the serial gateway moteino data and post it into mysql, send emails, etc. This is working great with my website and android app. However, I see that Felix has done an amazing job with his gateway solution so I would like to try it.
I would however need to store all the incoming messages into mysql in order for my web interface and android app to continue working properly.
I am just starting to learn nodejs so I dont know where to start, any help is appreciated.
Thanks a lot!
How about node-mysql (https://github.com/felixge/node-mysql)?
Also googling "nodejs mysql" reveals tons of tutorials online about node mysql integration.
Felix, it sure looks like this simple example shouldn't be much of a problem to implement. I still have a lot of learning to do in termes of nodejs, basically from zero, but I will try to see what I can do. I will post back if I manage to get it working.
meanwhile, I might use this thread to ask any small question that comes up during the process.
If anyone with experience has done something similar, please let me know, it would be nice to see how it is properly done by someone who knows what they are doing. But I will definitely try also
Thanks!
You essentially just need to replace the neDB code that saves the node statuses.
All the metrics are saved to binary files directly. That is a more challenging job to do and you will find that mysql will become slow once you load lots of data. That is why i never used mysql in the first place.
Interesting!
I have been timing the mysql INSERT done in my python script and usually takes between 0.05 to 0.12 seconds which I think is fast enough. Isn't it?
I guess you are talking about the graphing and loading of stored data, right? I have a web interface and android app that uses mysql data and although it is not super fast, it is ok. That is the reason for trying to start using your solution as the base of all the gateway, but add the mysql INSERT code in order to keep my interfaces working for now. I have realize I cant beat your great interface but cant throw away mine either.
I guess a good place to do the mysql stuff would be here...
Actually that is where the raw log data is posted.
I would start where the nedb data is persisted and retrieved. Look for "db." in the gateway.js file. Since nodejs is asynchronous in nature you will need to make sure the threading order of the db calls and dependent functions are kept the same.