Close

Server software

A project log for Internet of Trash

Trashcan sending the data to the internet!

mikrotronmikrotron 08/18/2016 at 12:290 Comments

What, SIM808 has AT command to monitor battery status ?!
Cool!
But now I have to modify the server, to accept it, store it, and display it.

OK let's get to it.

Command: AT+CBC

Response: +CBC: <bcs>, <bcl>,<voltage>

Where

bcs = charge status, 0 not charging, 1 charging, 2 charging finished
bcl = battery connection level, percent, 1-100
voltage = millivolts

Let's add another parameter, say, batInfo, just like we do with gpsInfo, but without parsing - we're just going to store the string received to the database, whatever it is.

The server source resides in server/src directory, and all the classes are in eu/diykits/ecotron subdirectory.

Our database consists of one table, GenericEntry. In memory, it's represented by GenericEntry class, which resides in eu/diykits/ecotron/db. The class consists of a number of public fields, and two constructors: empty one, used when hibernate loads the object from the database, and one with argument, that creates new object from a web request.

This is the source: https://github.com/mikrotron-zg/ecotron/blob/master/server/src/eu/diykits/ecotron/db/GenericEntry.java

To add another thing to it, I just need to add a public field, like this:

/** battery level info */
public String batInfo;

OK that's done.

Let's see, what else I need to implement and configure?

Well, nothing.

GenericEntry constructor takes all the parameters and maps them one-to-one. That is, whatever exists in GenericEntry, is a legal parameter to upload servlet request.

Object/relational mapping is generated automatically, and database structure modified automatically when web app starts.

Furthermore, download servlet will automatically include new field to generated CSV and JSON.

This is all done by two magic class I've been dragging around for 10+ years: HibernateDB, and DBObject.

HibernateDB handles database connections, transactions and queries, while DBObject generates textual representation of itself, either CSV, JSON, or custom.
Together, they allow for real fast prototyping.
However, full explanation of features is out of scope of this log, and project.

Let's just rebuild and redeploy our new app.

Build: ant war

Deploy: copy ecotronserver.war to your tomcat's webapp directory.

Let's check it out:

www.mikrotron.hr/ecotronserver/download?stationId=alfa

Yep, it contains batInfo string, with value null; guess that's it.

Discussions