Project Concordia – Update

Where I’m at: 

  1. Concordia.Hub:  A nodejs application that provides the UI dashboard of events and status of the home automation system.  Currently working items are:
    • Google OAUTH authentication
    • Dashboard written in VUE.js
    • Event API to store device data
    • Alexa Skill to read back sensor data by zone
  2. Alexa Skill:  A skill to interact with Amazon’s Alexa voice assistant.
  3. Concordia.Android:  An android application to monitor notifications from the hub as well as send call and message data to the Hub.
  4. Concordia.Sensor (TODO:  change to Concordia.Device):  A generic platform to configure ESP8266 sensor devices to interact with Concordia.Hub
  5. Concordia.DeviceManager:  A serial .Net application to configure the Concordia Device

Where I’m going:

  1. Open Source:  I plan to open up the source code under the MIT license for anyone that may leverage it for their own use.
  2. Continue development on each aspect above.  While the proof of concept pieces are complete, there is a lot that can be improved upon in both features and usability.
  3. RF:  I plan to create sensors that can communicate over RF where wifi is overkill or not possible due to other limitations.
  4. 3D printing enclosures:  I now own a 3D printer, so I plan to build custom enclosures using TinkerCad and eventually EagleCad.
Advertisements

The birth of Project Concordia

Concordia is the Latin word for “harmony,” literally “with (one) heart.”

I have a terrible problem of not feeling my phone vibrate when I receive a text or an email.  My plan is to build a dashboard for my car/work/home that will provide me with all the pertinent information in one place.  This will grow to include home automation and health tracking data.

The ecosystem will be several autonomous systems that are joined with a single “heart” in the cloud.  The first step will be building an alert system for incoming/missed calls and texts.  I plan to run the dashboard on an android tablet, so I’d like to use websockets to push notifications to the dashboard.  To accomplish this, I’ll build an android app that listens for incoming calls and texts and alerts the cloud app, which will in turn push a notification to the dashboard.

This will be an open-source project with the MIT license.

Now what?

So after 2.5 years of dedicating most of my free time to school and family, I now have time to look at what projects I’d like to explore.  Here’s my current list in no specific order:

  1. Create a ZoneMinder video alarm system for outside my home
    • Motion detection
    • Email alerts
  2. Create an Android tablet dashboard to show
    • Emails
    • Texts
    • Weather
    • Calendar alerts
    • News headlines
  3. Angular 2
  4. React
  5. Create an Android app to block calls
    • Not in my zip code &&
    • Not in my address book &&
    • Not in my outgoing call list &&
    • Not in my outgoing text list
  6. Work on my recipe collection to eventually publish a cook book
  7. Setup an educational instance of Linux for my 8 year old

Setting up a Django project with an ORM connected to an existing MySql instance

1.  Install Python:

https://www.python.org/downloads/release/python-279/

I had to add the following to my %PATH% variable

C:\Python27;C:\Python27\Scripts

2.  Install Django:  pip should have been installed with python so type

pip install Django==1.7.7

**Django comes with it’s own light-weight web-server, so there is no need to install one for development.

I’m going to follow https://docs.djangoproject.com/en/1.7/intro/tutorial01/ for the following steps.

3. Create the project:  Run the following command in the directory you wish to use for development.  It will create the project.

$ django-admin.py startproject CourseOptimizer

4.  Install the C++ .0 python compiler at:

https://aka.ms/vcpython27

5.  Add the MySql libraries

