Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Nick_W

Pages: 1 2 3 [4] 5 6 ... 15
46
mc-Things General Discussion / Re: beacon_decode.py issue
« on: January 24, 2017, 01:41:15 pm »
The beacon_decode.py program actually rebroadcasts the decoded beacons via MQTT. The log is just so that you can see what is going on.

If you look at the command line options, one of them is --topic (-t) which is the MQTT topic that the decoded beacons are sent to. Default is MCThings/

So each beacon is received, decoded and published to MCThings/<beacond_id>/<item> where <beacon id> is the same as what was received, and <item> is what the value was decoded as (Temperature, BatteryVoltage, Humidity etc.).

You can change --topic to whatever you want on the command line. If you leave it as default and subscribe on your computer to MCThings/# you should see all your modules data being published (decoded from beacons). To publish to the cloud, add this to the command line:

Code: [Select]
beacon_decode.py -t cloud_topic_whatever/whatever/whatever/

Where cloud_topic_whatever is where you publish things to see them on your phone. You can specify other command line options for broker, port, user_id and password - this assumes that you are receiving and sending to the same broker. If they are different, the program would need to be modified to have two mqtt brokers, ports, users, passwords etc. Easy enough to do, but I was assuming you would just use the one broker.

Data then shows up on  cloud_topic_whatever/whatever/whatever/<beacond_id>/<item> as previously described.


The log is just so that you can see what is happening.

47
mc-Things General Discussion / Re: beacon_decode.py issue
« on: January 23, 2017, 08:46:10 pm »
This describes the behaviour of Python 3.5 http://stackoverflow.com/questions/35249879/python-struct-unpack-errors-with-typeerror-a-bytes-like-object-is-required-not

And gives the fix. I'll see if I can fix it, but it'll be hard to test without having Python 3.5 installed.

48
mc-Things General Discussion / Re: beacon_decode.py issue
« on: January 23, 2017, 08:37:41 pm »
Are you running Python 3? This is a Python 2.7 program.

Python 3 uses byte arrays in place of the Python 2.7 strings. Should be fairly easy to fix, but I don't think I have Python 3 installed anywhere.

I'll see what I can do.

49
mc-Module / Re: Add a max6675 to a MCmodule 110
« on: January 23, 2017, 05:17:24 am »
Not without a lot of messing around (which was why I asked about the high temperature requirement).

Easiest would be to power everything from 3.3 V (or thereabouts) the modules can go up to 3.6V max, so you could run everything from a standard 3.3V supply/battery set up.

I haven't tried an SPI interface on a module, but I have implemented one on a cortex M1 before, and it wasn't hard (they have all the support built in).

I also interfaced an external break-out board to a module via I2C and had no real difficulties - if the SPI interface is as easy, then that may be the way to go.

You would be breaking new ground though, so be sure to let us know how you get on!

51
mc-Module / New 120 Module/Demo 205 Accelerometer Library Released!
« on: January 22, 2017, 05:48:52 pm »
Check out my github https://github.com/NickWaterton/mcScript

For many new programs, including:
All New LIS2DH12 library (for the 120 module and Demo 205 accelerometer)
Example programs for the accelerometer
Updated DoorSensor program for module 120
Updated Python logging program (makes viewing the accelerometer 120 example programs easy).

The new accelerometer library (V1.5) is completely re-written, and fully tested. Programs using the old incomplete library may need updating, as some function names have changed.

All bugs have been fixed* (and there were many).
All features of the accelerometer (except FIFO) have been implemented with easy to configure functions. These include.

  • Motion Detection
  • Transient Detection
  • Orientation Detection 6D and 4D
  • FreeFall Detection
  • Single and a Double Click Detection (tap)

All interrupts, modes, ranges and pins implemented.
6D, 4D (landscape/portrate) and high pass filter configurations made simple.
Readout of x,y,z pitch and roll in 8,10 and 12 bit resolution.
Sleep mode, data rates from 1 Hz to 1.5kHz
Ultra low power modes (2uA).
Easy read out functions return strings (such as "up" and "down" or "portrate_up" for Orientation detection)

Super easy to configure and use!

Plus much more.

Check it out and let me know what you think.

*This may not be true.

52
mc-Module / Re: Add a max6675 to a MCmodule 110
« on: January 21, 2017, 07:52:18 pm »
You could, I'm not sure exactly why you would want to, unless you need some special feature of the digital interface.

You would have to implement an SPI interface, which is supported, but with no real examples published. Doable though.

An easier (and cheaper) alternative would be to connect an analog k type thermocouple amplifier. Like this one:

https://www.adafruit.com/product/1778

Then you just need an analog input pin, and the interface is easy.

What is the temperature range you are reading? Do you need high temperatures (in the 1000 degrees range)?

