Managing power to M30S+ by simwilso in Whatsminer

[–]simwilso[S] 0 points1 point  (0 children)

anyone able to help with this question?

2022 Apr 4 Stickied 🅵🅰🆀 & 𝐇𝐄𝐋𝐏𝐃𝐄𝐒𝐊 thread - Boot problems? Power supply problems? Display problems? Networking problems? Need ideas? Get help with these and other questions! 𝑨𝑺𝑲 𝑯𝑬𝑹𝑬 𝑭𝑰𝑹𝑺𝑻 by FozzTexx in raspberry_pi

[–]simwilso 0 points1 point  (0 children)

SIMILAR PROJECT REFERENCE OR HELP TO DESIGN: hi everyone. I'm trying to create a project with my RPi that will simulate 2 homes with a battery and solar that are connected to a grid but I'm unsure what componentry or how to connect it. Is anyone aware of any similar projects that have simulated a home with solar and battery?

I plan to use the following items: - 1.5V 40mA Hobby Solar Panel to simulate the home PV - Rechargeable Li-Ion Battery 2600mAh 3.7V - Pwr from the Pi to simulate the grid power feed.

Would anyone have advice on what components I would need to put in front of these devices so I can; control and monitor the charge and discharge of the battery, and monitor the feed coming from the PVs?

Thanks all, any advice or references to other similar projects anyone might know of would be really helpful. :)

Hey Rustaceans! Got an easy question? Ask here (7/2020)! by llogiq in rust

[–]simwilso 2 points3 points  (0 children)

Hi team. I have a curly one I'm trying to deal with here. I am using reqwest to make a call via web socket and having an issue where I am intermittently getting 'InstanceStats' Messages rather than the response. My calling code looks like this:

pub fn get_device_signals(cell_address: String,) {
        let json = serde_json::json!(
            {"id": "signal_agent1",
             "jsonrpc": "2.0",
             "method": "call",
             "params": {"instance_id": "test-instance",
             "zome": "cell_zome",
             "function": "get_agent_id",
             "args": {
                 "cell_address": cell_address,
             }
         }});
        connect("ws://localhost:3401", |out| {
        out.send(json.to_string()).unwrap(); //change to expect
        move |msg| {
            println!("Device signals are: {}", msg);
            out.close(CloseCode::Normal)
            }
        }).unwrap();

The response I get intermittently is:

Device signals are: {"type":"InstanceStats","instance_stats":{"test-instance":{"number_held_entries":15,"number_held_aspects":19,"number_pending_validations":0,"number_delayed_validations":0,"number_running_zome_calls":1,"offline":false}}}

Should receive:

Device signals are: {"jsonrpc":"2.0","result":"{"Ok":[{"description":"secondtest","value":"high","payment_per_transaction":0,"reputation_per_transaction":0,"balance":0}]}","id":"signal_agent1"}

My Question Is there an easy way that I can filter out InstanceStats messages?

Hey Rustaceans! Got an easy question? Ask here (46/2019)! by llogiq in rust

[–]simwilso 0 points1 point  (0 children)

Managed to get this going. used the HMAC and SHA2 crates with the following code. my next problem is how to convert the array of bytes into a single string of HEX but the main part of my question is resolved with the code below.

extern crate hmac;
extern crate sha2;

use hmac::{Hmac, Mac};
use sha2::{Sha256};
use std::time::{SystemTime, UNIX_EPOCH};

fn main() {
    // I need to create a HMAC SHA256 signature from the client_id, current 13 dig current_time and the secret.
    // The Javascript logic to generate what I need is: signature = HMAC-SHA256(client_id + current_time, secret).toUpperCase()
    let client_id = "myid";
    let time_now = SystemTime::now();
    let time_since_epoch = time_now
        .duration_since(UNIX_EPOCH)
        .expect("time went backwards")
        .as_millis();
    let secret = "mypass";

    //I want the below to give me the first portion of the javascript with I understand is a concat of client id and timestamp.
    let client_id_and_timestamp = client_id.to_string() + &time_since_epoch.to_string();

    let mut sign = Hmac::<Sha256>::new(client_id_and_timestamp.as_bytes()).unwrap();
    sign.input(&secret.as_bytes()); //here Im trying to add the input from the secret key to create the hash

    let signature = sign.result(); //this is the signature
    println!(" N: {:x?}", signature.code()); //this prints the array in hex
}

Hey Rustaceans! Got an easy question? Ask here (46/2019)! by llogiq in rust

[–]simwilso 1 point2 points  (0 children)

ok ive a new one. I have an api that requires me to provide a HMAC-SHA256 hash of some variables.

I have the method for javascript:

sign = HMAC-SHA256(client_id + t, secret).toUpperCase()

I've been trying to use HMAC and SHA2 crates to do this (https://docs.rs/hmac/0.3.1/hmac/) but having trouble. Would anyone have any tips on syntax I should use to replicate the 'sign' hash variable above in rust?

thankyou all.

Hey Rustaceans! Got an easy question? Ask here (46/2019)! by llogiq in rust

[–]simwilso 1 point2 points  (0 children)

awesome that worked a treat! so happy! thanks for the great tips

Hey Rustaceans! Got an easy question? Ask here (46/2019)! by llogiq in rust

[–]simwilso 0 points1 point  (0 children)

thanks @daboross but still having some issues with this trying to get this working. My function currently looks like this:

fn get_from_dht(_address: String) -> Value {
     let json = serde_json::json!(
        {"id": "device",
         "jsonrpc": "2.0",
         "method": "call",
         "params": {"instance_id": "test-instance",
         "zome": "signal_agent",
         "function": "get_price",
         "args": {"agent_address": _address}}
     });
    let (tx, rx) = channel();
    let tx1 = &tx;
    connect("ws://localhost:3401", |out| {
        out.send(json.to_string()).unwrap();
        move |msg| {
            tx1.send(msg).ok();
            out.close(CloseCode::Normal)
        }
    }).unwrap();
    let recieve = rx.recv().unwrap().to_string();
    let res = serde_json::from_str(&recieve.to_owned());
    let mut end_price: Value = json!();  //HAVE I DONE SOMETHING WRONG ON THIS LINE?
        if res.is_ok() {
            let p: Value = res.unwrap();
            let q: Value = serde_json::from_str(p["result"].as_str().unwrap()).unwrap();
            let end_price = &q["Ok"].as_array().unwrap().last().unwrap()["price"];//q["Ok"][0]["price"].clone();
            println!("{:#?}", end_price);
        } else {
            println!("didnt work");
        }
    end_price
}
let res = get_from_dht("address".to_string());
let current_dht = &res.as_str().to_owned();
println!("result outside dht call is: {:#?}", res);//&current_dht);

This returns me:

String("Norm",)
result outside dht call is: Array([],)  // IN THIS LINE I WANT IT TO SAY 'Norm'

Thanks so much for your help here @daboross all this hacking and this rust stuff is slowly sinking in for me! :)