pip install MySql-Python (I spent about an hour before I found out it's very difficult to get it to work on windows)

pip install PyMySQL

To use it, you must go to the django directory, exactly in this directory
{..\PythonPath}\Lib\site-packages\django\db\backends\mysql
and do a search and replace of MySQLdb with pymysql
in the two files "base.py" and  "introspection.py

6.  Connect to database:  In the settings.py file, change the DATABASES variable to:

DATABASES = {
 'default': {
 'ENGINE': 'django.db.backends.mysql',
 'NAME': 'XXXXX',
 'USER': 'XXXX',
 'PASSWORD': 'XXXXX',
 'HOST': '127.0.0.1',
 'PORT': '3306',
 }
}

7. Scaffold the database schema for a Django site:

$ python manage.py migrate

8. Verify it runs:

$ python manage.py runserver

Go to http://127.0.0.1:8000

9. Create your first Models:

$ python manage.py startapp CourseCatalog

10. Map the legacy database to the models.py of the CourseCatalog app:

$ python manage.py inspectdb > coursecatalog/models.py

11. Open a python shell and verify the data has been mapped:

$ python manage.py shell
>>> from CourseCatalog.models import Course, Specialization, SpecializationCourse   # Import the model classes we just wrote.

# No questions are in the system yet.
>>> Course.objects.first().coursename
It should return the first row in the database's coursename

12. Create a view:

In the CourseCatalog/views.py file add the following and save:

from django.shortcuts import render
from django.http import HttpResponse

from CourseCatalog.models import Course

def index(request):
 course_list = Course.objects.all()[:5]
 output = ', '.join([p.coursename for p in course_list])
 return HttpResponse(output)

13. Map the view to a route

Create a file CourseCatalog/urls.py file add the following and save:
from django.conf.urls import patterns, url

from CourseCatalog import views

urlpatterns = patterns('',
 url(r'^$', views.index, name='index'),
)
In the CourseOptimizer/views.py file add the following and save:
 url(r'^coursecatalog/', include('CourseCatalog.urls')),

14. Create a template directory and index.html template

The template structure is /App/templates/App/index.html, so in this instance, create /CourseCatalog/templates/CourseCatalog/index.html and add the following:
{% if course_list %}
 <ul>
 {% for course in course_list %}
 <li>{{ course.coursename }}</li>
 {% endfor %}
 </ul>
{% else %}
 <p>No courses are available.</p>
{% endif %}

15. Run the server and verify you get a list of courses

The template structure is /App/templates/App/index.html, so in this instance, create /CourseCatalog/templates/CourseCatalog/index.html and add the following:
$ python manage.py runserver
Browse to http://127.0.0.1:8000/coursecatalog/ and see the courses

A simple static page web server using node js

nodejs-dark

I’m building a SPA using AngularJS, and Chrome doesn’t allow Angular to load the html partials because of cross origin request errors.  Firefox works, but I just prefer to develop using Chrome, so I needed to host the SPA somewhere.  IIS seemed like overkill, so I turned to Node which turned out to be very simple.

  1. Assuming you have node and NPM installed, install connect and serve-static with NPM
    $ npm install connect serve-static
  2. Create a server.js and place it in the same directory as the entry point of your SPA
    var connect = require('connect'); 
    var serveStatic = require('serve-static');
    connect().use(serveStatic(__dirname)).listen(8080);
  3. Start the web server
    $ node server.js
  4. Browse to your SPA entry page:
    http://localhost:8080/index.html

 

That’s it!  I really love some things about Node, and the simplicity of setting up a web server is one of those things.

How to add polygon search capabilities to Apache SOLR

solr

This is another post to document for myself how to add polygon search capabilities to solr since I do it very seldomly.

 

  1. >wget  http://downloads.sourceforge.net/project/jts-topo-suite/jts/1.13/jts-1.13.zip
  2. >sudo unzip jts-1.13.zip -d jts-1.13
  3. >sudo cp lib/* /var/lib/tomcat6/webapps/solr/WEB-INF/lib
  4. Add the following field type to your solr schema:
    <fieldType name=”location_rpt” class=”solr.SpatialRecursivePrefixTreeFieldType”
    spatialContextFactory=”com.spatial4j.core.context.jts.JtsSpatialContextFactory”
    distErrPct=”0.025″
    maxDistErr=”0.000009″
    units=”degrees”
    />
  5. Add a field of type “location_rpt” to index the lat/lng data:
    <field name=”geo” type=”location_rpt” indexed=”true” stored=”true” multiValued=”true” />
  6. Restart Solr
  7. Index the data in solr
  8. Query to ensure you have the ability to search a polygon:
    http://127.0.0.1:8080/solr/core0/select?q=*%3A*&fq=Geo:%22Intersects(POLYGON((-84.113824%2034.085196,-84.003009%2034.146633,-83.856827%2034.032769,-84.188127%2033.993178,-84.113824%2034.085196)))%22+&wt=json&indent=true