Avatar for user84292

user84292

Member since Dec 2017 • Last active Jan 2018
  • 4 conversations
  • 14 comments

Most recent activity

    • 17 comments
    • 7,231 views
  • in Pico / Wifi / Original Espruino
    Avatar for user84292

    Wondering if anyone has had a chance to follow up on this?

    Thanks

  • in Pico / Wifi / Original Espruino
    Avatar for user84292

    Yes, tried with a number of cards and both sockets. Cards were formatted Fat32 on a Linux machine with parted. They could be read by a Windows machine as well.

  • in Pico / Wifi / Original Espruino
    Avatar for user84292

    Geez, I move between C++, Python, Java, Scala . . . .

    All those have the parentheses. Habit!

  • in Pico / Wifi / Original Espruino
    Avatar for user84292

    Sure, here you go. The Web output is like a REST/JSON response that gives a sliding window of readings:

    {
    "current" : 41.4,
    "log" : [
    	{ "1514836500" : 47.9 },
    	{ "1514836800" : 41.4 },
    	{ "1514837100" : 39.5 },
    	{ "1514837400" : 39.3 },
    	{ "1514837700" : 39.1 },
    	{ "1514838000" : 39.1 },
    	{ "1514838300" : 38.9 },
        . . . .
    	{ "1515066900" : 41.4 },
    	{ "1515067200" : 41.4 },
    	{ "1515067500" : 41.4 }
    ]
    }
    

    I also send the readings to Graphite so I have a historical view (attached).

    // Wifi setup
    var WIFI_NAME = "myssid";
    var WIFI_OPTIONS = { password : "mypassword" };
    var wifi;
    
    // Where we are in the array.  Once full we'll shift and add to the end
    var arr_ptr = 0;
    
    // Max samples.  
    //    672 is 30 days of 15m samples
    //    4320 is 30 days of 5m samples
    var maxSamples = 4320;
    
    // How often to take a sample in seconds
    var sampleSec = 300;
    
    // Our sample arrays
    var ts_arr = Uint32Array(maxSamples);
    var temp_arr = Float32Array(maxSamples);
    
    // Array elements filled
    var arr_elements = 0;
    
    // Initial temperature setting
    var tempF = 32;
    
    // One wire object
    var ow = new OneWire(B0);
    
    // HTTP object
    var http = require("http");
    
    // Sensor object
    var sensor = require("DS18B20").connect(ow);
    
    // Fahrenheit?
    var fahr = true;
    
    // Graphite server
    graphite_host = "192.168.0.48";
    graphite_port = 2003;
    
    
    // Connect to WIfi
    function onInit() {
      wifi = require("EspruinoWiFi");
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
        if (err) {
          console.log("Connection error: "+err);
          return;
        }
        console.log("Connected!");
        setTimeout(initProcess, 1000);
      });
    }
    
    // Get the temperature
    function updateTempF() {
      sensor.getTemp(function (sensor_temp) {
        tempF = ((sensor_temp * 9) / 5) + 32;
      });
    }
    
    
    // Initialization
    function initProcess() {
      // Get a page so we can get the current date from the header
      http.get("http://www.pur3.co.uk/hello.tx­t", function(res) {
        // Set our time bsaed on the header date
        now = res.headers.Date;
        epoch = Date.parse(now);
        setTime(epoch/1000);
        date = new Date();
        console.log("Init: ", date.toUTCString());
    
        // Set logging and the server to start after a few seconds
        updateTempF();
        setTimeout(startLogging, 3000);
        setTimeout(startServer, 5000);
      });
    }
    
    
    // Start our Web server
    function startServer() {
      console.log("Starting server");
      http.createServer(function (req, res) {
        updateTempF();
        res.writeHead(200, {'Content-Type': 'application/json'});
        if (arr_elements === 0) {
          res.end("{\n\"current\" : " + tempF.toFixed(1) + ",\n\"log\" : []\n}");
          return();
        }
        var i = 0; 
        res.on('drain', function() {
          for (var n = 0; n < 10; n++) {
            sample = "\n\t{ \"" + ts_arr[i] + "\" : " + temp_arr[i].toFixed(1)+ " }";
            res.write(sample);
            if (++i == arr_elements) {
              res.end("\n]\n}");
              break;
            }
            else {
              res.write(",");
            }
          }
        });
    
        page = "{\n\"current\" : " + tempF.toFixed(1) + ",\n\"log\" : [";
        res.write(page);
      }).listen(80);
    }
    
    
    // Start logging the temperature
    function startLogging() {
      console.log("Starting logging");
      setInterval(function() {
        sensor.getTemp(function (sensor_temp) {
          now = Date.now() / 1000;
          floor = parseInt(now);
          if (fahr)
            tempF = ((sensor_temp * 9) / 5) + 32;
          else
            tempf = sensor_temp;
          mod = floor % sampleSec;
          if (!mod) {
            if (arr_ptr == maxSamples) 
              arr_ptr = 0;
            ts_arr[arr_ptr] = parseInt(floor);
            temp_arr[arr_ptr++] = tempF;
            if (++arr_elements > maxSamples)
              arr_elements = maxSamples;
          }
          // Also send to Graphite
          socket = require("net").connect({"host" : graphite_host, "port" : graphite_port}, function() {
            msg = "espruino-attic-oaktreepeak-com.temperat­ure " + tempF + " " +  now + "\n";
            socket.write(msg);
            socket.end();
          });
        });
      }, 1000);
    }
    
    
  • in Pico / Wifi / Original Espruino
    Avatar for user84292

    I actually did exactly as you suggest, cutting and pasting from the code above. I'm really at a loss as to how to debug, as I've had no issues getting these adapters to work with Arduinos, Rasp PIs, etc.

    • 7 comments
    • 3,022 views
    • 6 comments
    • 3,288 views
  • in Pico / Wifi / Original Espruino
    Avatar for user84292

    Hi folks,

    I had wired up an SD card socket from Sparkfun:

    https://www.mouser.com/ProductDetail/Spa­rkFun-Electronics/DEV-13743/?qs=WyAARYrb­Sna7AKzdOk0X8g%3D%3D&gclid=Cj0KCQiAsqLSB­RCmARIsAL4Pa9TQXhYrFu8L0QQcDVMAQE91NwG4R­Am4irzcp8LHGGQq_icz7bBiY6saAuxPEALw_wcB

    But I keep getting the message, even with multiple different SD cards, all formatted to Fat32.

    "Uncaught Error: Unable to mount media : NOT_READY
        at line 6 col 41
         console.log(require("fs").readdirSync())­;"
    

    I triple-checked all the connections, and then used a meter to check connectivity, power, shorts, etc. They were all correct.

    So I figured it must be the socket. I removed it and soldered this one on in it's place, figuring that perhaps the added voltage regulation circuit might help:

    https://www.adafruit.com/product/254?gcl­id=Cj0KCQiAsqLSBRCmARIsAL4Pa9SFqtMV7P6ij­T3YC_O2wkmDjScGyUWDSlxgrcYFvsitDs03yyHVn­2oaApQ7EALw_wcB

    But I still get the exact same error message. Am I missing something obvious here? Again, I checked all the connections and they're fine. I have a DS18B20 connected to different pins and it works great, so the Espruino appears to be fine. Test program for SD card looks like this:

    
    function onInit() {
      console.log("Connected!");
      // Wire up up MOSI, MISO, SCK and CS pins (along with 3.3v and GND)
      SPI1.setup({mosi:B5, miso:B4, sck:B3});
      E.connectSDCard(SPI1, B6 /*CS*/);
      // see what's on the device
      console.log(require("fs").readdirSync())­;  
      for (var i in files)
        console.log("Found file "+files[i]);
    
      var f = E.openFile("log.txt", "w");
      f.write("Testing 123");
      f.close();
      
      f = E.openFile("log.txt", "r");
      f.pipe(console.log);
      f.close();
    }
    
    
Actions