Author Topic: Mobile interface  (Read 1678 times)

mapoisson

  • Newbie
  • *
  • Posts: 9
    • View Profile
Mobile interface
« on: June 20, 2016, 07:31:02 pm »
Hi,

Is there some plan to develop mobile apps (iPhone/iPad, Android) that would allow to run scripts, consult major indicators (ex. Temperature), and receive notifications? That would be extremely practical. I'm not hyper technical, and having the possibilty of easily using code develop by others would be nice.
« Last Edit: June 20, 2016, 07:33:08 pm by mapoisson »

Share on Facebook Share on Twitter


kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Mobile interface
« Reply #1 on: June 20, 2016, 07:40:01 pm »
Hello.
Maybe you could tell us some more about this. Do you have some more examples.
The built in support for MQTT and IFTTT makes it possible already and it does not need to be only for mcThings.

Example with IFTTT then you could get a message to your phone if the temperature us abow a selected value or if a door is opened or closed and things like this hat.

But please provide a scenario and let's see what we could do to solve it.

mapoisson

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Mobile interface
« Reply #2 on: June 20, 2016, 08:24:38 pm »
I don't really have tons of scenarios in mind at the moment. The only one I would like to exploit to date, if it can withstand it, is using modules to monitor my freezer, and refrigirator in case the temperature go above some point in case of a power outage, and notify me on my cell if it happen. Is there some IFTTT recipies already available (for this, and in general)? I haven't seen any in the IFTTT database
« Last Edit: June 20, 2016, 08:33:24 pm by mapoisson »

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Mobile interface
« Reply #3 on: June 21, 2016, 01:57:41 am »
That is a perfect scenario to start with and I have to say that its not that hard to accomplish.

You let the mcModule handle the temperatur calculation and sends to IFTTT when the temperatur is above a value that you have set.
And then you have to decide what kind of message you want to have to your phone, maybe mail or something, that you will configure in your recipe on IFTTT.

Let me know if you want the code for this.

mapoisson

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Mobile interface
« Reply #4 on: June 21, 2016, 07:02:33 am »
I would definitely like to have the code, even though it would be useful just right now. We have an outage that begun last night. We will probably lost a part of our fridge if electricity don't get back soon. Freezer should be fine ... if electricity get back in the next 4-6 hours.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Mobile interface
« Reply #5 on: June 21, 2016, 08:11:54 am »
Here is a simple code that will publish to IFTTT if the temperatur gets to hot, this code will get you started but maybe you should add some more functions that will notify you when the temperatur is in the correct range again and things like that.

Code: [Select]
Class Temperature
    Shared Event GetTemp() RaiseEvent Every 1 Minutes
       
        Dim Temp As Float = TempSensor.GetTemp
        Dim tempstring As String = Temp.ToString()
       
        If Temp > 5 Then
            //Temperatur is more then 5
            Lplan.IFTTT("Your key", "NameofRecipe", tempstring, "", "")
        Else
            //Temperatur is not more then 5
        End If
       
    End Event
End Class

When you add this code in mcStudio then you also need to add the TempSensor library from File/Add Library Code.

And now you need to create a IFTTT recipe
Trigger channel "Maker"
Action Channel "Gmail"
and select Send an Email, now you could receive an email when the temperatur gets to high.

Let me know if any part of this need better explanation or if you have other questions.

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Mobile interface
« Reply #6 on: June 21, 2016, 10:13:35 am »
@Kristofferis - Great code, thanks for your help!

@Mapoisson - One thing to think about when using monitoring your freezer, there are industrial style 3V batteries that can handle lower temperatures better than standard cr2032 batteries. Since the mc-Modules are rated to work to -40C, the hardware is not an issue but you may lose battery life on a regular 3V when it is in your freezer for a long time. Might be something to look into if you are planning on keeping the module in your freezer for a while
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Mobile interface
« Reply #7 on: June 21, 2016, 03:30:27 pm »
Maybe a BR2032 is better suited for this.
I will buy some BR and make some test, I became little curious. :)

