Thursday, May 28, 2020

Messing around with Socket Servers on ESP32

https://shawnhymel.com/1675/arduino-websocket-server-using-an-esp32/

See the link above. I gave this a shot, but my computer immediately disconnects once I connect to the socket server. I need to somehow keep the socket open.

I am going to try his more advanced websocket server (link below) and see if I run into the same issue. Maybe I can backtrack the problem, or maybe I can ask a friend.

https://shawnhymel.com/1882/how-to-create-a-web-server-with-websockets-using-an-esp32-in-arduino/

Compare the result to using an HTTP server.

https://www.youtube.com/watch?v=3FNs-t-fbzU


Supposedly a Socket Server is better because I can keep the connection open. But how do I keep it open?


Edit (May 31st, 2020):

The second Shawn Hymel link mentions WiFi.SoftAP . The only mention in the Ardunio library that I found was:

https://github.com/arduino-libraries/WiFi/blob/425e5a45745e0985345dc5e9d86062dee3e2a153/extras/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/wl_api.h#L1311

SoftAP is https://en.wikipedia.org/wiki/SoftAP . This requires a password, which is a problem according to Wikipedia. Maybe not if you go the verifiable credentials / DID route. Libraries? Ockam?

Edit (May 31st, 2020):

I tried the second project "1882" and recorded the results:

https://youtu.be/Gqzvq05QUKw
Now I do not know how to pull data from the Sockets Server. I know how to push data to it using the button. However, I notice that if I place a toggle switch in the circuit with the LED and break the connection the webserver code does not read any change in state from the sockets server. I need code that continuously listens to what is happening on the server side (i.e. whether there is a connection).

I suspect that a chat server is a good analogue.
https://www.youtube.com/watch?v=rxzOqP9YwmM

The code is here:
https://github.com/WebDevSimplified/Realtime-Simple-Chat-App

