2

I've found parts of a smart contract and I have an idea how to add things but I'm currently stuck. Maybe you can help me with that. The contract looks as following:

pragma solidity 0.4.15; 

contract monitoring {

uint8 public temperature;
address sensor;
address led;

event Instruction (address device, string instruction);

function monitoring (address _sensor, address LED ){
    sensor = _sensor;
    led = LED;
}

function updateTemp(uint temp){
    if(msg.sender != sensor) throw;
    temperature = temp;
    if (temperature > 90) {
        instruction(led, "ON");
    {
    else instruction(led, "OFF");
}
}

What I want to improve is, that after the event occurs (temperature raises above 90), a file with information about the event (like temperature, time of the day) gets written to some file and than the file gets hashed (with md5 or so) and the hash is written to a blockchain transaction.

Is that actually possible to do? If so, can you please give me an advice how to start? Thanks a lot in advance! :)

0

How about just adding a new event (or replacing the current event)?

If you emit an event like HighTemp(int32 millicelsius, uint64 timestamp, address sensor) then it will be easily accessible to listening devices, and significantly cheaper in gas.

0

You cannot write the file using solidity language. Using event your client side get notify which is written in javascript using web3js library after that you can pass this information to server side using ajax and write the file on server.

Solidity Event => Client Notify(Web3) => Handle the callback in Cliebt(web3) => Pass data to server(Let's Node js) => Write data in file

I didn't test that but it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.