53
mc-Studio / SOLVED: Select Case not working with Byte variable
« on: January 21, 2017, 07:30:19 pm »
Well this was my stupid fault. Up too late working on this. The problem is obvious (it you look closely)

Code: [Select]
            Select orientation
                Case INT_SRC_YL
                    result = "left"
                Case INT_SRC_XH
                    result = "right"
                Case INT_SRC_XL
                    result = "top"
                Case INT_SRC_YH Then
                    result = "bottom"
                Case INT_SRC_ZH Then
                    result = "up"
                Case INT_SRC_ZL Then
                    result = "down"
            End Select

Can you see it? "Then" does not belong in a case statement. Look at the last three case statements, compared to the first three. Doh!

54
JSON / Duplicate keys
« on: January 21, 2017, 07:23:12 pm »
I'm just getting ready to release my new LIS2DH12 library (which actually works), and I'm writing some example programs.

One thing I ran into, was putting a line like this into the accelerometer ISR

Code: [Select]
JData.add("Orientation", Orientation)

Where jData is a json object, and Orientation is a string giving the Orientation "up" "down" etc. The json is published ever 10 seconds by a shared event.

The json object is a shared variable, and is cleared after it is published.

I thought that as the orientation was changed, the new orientation would overwrite the old, and when published you would have the orientation at the point it was published.