[review node modules for node project setup:
https://docs.npmjs.com/creating-node-js-modules]

Once I know how a chat server works, then maybe I will be able to apply it to an LED.

A sensor turns "on" and "off" when it receives new data.

[ note. the websocket server is on a different network than the wifi network. (uses softAP) this is a problem for my laptop (at least under the current configuration) . Perhaps I can connect to both networks in my network card supports it??
https://askubuntu.com/questions/488588/how-do-i-connect-to-multiple-wifi-networks] ... nvm...I can get the websocket server and the rest of the system to run on the same network

Edit:: I found a configuration that works. I can turn on an off an LED from a webpage.

Interesting document
https://tttapa.github.io/ESP8266/Chap01%20-%20ESP8266.html

It has websockets!
https://tttapa.github.io/ESP8266/Chap14%20-%20WebSocket.html

But how do I get it to forward my sensor data?? Try this::
https://esp8266-shop.com/blog/websocket-connection-between-esp8266-and-node-js-server/
or https://techtutorialsx.com/2018/09/11/esp32-arduino-web-server-sending-data-to-javascript-client-via-websocket/

In the future see:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html

and:

https://www.youtube.com/watch?v=EvUI4vRhF88 (MQTT Over Websockets Explained for Beginners )

https://www.youtube.com/watch?v=2aHV2Fn0I60 (An Introduction to MQTT for Beginners) [one version uses TCP another uses UDP]

Espressif also provides a websocket client:
https://github.com/espressif/esp-idf/tree/7d75213674b4572f90c68162ad6fe9b16dae65ad/components/esp_websocket_client

Monday, May 25, 2020

IPFS, Leger, React Links

https://itnext.io/build-a-simple-ethereum-interplanetary-file-system-ipfs-react-js-dapp-23ff4914ce4e

https://www.bigchaindb.com/

IoT and Sampling Rate

I can access an IoT unit by a local IP address through http, but I must refresh the browser to see any changes. The same thing with curl (duh, http://IP is not a loop). What does it mean to fetch data whenever there is a change on the IoT unit? Do I have to set a sampling rate by sending out HTTP requests? I think there is an internal sampling rate on the IoT unit between the sensor and the Ardunio-compatible ESP32 based device that acts as a webserver.

silly rant. need more coffee.


Try :::


https://shawnhymel.com/1675/arduino-websocket-server-using-an-esp32/

The Actor Model looks a lot like mm-ADT?

"The Actor is the fundamental unit of computation. As the fundamental unit of computation it has to embody 3 things.
It has to embody:
(1) Processing (because you have to get something done)
(2) Storage (because you have got to be able to remember and store things)
(3) Communication
So an actor is the fundamental unit, the primitive unit that embodies all
three essential units of computation." - Carl
https://www.brianstorti.com/the-actor-model/


Compare to:


https://www.slideshare.net/slidarko/mmadt-a-multimodel-abstract-data-type/55




I shared this with Marko, and he said that:
"The actor model is a style of distributed computing similar to message-passing computing."


For data processing, I am looking at:
https://www.baeldung.com/rx-java

http://reactivex.io/RxJava/javadoc/overview-summary.html

https://en.wikipedia.org/wiki/Thread_pool




Friday, May 22, 2020

Why I am a terrible programmer (theory)

I have been reflecting why I read advanced stuff, and think about advanced and rebellious stuff for years on end, yet have huge holes in my knowledge that most would have already mastered in much less time.

You're going to work for a company. They are going to tell you want to do. In their glossy brochures and flashy websites they say the projects are cool and benefit society.
If you are lucky, you might get to do some of the things you want to do (your dreams, your creativity), maybe if you are at it long enough. Maybe the companies will be generous and help you further your education.

I grew up in a world where this mindset was the case. Substitute company with school or group led by an authority figure. Maybe I viewed things through family.

I also struggled with math and felt silly when I asked for help. I thought some people were just smarter and more skilled. It did not always click right away. I was inspired by great people since an early age.

Which is kind of why I am still weak here, and why I have not seen these websites much?

https://www.geeksforgeeks.org/top-10-algorithms-in-interview-questions/
https://www.freecodecamp.org/learn/ 
(see coding interview prep)

 I suppose this shouldn't be out in the wild:

This is interesting, and I am having fun learning it, but do the people that I know that work at the companies know about it or at least value it? Do they value my view point, or do they ignore me because I don't have the same number of years in their existing peer group with the same sort of title? This is why it is important to have some degree of F.U. money because constantly being concerned about what other people think is a drain. Working a $7-$12/hr job is exhausting, but totally worth it if it gets you practice and exposure working with stuff that gets you up in the morning. Buying into, "oh you have an advanced degree, recruiters will throw your resume out if they see that" is foolish. The truth is, you might get into the interview but they will throw you out because they said "he rambled on and on about this" or "he did not seem too passionate" or "he said something at the end of the interview that indicated he really was faking it the whole time". Majors are important because it puts you in a group and allows those who are hiring to assemble you like lego blocks without really thinking what is inside. They are just trusting that you were vetted by the university. If you get pushed into a certain major and are not allowed to make course corrections based on understanding of yourself then you are in trouble. Having F.U. money helps with making course corrections for problems you see, but others refuse to see. If you don't make these course corrections, or don't have or refuse to spend lots of money at universities and colleges then you can get responses like, "I see all of these hobbies, and or lots of activities on your c.v., but no real experience".


Oh, this is so cool, but does it involve .NET, C#, MySQL, JavaScript, or React?
(or Java, Python...) I should be the best I can be at these 5 things and then apply for 500 job postings. I should present on these popular things because people are using them, and it might get me a job. I actually feel guilty for pursuing things other people don't. I go through contortions trying to explain. I don't blame them really. They all are focusing on the same sorts of things under the illusion that it will allow them to survive. I'm more motivated by ideas and excellent projects, less by job boards. Things usually end in: I wish I would have bought Ethereum or Ripple or Bitcoin. I knew about them all, early. Bitcoin in Jan 2012, then all of the others at inception. I wish I wouldn't have asked people if I should, or asked people who gave me responses that gave me fear. It is too volatile. It has no value b/c Warren Buffet says so. etc...

I wish I would have spent more money on conferences that fit in line with projects I was pursuing, and less on conferences that were curiosities that were just fun because people I found that were easy to commute to every month were doing it.You fall behind and you get abandoned twice: first by the people who were evolving and discovering new things (and have a few years under their belt pursing it) and second by the people you just hung with who have a few years more experience doing whatever they do but never really had the time to care or never saw value or never wanted to understand what you do. All of this abandonment and disconnection does not make you seem more valuable.

In addition to that you still might have more rough edges than you might otherwise have. People who go on with there lives and just acquire more stuff but you never really see except if you go to specific events and never really care what you do in general are not going to help you smooth out these rough edges.

I recall that during the summer of 2013 I worked as an adjunct professor teaching a chemistry lab at a community college. I could have theoretically taken a computer science class. I did move in that direction and approached a professor in the network security teaching profession. I recall that I felt that the professor wanted me to do an entire curriculum, and I was scared away. I perhaps had sticker shock. I perhaps had hubris of oh, I'll figure it out and it is cool that I think I can. It makes me better smarter than those blindly going through the system...etc. i very much enjoyed spending time with the elites on the w3c forums. I also was unwilling to part with money that I was making. (instead I squandered some of it by living for a stint in california. Before I went the thought passed: what would people at church think. I thought about telling them, but I guess I didn't value their opinion because felt that my aspirations with a distributed economy were improper or they wanted me to chose a more normal career and be like everyone else. I was in california, but I couldn't stop studying. I did some odd jobs. I was not all that committed to tutoring.) Maybe I too was wounded from my university experience.

Part of the reason why the university was difficult is that I had trouble making course corrections for my interests or weaknesses. I didn't fund it and I did not have a lot of confidence going in. I should have worked during high school, but that was discouraged. I guess I should have approached standardized testing with more vigor than I did.


Rock solid co-creation is what moves things forward. Inspiration moves things forward.
https://twitter.com/twarko/status/1269522827205640192?s=20
https://twitter.com/twarko/status/1269522827205640192?s=20
https://twitter.com/twarko/status/1269522827205640192?s=20
https://twitter.com/twarko/status/1269522827205640192?s=20

grab the data with the script

Step 1:

Plug in the Heltec Wifi 32 into the computer

Step 2:

Open the serial monitor in the Arduino IDE. Record the ip adress.
e.g. 10.0.0.7

Step 3:

Enter "http://" prefixing the ip address in the browser.

e.g. "http://10.0.0.7" .




Step 4:

"hello from esp8266!" should be displayed in the browser window.

Step 5:

Turn on the LoRa transmitter board (heltec cubecell) and refresh the browser.

"hello from esp8266!Hello world number9 lumens: -1610612736"


Step 6:

look for a PHP script that does an HTTP GET

grab the data with the script:
(find different ways to do this)
/var/www/html/testcode/get_data$get_data_short.php

"
<?php

$url = "http://10.0.0.7";

$opts = array('http' =>
    array(
        'method' => 'GET',
        'max_redirects' => '0',
        'ignore_errors' => '1'
    )
);

$context = stream_context_create($opts);
$stream = fopen($url, 'r', false, $context);

// header information as well as meta data
// about the stream
//var_dump(stream_get_meta_data($stream));

// actual data at $url
$str = var_dump(stream_get_contents($stream));
fclose($stream);

echo "hai monkey boy";
// parse the string the get lumens

// Recommended
parse_str($str, $output);
var_dump($output);
//echo $output['first'];  // value
//echo $output['arr'][0]; // foo bar
//echo $output['arr'][1]; // baz


?>
"

or see also:

~/Downloads/php-tests5_new$test4_reactphp_httpclient.ph

"
<?php

require "vendor/autoload.php";

use React\HttpClient\Client;

$loop = React\EventLoop\Factory::create();
$client = new React\HttpClient\Client($loop);

$request = $client->request('GET', 'http://10.0.0.12');
$request->on('response', function ($response) {
        $response->on('data', function ($chunk) {
        echo "start of string";
        echo "\r\n";
        echo $chunk;
        echo "\r\n";
        echo "end of new string";
        echo "\r\n";
    });
    $response->on('end', function() {
            echo 'DONE';
            echo "\r\n";
    });
});
$request->on('error', function (\Exception $e) {
    echo $e;
});
$request->end();
$loop->run()

?>
"

Step 7:

Parse string from get request . (followed in code in step 6)

Step 8:

insert the reading into the database table.

/var/www/html/testcode/previous_attempts$connect3f3.php

"
<?php
$mysqli = new mysqli("localhost", "user", "password", "database_name");


/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$dt = date("Y-m-d H:i:s");
$id = 7;

// I need to create a value for ID that prints the next value
$query = "INSERT INTO BH1750 VALUES (NULL, 23,"."'$dt'".")";
$mysqli->query($query);

/* close connection */
$mysqli->close();
?>
"



Tuesday, May 19, 2020

thought about IoT.

Internet of things isn't so much about things. It is about data.

Friday, May 1, 2020

Musings of May 1st

Monoids are to functional programming as design patterns are to object oriented programming??

Need to check out:
https://blog.ploeh.dk/2017/10/04/from-design-patterns-to-category-theory/