mapoisson

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Mobile interface
« Reply #8 on: June 21, 2016, 03:59:51 pm »
Thanks for all this. I will try this this weeked. Where can we fin BR2032 in Canada? Amazon.ca don't seems to have them.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Mobile interface
« Reply #9 on: June 21, 2016, 04:11:06 pm »
Well i noticed that here in Sweden that the stores that is selling mostly for home use they does only have CR but some stores that is selling mostly to companies they sell both BR and CR.
So maybe the same in Canada. 

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Mobile interface
« Reply #10 on: June 21, 2016, 04:22:46 pm »
The easiest might be ordering online through a store like digikey: http://www.digikey.ca/product-detail/en/panasonic-bsg/BR-2032-BN/P186-ND/31924 or you could try some specialty electronic stores as well.
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

mapoisson

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Mobile interface
« Reply #11 on: June 24, 2016, 05:00:09 pm »
So my code looks like that

Class TempSensor
    // Function returns the temperature in degree celcius or
    // Float.NaN if something is wrong
    Shared Function GetTemp() As Float
        // Define the properties of the I2C peripheral and device address
        Dim sensor As I2c
        sensor = I2c.Create(400000, Pin.SCL, Pin.SDA, 0x48)
       
        // Power up the sensor and give it some time to settle
        Device.EnableTempSensor()
        Thread.Sleep(40000) // See page 13 of the datasheet
       
        // Read the sensor (only 2 bytes to read
        Dim res As ListOfByte = sensor.Read(2)
       
        // See Tmp102 documentation how to interpret the data (page 8)
        Dim temp As Float = Float.NaN
        If res <> Nothing Then
            // Shift the partial part to the right nibble
            Dim part As Float = res(1) >> 4
            // Temperature partial is 1/16*n where n is between 0 and 15           
            part = part / 16
            // Sign extend the byte to an integer
            temp = res(0).SignExtend() + part
        End If
       
        // power off
        Device.DisableTempSensor()
        Return temp
    End Function
   
    Shared Function GetDieTemp() As Float
        // Just get the temperature and return
        Return Device.TempDie
    End Function
   
    Shared Function ToFarenheit(celcius As Float) As Float
        Return (celcius * 9) / 5 + 32
    End Function
   
    Shared Function ToCelcius(farenheit As Float) As Float
        Return (farenheit - 32) * 5 / 9
    End Function
   
End Class

Class Temperature
    Shared Event GetTemp() RaiseEvent Every 1 Minutes
       
        Dim Temp As Float = TempSensor.GetTemp
        Dim tempstring As String = Temp.ToString()
       
        If Temp > 5 Then
            //Temperatur is more then -4
            Lplan.IFTTT("Your key", "NameofRecipe", tempstring, "", "")
        Else
            //Temperatur is not more then -4
        End If
       
    End Event
End Class


Is that right? Not sure I understand how to make the recipe in that case, and how to link it to this code. Also, how can the code be upload to the module? Rookie, and not teckie (well, a bit, but not a coder)

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Mobile interface
« Reply #12 on: June 24, 2016, 05:13:07 pm »
You do not have to copy the code from the TempSensor to "your" code, it's ok to have the TempSensor in a different Tab in mcStudio. Maybe that's what you have and you just did copy from the second tab to this post?
Both ways works but it's cleaner to use tabs.

You have to create a account on ifttt.com and connect to makers channel. Then you create a recipe. You replace "your key" with key from makers channel and "NameofRecipe" with the name you used for the recipe.

In the download page for mcThings there you will find some documentation about how to use mcStudio.
You will need to connect to your mcGateway from mcStudio and then you can connect to the mcModules that is connected to that mcGateway.
When that is done, now you could load the code on that device.

Did this make things a little clearer?

jeffmartin

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mobile interface
« Reply #13 on: June 29, 2016, 11:45:47 am »
I have a question regarding using the mcDongle inside a freezer. Will the RF signal reach through the metal walls? Will an external temp sensor with the mcDongle located outside the freezer be required? This would give you the option to use any xx2032 battery and you could monitor the temp difference between the inside of the freezer and the room the freezer is in.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Mobile interface
« Reply #14 on: June 29, 2016, 11:52:59 am »
Hello.
About the RF signal, I have to say that it depends on the freezer and where you have your mcRouter, I have used 433Mhz devices in my freezer with success before, I have not yet tested with mcModule.
But it's better for the battery if you could put the device on the outside and the sensor on the inside.

It seems that there are several people interested in monitoring the freezer and I see no reason why I not should start to use mcModule for this. I will try to find some time to run some tests on this subject.
Like Like x 1 View List