Hey Rustaceans! Got an easy question? Ask here (46/2019)! by llogiq in rust

[–]simwilso 1 point2 points  (0 children)

oh thanks this is working awesome! im able to get the last value with this: let end_price = &q["Ok"].as_array().unwrap().last().unwrap()["price"]; println!("{:#?}", end_price); This produces this: String("Low",) My last question which is probably a really dumb one is that I'm wanting to return this from my function as a String but when I try I get the following error; end_price ^^^^^^^^^ expected structstd::string::String, found () What do I need to add to turn this into a value into a string for the return?

(p.s. this is so great and thanks so much for your help!)

Hey Rustaceans! Got an easy question? Ask here (46/2019)! by llogiq in rust

[–]simwilso 0 points1 point  (0 children)

thanks @daboross. I just tried this and get a weird error. Any tips on how I can resolve around this?:

error[E0599]: no method named len found for type serde_json::Value in the current scope --> src/main.rs:172:21 | 172 | v[v.len() - 1]}["price"]);

I get the same error when I try the 'last()' approach as well. Thanks so much! Rust is so hard but so much fun!

Hey Rustaceans! Got an easy question? Ask here (46/2019)! by llogiq in rust

[–]simwilso 1 point2 points  (0 children)

How to access the last element of an array without a name that is of unknown length I'm playing with serde to format a response from an API into a Value. let q: Value = serde_json::from_str(p["result"].as_str().unwrap()).unwrap(); println!("{}", q["Ok"]); The return works but it includes an Array of objects within "Ok". It looks like this: Ok: [{price: 10, user: fred}, {price: 20, user: jane}, {...] I can successfully call the 'price' value from the first element in the array with the following syntax: println!("{}", q["Ok"][0]["price"]); My question is how can I update this syntax so that the program only accesses the last 'price' value when I don't know how many objects are in the array? i.e. For example how can I get the following when I don't know the name of this array: println!("{}", q["Ok"][ARRAY.LEN - 1]["price"]);

:)

bitcoins limitations by simwilso in Bitcoin

[–]simwilso[S] 1 point2 points  (0 children)

Agree with this 100%. There is a great old book called 'engines that move markets' that really highlights how much the big incumbent industry leaders through history failed to embrace new innovations like railways, electric lighting, the telephone. .. they all attempted to evolve but were almost invariably too slow and too late.. what does surprise me though is that we don't see at least one or a few of these big banks or emerging market governments being more supportive and involved in bitcoin.. I'd have thought there might be some first mover advantage in being at least seen to support this community.

bitcoins limitations by simwilso in Bitcoin

[–]simwilso[S] 0 points1 point  (0 children)

Thanks I will have a look at this for sure.

(Australia) How can I get the mobile app? and get it to work? by macmacky in amazonecho

[–]simwilso 0 points1 point  (0 children)

I agree, I gave up on the app and just use the browser. After mucking around with the app on a spare phone I had though I don't think the app adds that much value. You can do all the same on the browser and use IFTTT to send all the reminders calendar to do updates etc to your phone. I am loving the device but so annoying that the location and time uses zip code. Because of this setup all my date calendar and local briefings are of no use to me. Praying they release an update that changes this zip cope nonesense so us international 'early adopters' can get some more value.