Instead, I get a run time error, saying that the publish string is too long. Looking at the culprit (jData) it has dozens of entries (I couldn't tell what the entries were, the Debugger shows (" for the content, but the Count() was 120 in one instance.

This seems to imply that duplicate pairs are allowed in a json object (and the standard does not disallow this).

Is this the case? Is this the intended operation of your implementation of the json object?

It's an easy fix (just clear before adding the new value), but I was wondering if this was intended or not, as most json implementations do not allow duplicate keys.

I also ran this through slowly, to see how duplicate keys deserialize to strings, and lo! No duplicate keys in the string. But the count says there is. Not sure exactly what is going on.

55
mc-Studio / Re: Select Case not working with Byte variable
« on: January 19, 2017, 08:37:34 pm »
I should have known that it works, I use exactly the same construct elsewhere in the same class and it works fine there.

The thing that is odd is that the variables are defined anyway. Still not sure what I was doing wrong.

I'll take another look tomorrow.

56
mc-Studio / Re: Select Case not working with Byte variable
« on: January 19, 2017, 11:10:51 am »
Weird, OK here is my actual code. You can't run it (which is why I made up the example) as it's reading from the accelerometer, and is part of a large class that is instantiated as a new object:

Code: [Select]
    Public Function GetINT1ActiveInterrupt() As Byte
        'bit 7 not used
        'IA Interrupt active. Default value: 0 bit 6
        '(0: no interrupt has been generated; 1: one or more interrupts have been generated)
        'ZH Z high. Default value: 0 bit 5
        '(0: no interrupt, 1: Z high event has occurred)
        'ZL Z low. Default value: 0 bit 4
        '(0: no interrupt; 1: Z low event has occurred)
        'YH Y high. Default value: 0 bit 3
        '(0: no interrupt, 1: Y high event has occurred)
        'YL Y low. Default value: 0 bit 2
        '(0: no interrupt, 1: Y low event has occurred)
        'XH X high. Default value: 0 bit 1
        '(0: no interrupt, 1: X high event has occurred)
        'XL X low. Default value: 0 bit 0
        '(0: no interrupt, 1: X low event has occurred)
        Return Read(INT1_SRC)
    End Function

    Public Function GetInt1Orientation() As String
        'special function to decode INT1_SOURCE in 6D/4D mode (only valid for that mode)
        Dim intSource As Byte = GetINT1ActiveInterrupt()
        Dim result As String
        Dim orientation As Byte = intSource & ~INT_ACTIVE
       
        '        If (intSource & INT_ACTIVE) = INT_ACTIVE Then
        '            If (intSource & INT_SRC_YL) = INT_SRC_YL Then
        '                result = "left"
        '            ElseIf (intSource & INT_SRC_XH) = INT_SRC_XH Then
        '                result = "right"
        '            ElseIf (intSource & INT_SRC_XL) = INT_SRC_XL Then
        '                result = "top"
        '            ElseIf (intSource & INT_SRC_YH) = INT_SRC_YH Then
        '                result = "bottom"
        '            ElseIf (intSource & INT_SRC_ZH) = INT_SRC_ZH Then
        '                result = "up"
        '            ElseIf (intSource & INT_SRC_ZL) = INT_SRC_ZL Then
        '                result = "down"
        '            End If
       
       
        If (intSource & INT_ACTIVE) = INT_ACTIVE Then
            Select orientation
                Case INT_SRC_YL
                    result = "left"
                Case INT_SRC_XH
                    result = "right"
                Case INT_SRC_XL
                    result = "top"
                Case INT_SRC_YH Then
                    result = "bottom"
                Case INT_SRC_ZH Then
                    result = "up"
                Case INT_SRC_ZL Then
                    result = "down"
            End Select
        End If
       
        Return result
    End Function // GetInt1Orientation

GetInt1Orientation() is the function that causes the error. The commented out code is my workaround, (which works).

Any clues?

PS I don't know if it helps, but here are the constants definitions:

Code: [Select]
    Const INT_ACTIVE As Byte = 0x40
    Const INT_SRC_ZH As Byte = 0x20
    Const INT_SRC_ZL As Byte = 0x10
    Const INT_SRC_YH As Byte = 0x08
    Const INT_SRC_YL As Byte = 0x04
    Const INT_SRC_XH As Byte = 0x02
    Const INT_SRC_XL As Byte = 0x01

57
mc-Studio / SOLVED: Select Case not working with Byte variable
« on: January 18, 2017, 09:56:42 pm »
Just found a new bug (feature).

The following give a build error "object not set to an instance...", you know, the usual one.

Code: [Select]
Dim var1 as Byte = something()
Dim text as string
Select var1
  Case 0x01
    Text="1"
  Case 0x02
    Text="2"
End select 

Works OK with variable (expression I guess) as string, haven't tested it with other data types, but Byte does not work.

58
mc-Studio / Re: Crashing during debugging
« on: January 17, 2017, 09:32:18 pm »
Thanks John,

What about the class names for Functions/Subs?

ie Public Functions/Subs don't need the class name if they are in the same class, but Shared Functions/Subs do
Variables (Public or Shared) don't need the class names when used within the same class.

The inconsistency seems to be Shared Functions/Subs needing the class name when used within the same class This is not how VB.NET does it, and seems the biggest inconsistency.

Thanks for taking the time to look into this.

59
mc-Studio / Re: Crashing during debugging
« on: January 17, 2017, 05:59:31 pm »
I understand that, that's not what I am saying.

In the IDE it is not internally consistent, with itself or VB.NET.

lets take your example:

Code: [Select]
Class Start
    Shared Event Boot()
        Dim X as Boolean
        Dim t as test = New test
        x = t.Fun1() ' would result true
        x = Test.Fun2() 'would result false
        x = Test.Fun3() 'result unpredictable...
    End Event
End Class

Class Test
    Public Var1 as Boolean = True
    Public Function Fun1() as Boolean
        Return Var1
    End Function
    Shared Function Fun2() as Boolean
        Return False
    End Function
    Shared Function Fun3() as Boolean
        Return Fun1() 'Should give error. Var 1 undefined
    End Function
    Shared Function Fun4() as Boolean
        Return Var1 'Not allowed because Var1 is not instanciated
    End Function
End Class

Now write it like this:
Code: [Select]
Class Start
    Shared Event Boot()
        Dim t as New Test
        t.Fun1()     'should turn on Green LED (does not compile, you have to change Fun4() to Fun5() to compile). Note Fun1() does not use class name for Fun4()
        t.Fun1a()    'turns on Green LED. Note Fun1a() does not use class name for Fun4a()
        Test.Fun2()  'should turn on Green LED,(does not compile) "Unshared Sub/Function" which it is
        Test.Fun3()  'should turn on Green LED (does not compile, you have to change Fun4() to Fun5() to compile). Note Fun3() must use the class name for Fun4() even though it is in the same class (inconsistent with Fun1a())
        Test.Fun4()  'should turn on the Green LED. (does not compile) "Cannot refer to an instance method of a class from within a shared method without an explicit instance of the class" LedGreen is a PinName
        Test.Fun5()  'should turn on the LED and does work, inconsistent with the above
        Lplan.Publish("topic", Test.Fun6())  'should publish "test" to topic, does not compile, "Unshared Sub/Function", which it is.
    End Event
   
    Private Function NotUsedAnywhereFun()
        Dim test as Float 'Local Variable, should be OK, but will not compile unless this variable definition is removed, or Class Test is renamed.
        test = 5.1*2.0    'error "The left hand side of the expression is not a variable or indexer"
        return test.Floor 'error "Floor is not a shared member"
    End Function
End Class

Class Test
    Public Sub Fun1()
        Fun4()
    End Sub
    Public Sub Fun1a()
        Fun4a()
    End Sub
    Shared Sub Fun2()
        Fun4()
    End Sub
    Shared Sub Fun3()
        Test.Fun4()
    End Sub
    Shared Sub Fun4()
        LedGreen = True
    End Sub
    Public Sub Fun4a()
        LedGreen = True
    End Sub
    Shared Function Fun5() as Nothing
        LedGreen = True
    End Function
    Shared Function Fun6() As ListOfByte
        Dim X as New ListOfByte
        X.add("Test")
        Return X
    End Function
End Class

Now do you see what I mean about the number of inconsistencies?

60
mc-Studio / Re: Crashing during debugging
« on: January 17, 2017, 03:43:32 pm »
OK, in process of conversion.

There is still some weirdness going on though:

This works (although you say it shouldn't):
Code: [Select]
    Public Sub LedGreenFlash1()
        LedGreen = True
        Thread.Sleep(3000)
        LedGreen = False
    End Sub

This does not work (even though you say it should):
Code: [Select]
    Shared Sub LedGreenFlash()
        LedGreen = True
        Thread.Sleep(3000)
        LedGreen = False
    End Sub
Gives error "Cannot refer to an instance method of a class from within a shared method without an explicit instance of the class". LedGreen is the issue, and given that this is a PinName, the error makes no sense.

This however does work:
Code: [Select]
    Shared Function LedGreenFlash() As Nothing
        LedGreen = True
        Thread.Sleep(3000)
        LedGreen = False
    End Function
No idea what the difference is, I assume a bug?

This applies to all pins like ReedSwitch, LedRed etc. You can use them within a Shared Event, Shared Function, Public Sub etc. but not from a Shared Sub.

Also a bit of a pain, I can't get the value of a shared function directly. eg, if I want the value of GetTimeStamp() I used to have a function:

Code: [Select]
Public Function GetTimestamp()
    return Timing.GetTimestamp()
End Function

and I would just use GetTimestamp() in the Main class. eg:

Code: [Select]
jData.Add("time", GetTimestamp())

because:
Code: [Select]
jData.Add("time", Timing.GetTimestamp())
doesn't work (error "unshared sub/function"). When clearly it is a shared function - if you hover the mouse over "Timing" it even lists the function as shared.

So now I have to do this:
Code: [Select]
Dim timestamp As String = Timing.GetTimestamp()
jData.Add("time", timestamp)
for every variable that I want that is shared in another class. Which is messy, and a pain. Why can't I get the values directly?

I would also like to point out that in the documentation, you exclusively use public sub/functions. No shared sub/functions at all, so one might be led to believe that this was acceptable.

For example, page 57 of the mcScript user guide gives this example:

Code: [Select]
01 Define PinMode Pin8 As AnalogInput

13 Public Function GetVoltage() As Short
14     Dim value As Short
15     value = Pin8 // Read the pin. This activates the ADC
16     Return value // Return value in millivolt
17 End Function

But does not mention that you shouldn't do this in the main program. In fact I think that it implies that you can.

And of course it does in fact work as is.

Another thing that doesn't add up, if I use a Public Function, I don't have to specify the Class name to use it within the same class (the compiler assumes I mean the same class - which is reasonable). If however I make it a shared Function, I do have to use the class name - even within the same class. This makes no sense, and is not consistent either internally, or with normal VB.NET behavior (which does not require the class name for public or shared functions within the same class, only external to the class). Shared or Public variables also do not need the class name within the same class.

Another thing I ran into recently, If one class has a variable called "Time", I can't create a class called "Time" even though the variable is internal to the first class.

Here the Class mma8652 has this function:
Code: [Select]
    'Returns list of length 2: maxTime, timeStep (both in ms)
    Private Function GetMaxTimeAndTimeStep(stepSize As String) As ListOfFloat
        Dim frequency As Byte = Read(CTRL_REG1_REG) & CTRL_REG1_DR
        Dim mode As Byte = Read(CTRL_REG2_REG) & CTRL_REG2_MODS
        Dim ms As Float
        Dim time As Float
        Dim offset As Integer
        Dim msTable As ListOfFloat = New ListOfFloat
        Dim result As ListOfFloat = New ListOfFloat
Notice the "Dim time" line

Now if I try to create a class Time

I get this error:
Code: [Select]
Time = ms * 255
       
result.Add(Time.Floor)
"The left hand side of the expression is not a variable or indexer"
""Floor" is not a shared member"

Highlighting the above two lines in the Private Function GetMaxTimeAndTimeStep(), which the IDE obviously believes to be something to do with the new class Time (which it isn't).

I guess my point is that I don't want to spend a lot of time refactoring all my code to eliminate one logical inconsistency, when the replacement itself is logically inconsistent, and there are so many inconsistencies, who knows what the final fixes will be?

So maybe it's best to leave it as is, and when you release breaking changes, hopefully you will let us know what those changes are.

Pages: 1 2 3 [4] 5 6 ... 15