Avatar for redfox


Member since Jul 2020 • Last active Aug 2020
  • 2 conversations

Most recent activity

  • in Interfacing
    Avatar for redfox

    Installed Espruino Hub on a Raspberry Pi W, got it all working, and node-red works.
    But how do you get the web bluetooth code working on there to connect to the Puck.js through the Pi, as im currently getting odd errors.

    I copy pasted the code at https://www.espruino.com/Smart+Meter at the bottom of the page, and put that in a file called meter.html in the hub's www dir.

    The page loads, but when you click the box, it says Web Bluetooth is not supported in this browser.

    I'm guessing there's some extra work to tell it to use the Pi's MQTT bridge to the Puck, rather than connecting to the Puck directly, but still the error is odd, as it should support web bluetooth, as im still using the same Chrome that worked when I tried to connect to it directly from the example page.

  • in Interfacing
    Avatar for redfox

    Oh yeah, I didnt want a big number per se. It was more that it was a number that seemed right, but obviously was not.

    And your suggestion of a var, that sounds much much simpler. I'll give that a go.
    From the reading I did, its either context, flow, or global variables. In this case, im thinking a flow one, as it only needs to work within the given flow.

  • in Interfacing
    Avatar for redfox

    Once this works, would be cool to work with you perhaps to have a Part 2 to your guide based on what I do, to deal with 'The Other Side' of the bluetooth transmission of the energy data. Unless you dont want the examples to be too 'complete' as it might not encourage people to think for themselves.

  • in Interfacing
    Avatar for redfox

    Ahh, ok yes thats what I meant. ok I'll have to take a second look at that. I must have done something wrong, as using 16 got me no or weird results (cant remember) and 32 got me a big number. Checking again now, 32 gets me 69702, and 16 gets me 9254. So now its giving me a value. I'll go with 16 then, as you know more about it than me, who knows what typo I made before.

    ok, I 'think' I follow what you're saying there for the storage. If thats the case, then yes maybe I do want to follow the same logic in the firebase data structure.

    I was starting along the lines of this: https://jsfiddle.net/redfox05/7Lpmvbkz/2­7/

    var min = d.getMinutes();
    switch ( true ) {
        case min <= 15: console.log('segment1', min); break;
        case min <= 30: console.log('segment2', min); break;
        case min <= 45: console.log('segment3', min); break;
        default: console.log('segment4', min);

    Trying to break each hour into 4 segments of 15 minutes, as perhaps doing it per minute would not be accurate enough / lead to errors given its tighter points.
    From what I understand, each pulse flash is 1000th of a kWh, so 1000 counts in 1 kWh.

    So ideally, I would like to get to a point where we know how many kWh or fraction thereof are used for every 15 min block.
    The datastore needs to be able to be queried per 15, per hour, per day, month etc, so I'll keep thinking on that one.

    Be really cool if I could expand this to then do prediction stuff. Im pretty sure Google/AWS has some clever tools for this.

  • in Interfacing
    Avatar for redfox

    Thanks Gordon. Slight tweak needed, as in your smart meter tutorial, you set it as a Uint32, so changing the 16 to 32 gave me a number that certainly looks like what I need (But its the total overall count I think, not for the day, so a little more work needed).

    Would it be possible for you to explain, maybe in pseudo code or high level story, what you do in your example code from https://www.espruino.com/Smart+Meter?

    I'm trying to figure out what it does at each step, so that I can find the best way to build historical data from it.

    Looking at the Historical data part with the Counter, I was trying to see what you are doing with the years, months, days etc, but it does not make sense to me. Im totally new to storing data in byte format, so thats probably why it looks alien to me.

    I get that I can just strip out all the code, and in fact just use the basic example code at the start of your tutorial, and just reset it every day, but I would like to understand how and why you took your approach.

    I'm thinking btw that in node-red I would need to track the current minute and last value, and then when the value changes, note the time that happened, and then subtract the counter value from the last time it changed, to get the amount of counts for a given minute. And then store that in Firebase to build up a per minute usage. Or maybe thats overkill and it needs to be every 10 minutes. Does that sound logical to you? Again, totally new to IoT, and im a web developer, so thats where my thought process only comes from.

  • in Interfacing
    Avatar for redfox

    Hi all,

    Im following https://www.espruino.com/Smart+Meter

    How do you access data in an ArrayBuffer that is sent over a BLE advert to node-red.

    And my end-goal is to get data from my Electricity Meter, to the Puck.js to Raspberry pi, to Firebase DB.

    So far:
    I've got the data to the puck.
    I've got the data to the raspberry pi via the bluetooth advertising and node-red/EspruinoHub.

    Now im trying to figure out the advertising data, how to read it, and then once I have that, I can focus on the connection to Firebase.

    My current issue is that the data over MQTT is coming out as the current count from the Puck.js, seems all ok, but then it changes from a number (00000001) to something else (000004f9) which looks binary or bytes or something else.

    I need help figuring out how the ArrayBuffer plays with the DataView and everything else.
    I kind of get that you dont access data directly in the ArrayBuffer, you use the DataView for read and write, but in this case, its writing to it, and then it goes across the Bluetooth highway, into node-red as the unreadable string, and then.... well thats where im stuck.

    How do I make sense of:

    7/27/2020, 6:23:10 PMnode: 85a205c2.26d3f8
    /ble/advertise/mac:address/manufacturer/­0590 : msg.payload : string[10]

    And get it into something like Firebase (I'm thinking RealTime db seems best, normal db would go crazy if it was updated every 600ms / out of free credits). Im not tied to Firebase, just seemed like a good option.

  • in News
    Avatar for redfox

    Any chance you want to run this challenge again? I'm currently looking at a number of projects, including expanding on your puck.js energy meter, to tie it in with a raspberry pi, espruino hub, and then either local webserver to manage this and then expose to the internet, or send to AWS to go and do some even more fun stuff with their API's.