tisdag 31 januari 2017

Still email-problems with Binero, focused on PHP and MySQLi

I've made a simple website now that shows:

Raspberry pi last upload: 2017-01-31 14:21:12

Raspberry pi has been offline: 48.37 minutes

Offline warning
sending SMS...
sending mail...
Uploading alarmtime... 


If the raspberry pi doesnt upload data within 1 minute, it reacts.

I have not yet fixed the mail-sending, sms-sending or uploading alarmtime. But it calculates a correct deltatime since the r-pi been up and reacts.

Tomorrow I'll focus on making the SMS part and uploading alarmtime done. The alarmtime is the time when this site sends the Offline warning. If that isn't saved somehow, the site will continually send sms. We just want one sms.

måndag 30 januari 2017

Binero, SMTP and an image from webcam

I couldn't fix the TLS error by myself and I thought I'd buy some time by calling Binero about the problem. We talked and then he started looking at my uploaded code, he said he was going to mail me about the problem so I don't have to wait in the phone. 2 hours later nothing, so I'll check tomorrow.

In the mean time I focused on writing the rapport for school and connected r-pi to the webcam to get an image, this image is going to be sent by email if there is an alarm. Neat?

And I learned some about TLS STARTTL and SSL.

fredag 27 januari 2017

SSH tunneling magically works

Somehow when I tried to connect and try what I tried yesterday, it worked. Instead of getting:

_mysql_exceptions.OperationalError: (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 0")

I got the name of the database version used (I sent the SQL "SELECT VERSION()")

I checked the connections with netstat and ps aux and it seemed like yesterday.

I tried to replicate the error but it allways worked now. So I went to upload some mysql.

I got stuck like half an hour because I forgot commit()... But then I got it to work so now the database is updated every 10 min with sensordata. So now I can fully focus on the server-part. (I'm going to have problems in the future with SSH and if I have time I'll look into autossh to fix this)

Then I started to look at sending email from the server again. No significant progress but I narrowed it down to that TLS seems not to be started by my PHP-script. So Tomorrow I'll be checkin' if that's the solution to the error:

authentication failure [SMTP: STARTTLS failed (code: 220, response: 2.0.0 Ready to start TLS)]

I am also VERY happy of my troubleshooting documenting system I talked about in a previous post. This helps SO much to have all the relevant history. I also think it helps me focus about the right concepts and remember to forget about things that is not important. Get it?

torsdag 26 januari 2017

SSH tunneling is so hard

Made MySQL program in python and it works with my windows laptop. I use putty to make the SSH-tunnel. But on my r-pi with linux i need to write stuff like:

ssh -fNg -L 3306:xxxxxxxxx.mysql.binero.se:xxxxxxxx@ssh.binero.se

And it makes me so confused. I managed to understand a lot but I think I have to learn a lot more before I get this to work... Going to continue with it tomorrow anyhow. Maybe I'll post on stack overflow for this one.

onsdag 25 januari 2017

Online alarm surveillance designed and Email with PHP

Got an answer from Binero about how to create an online checking alarm-system thing. A site that checks each halfhour if a system on another place is online, connected to the internet and alive and well. Apperently they offer a service to schedule running of URLs. This is perfect. This means I just need to make a site that checks if the remote alarm is okay and if not, it sends email and sms.

The Raspberry pi updates a MySQL database every halfhour or 5 min.
The online server checks if the r-pi has reported that it's okay.

This way we do not need to worry about opening ports on a router. This is important if we encouter a customer with several routers and we probably never need to put effort in configuring a router.

So I focused on making a site to send email. I choose to use PHP since I'd like to have a little more experience on that. But later I think I maybe should have used javascript..well well.

I learned that the server on binero can be run just like a raspberry pi using SSH to connect. I had to do this to install PEAR for PHP to send email. Haven't got it to work yet, big trouble connecting in the right way.

Learned some more PHP on codecademy really great site!

Tomorrow I'll be trying to fix this even more and then go on to make a POST to cellsynt to send SMS.

tisdag 24 januari 2017

Had a presentation today

Presented my work to Andreas and Anton, and it was appreciated. They where also interested in how I work using a winscp - script to load up files fast and work with wing to program. Also the dataplicity connection making it available from anywhere was also interesting. I'm going to help them to set those things up so they know how.

I have also tried to set up the r-pi to run a command and the python program at startup but have not yet succeeded. Will continue with that tomorrow and then focus on making an online server checking data on a database. The pi will upload status every 5 minutes and the online server will check each half hour or so to see if there's been an upload the last half hour, if it hasn't, it will send sms or email telling that the r-pi might be down and not able to send alarms.

If I would make a server that connects to the r-pi, it would need to act as a webbservice and we would have to open ports on the router.

But doing it with a database means we don't have to open any ports on a router so if the system is to be made for a customer we don't have to manage a lot of routers, because there could be several routers on routers and legal things and other things that prevents from ports beeing opened.

Tomorrow, online server. It's nice that I've set up the other stuff for email and sms, so it should be pretty easy to have the server do that as well.

måndag 23 januari 2017

I think I made it to complex/big

Today I've worked out the bug from last week. I just realized that it shouldn't be fixed until it is discovered when making a system for a customer. The problem is that it will send alarms to often. I don't know how to fix it without breaking the readability of the code, and I have not much time. I have prioritized other things more important.

I've started thinking about the online service that will check if the system is online and working.

I have also tidied up the code, made a map so it's easier to understand the code.

Tomorrow I will show what I've worked on and what needs a configuration and how the system can be adapted to other alarms. But I'm not satisyed because it's pretty messy still. Maybe I should have focused on making it easy to understand instead of making it modular. I will also continue working on the online service.