Avatar for user70647

user70647

Member since Nov 2016 • Last active Jan 2017
  • 0 conversations
  • 3 comments

Most recent activity

  • in ESP8266
    Avatar for user70647

    Hello All,
    I am New to Espruino and electronics. I Need help for one on my small project of I2C communication between atmega8 an esp8266, I just want to send I2C data from esp8266(master) and read at atmega8(slave[slaveid=1]) and same send data from atmega8(slave) to esp8266(master). any one have any idea? how I can do this....
    please help me....

    I try as following but still not work, is any one help me to know what I am doing wrong here :
    esp8266 code :

    var I = new I2C();
    console.log(I);
    var J = I.setup({scl:0, sda:2});
    console.log(J);
      setInterval(function(){
         console.log("I:::",I.readFrom(1,5));
      },1000);
    

    Atmega8 code :

    [#include](https://forum.espruino.com/se­arch/?q=%23include) <Arduino.h>
    [#include](https://forum.espruino.com/se­arch/?q=%23include) <Wire.h>
    void requestEvent();
    void setup() {	
    	Wire.begin(1);                // join i2c bus with address #1
    	pinMode(4,OUTPUT);
    	digitalWrite(4,HIGH);
    	pinMode(3,OUTPUT);
    	digitalWrite(3,HIGH);
    }
    void loop() {
    	delay(100);
    }
    
    // function that executes whenever data is requested by master
    // this function is registered as an event, see setup()
    void requestEvent() {
    	digitalWrite(3,LOW);
    	Wire.write("hello "); // respond with message of 6 bytes
    	// as expected by master
    }
    
  • in ESP8266
    Avatar for user70647

    Thanks @Gordon, my issue is solved. i just turn off NPM (Beta) from settings.

  • in ESP8266
    Avatar for user70647

    My code is :

    var ws = require('ws');
    var Wifi = require("Wifi");
    Wifi.connect("123", {password: "456"}, function (ap) {
        console.log("connected:", ap);
    });
    Wifi.on('connected', function (details) {
        var x = new Date();
        console.log("Connected......", x.toString());
        Wifi.getAPDetails(function (detail) {
            console.log("AP Details : ", detail);
        });
        Wifi.getAPIP(function (detail) {
            console.log("APIP Details : ", detail);
        });
        Wifi.getDetails(function (detail) {
            console.log("Details : ", detail);
        });
        Wifi.getDHCPHostname(function (detail) {
            console.log("DHCP HostnameDetails : ", detail);
        });
        Wifi.getHostname(function (detail) {
            console.log("Hostname Name : ", detail);
        });
        Wifi.getIP(function (detail) {
            console.log("IP : ", detail);
            //server();
            socketServer();
        });
        Wifi.getStatus(function (detail) {
            console.log("Status : ", detail);
        });
    });
    /*Wifi.on('probe_recv', function(details) {
     console.log("probe Details : ",details);
     });*/
    Wifi.scan(function (detail) {
        console.log("scan Detail : ", detail);
    });
    Wifi.setHostname("123-esp");
    Wifi.on('sta_joined', function (details) {
        console.log("sta_joined : ", details);
    });
    Wifi.on('sta_left', function (details) {
        console.log("sta_left : ", details);
    });
    Wifi.startAP('123-esp', {authMode: 'wpa2', password: '456', channel: 13}, function (a, b, c, d) {
        console.log("startAP::", a, b, c, d);
    });
    /*Wifi.stopAP(function(a,b,c,d){
     console.log("stopAP ::",a,b,c,d);
     });*/
    Wifi.save();
    function server() {
        var page = "<html>\n<head><meta name=\"viewport\" content=\"width=device-width,initial-sca­le=1\"></head>\n<body style=\"width:100%;height:100%;overflow:­hidden;\">\n<svg style=\"width:100%;height:100%;\"\n   viewbox=\"0 0 500 500\" id=\"svg\">\n    <path\n       style=\"fill:#80e5ff;fill-opacity:1;fill­-rule:nonzero;stroke:none\"\n       d=\"M 250 0 C 111.92882 3.7895613e-14 0 111.92882 0 250 C -1.249508e-14 341.05067 48.689713 420.72528 121.4375 464.4375 L 154.625 409.40625 C 100.50052 376.95218 64.28125 317.69934 64.28125 250 C 64.28125 147.43284 147.43284 64.28125 250 64.28125 C 352.56716 64.28125 435.71875 147.43284 435.71875 250 C 435.71875 317.53896 399.66155 376.65256 345.75 409.15625 L 378.71875 464.34375 C 451.37991 420.61135 500 340.98541 500 250 C 500 111.92882 388.07118 -1.8947806e-14 250 0 z \" id=\"ring\"/>\n    <rect\n       style=\"fill:#ffffff;fill-opacity:1;fill­-rule:nonzero;stroke:none\"\n       id=\"needle\"\n       width=\"16\"\n       height=\"80\"\n       x=\"242\"/>\n    <text\n       xml:space=\"preserve\"\n       style=\"font-size:122.59261322px;font-st­yle:normal;font-variant:normal;font-weig­ht:normal;font-stretch:normal;text-align­:center;line-height:125%;letter-spacing:­0px;word-spacing:0px;text-anchor:middle;­fill:#000000;fill-opacity:1;stroke:none;­font-family:Helvetica;-inkscape-font-spe­cification:Helvetica\"\n       x=\"250.01915\"\n       y=\"845.31812\"\n       id=\"text\"><tspan\n         id=\"label\"\n         x=\"250.01915\"\n         y=\"292.95594\">0</tspan></text>\n    <path\n       style=\"fill:#d5f6ff;fill-opacity:1;fill­-rule:nonzero;stroke:none\"\n       id=\"up\"\n       d=\"m 294.75099,133.39225 -90.93056,0 45.46528,-78.748173 z\"\n       transform=\"matrix(0.61903879,0,0,0.6190­3879,95.682477,91.16682)\"\n       />\n    <path\n       transform=\"matrix(0.61903879,0,0,-0.619­03879,95.682477,408.80767)\"\n       d=\"m 294.75099,133.39225 -90.93056,0 45.46528,-78.748173 z\"\n       id=\"dn\"\n       style=\"fill:#d5f6ff;fill-opacity:1;fill­-rule:nonzero;stroke:none\" />\n</svg>\n\n<script>\n// Convert touch to mouse event for mobile devices\nfunction touchHandler(event) {\n  var touches = event.changedTouches,\n       first = touches[0], type = \"\";\n  switch(event.type) {\n    case \"touchstart\": type=\"mousedown\"; break;\n    case \"touchmove\":  type=\"mousemove\"; break;        \n    case \"touchend\":   type=\"mouseup\"; break;\n    default: return;\n  }\n  var simulatedEvent = document.createEvent(\"MouseEvent\");\n  simulatedEvent.initMouseEvent(type, true, true, window, 1, \n                            first.screenX, first.screenY, \n                            first.clientX, first.clientY, false, \n                            false, false, false, 0/*left*/, null);\n  first.target.dispatchEvent(simulatedEven­t);\n  event.preventDefault();\n}\ndocument.add­EventListener(\"touchstart\", touchHandler, true);\ndocument.addEventListener(\"touc­hmove\", touchHandler, true);\ndocument.addEventListener(\"touc­hend\", touchHandler, true);\ndocument.addEventListener(\"touc­hcancel\", touchHandler, true); \n\n// rotate needle to correct position\nvar pos = 50;\nfunction setPos(p) {\n  if (p<0) p=0;\n  if (p>100) p=100;\n  pos = p;\n  document.getElementById(\"label\").textC­ontent = pos;    \n  var a = (pos-50)*2.8;\n  document.getElementById(\"needle\").setA­ttribute(\"transform\",\"rotate(\"+a+\" 250 250)\");    \n}\nsetPos(pos);\n\n// handle events\nvar dragging = false;\nfunction dragStart() {\n  dragging = true;\n  document.getElementById(\"ring\").style.­fill = \"#ff0000\";\n}\ndocument.addEventListen­er(\"mousemove\", function(e) {\n  if (dragging) {\n    e.preventDefault();\n    var svg = document.getElementById(\"svg\");\n    var ang = Math.atan2(e.clientX-(svg.clientWidth/2)­,(svg.clientHeight/2)-e.clientY)*180/Mat­h.PI;\n    setPos(Math.round((ang/2.8)+50));\n  }\n});\ndocument.addEventListener(\"mous­eup\", function(e) {\n  dragging = false;\n  document.getElementById(\"ring\").style.­fill = \"#80e5ff\";\n  document.getElementById(\"up\").style.fi­ll = \"#d5f6ff\";\n  document.getElementById(\"dn\").style.fi­ll = \"#d5f6ff\";\n  // POST data to Espruino\n  var req=new XMLHttpRequest();\n  req.open(\"POST\",\"?pos=\"+pos, true);\n  req.send();\n});\ndocument.getElementByI­d(\"ring\").onmousedown = dragStart;\ndocument.getElementById(\"ne­edle\").onmousedown = dragStart;\ndocument.getElementById(\"up­\").onmousedown = function(e) { e.preventDefault(); this.style.fill = \"#ff0000\"; };\ndocument.getElementById(\"dn\").onmo­usedown = function(e) { e.preventDefault(); this.style.fill = \"#00ff00\"; };\ndocument.getElementById(\"up\").onmo­useup = function(e) { setPos(pos+10); };\ndocument.getElementById(\"dn\").onmo­useup = function(e) { setPos(pos-10); };\n</script>\n</body>\n</html>";
        function pageHandler(req, res) {
            if (req.method == "POST") {
    // If it's a POST, save the data
                var info = url.parse(req.url, true);
                console.log("POST ", info);
                if (info.query && "pos" in info.query)
                    res.writeHead(200);
                res.end("Ok.");
            } else {
    // otherwise write the page out
                console.log("GET " + req.url);
                if (req.url == "/") {
                    res.writeHead(200);
                    res.end(page);
                } else {
                    res.writeHead(404);
                    res.end("404: Not found");
                }
            }
        }
        require("http").createServer(pageHandler­).listen(80);
    }
    
    function socketServer() {
        var page = '<html><body><script>var ws;setTimeout(function(){';
        page += 'ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");';
        page += 'ws.onmessage = function (event) { console.log("MSG:"+event.data); };';
        page += 'setTimeout(function() { ws.send("Hello to Espruino!"); }, 1000);';
        page += '},1000);</script></body></html>';
    
        function onPageRequest(req, res) {
            res.writeHead(200, {'Content-Type': 'text/html'});
            res.end(page);
        }
    
        var server = ws.createServer(onPageRequest);
        server.listen(8000);
        server.on("websocket", function (ws) {
            ws.on('message', function (msg) {
                print("[WS] " + JSON.stringify(msg));
            });
            ws.send("Hello from Espruino!");
        });
    }
    

    i getting error :
    NPM: Checking NPM at http://registry.npmjs.org/Wifi
    NPM: Checking NPM at http://registry.npmjs.org/http
    loadModule(ws.min)
    ERROR: Not Found
    NPM: Latest version 0.0.0
    NPM: URL https://registry.npmjs.org/http/-/http-0­.0.0.tgz
    [object Object]
    loadModule(http)

    • ws.min requires ["crypto","net","http"]
      Queueing crypto
      NPM: Checking NPM at http://registry.npmjs.org/crypto
      Queueing net
      NPM: Checking NPM at http://registry.npmjs.org/net
      Already loading http
      ERROR: Not Found
      NPM: Latest version 0.0.3
      NPM: couldn't find latest tarball
      [object Object]
      loadModule(crypto)
      NPM: Latest version 1.0.2
      NPM: couldn't find latest tarball
      [object Object]
      ERROR: Not Found
      loadModule(net)
      ERROR: Not Found
      WARNING: [notify_warn] Module http not found
      ERROR: Not Found
      ERROR: Not Found
      ERROR: Not Found
      WARNING: [notify_warn] Module crypto not found
      ERROR: Not Found
      WARNING: [notify_warn] Module net not found


    please help me for this

Actions