{"id":341,"date":"2021-02-25T20:00:04","date_gmt":"2021-02-25T11:00:04","guid":{"rendered":"https:\/\/sakae-shokai.com\/?p=341"},"modified":"2021-02-25T20:00:05","modified_gmt":"2021-02-25T11:00:05","slug":"esp32%e3%81%8b%e3%82%89mariadb%e3%81%ab%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e3%81%a8%e3%81%b0%e3%81%99","status":"publish","type":"post","link":"https:\/\/sakae-shokai.com\/wordpress\/?p=341","title":{"rendered":"ESP32\u304b\u3089MariaDB\u306b\u30c7\u30fc\u30bf\u3092\u3068\u3070\u3059"},"content":{"rendered":"\n<p>\u30bb\u30f3\u30b5\u304b\u3089\u306e\u30c7\u30fc\u30bf\u3082\u3068\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u3001Wi-Fi\u306b\u3064\u306a\u304c\u308a\u3001\uff2e\uff34\uff30\u3067\u6642\u8a08\u306e\u88dc\u6b63\u3082\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>IoT\u3092\u9032\u3081\u308b\u4e2d\u3067\u5fc5\u8981\u306a\u306e\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u3072\u305f\u3059\u3089\u30c7\u30fc\u30bf\u3092\u653e\u308a\u8fbc\u307f\u3001\u305d\u306e\u4e2d\u3067\u3001\u7570\u5e38\u306e\u3042\u308b\u30c7\u30fc\u30bf\u3092\u3044\u304b\u306b\u65e9\u304f\u898b\u3064\u3051\u51fa\u3059\u304b\u304c\u91cd\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u305f\u3081\u3001\u4eca\u56de\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306bMariaDB\u3092\u7528\u3044\u3001ESP32\u304b\u3089\u30c7\u30fc\u30bf\u3092PHP\u306bPOST\u3057\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u53d6\u308a\u8fbc\u3080\u4e00\u9023\u306e\u6d41\u308c\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002MariaDB\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u305d\u306e\u4ed6\u306f\u7701\u7565\u3057\u307e\u3057\u3066\u3001\u65e2\u306besp_data\u3068\u3044\u3046\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u3066\u3042\u308b\u3068\u3053\u308d\u304b\u3089\u59cb\u3081\u307e\u3059\u3002phpMyAdmin\u3092\u4f7f\u7528\u3057\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e2d\u306bSensorData\u3068\u3044\u3046\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002\u6b21\u306eSQL\u6587\u3092phpMyAdmin\u306eSQL\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3057\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002\u4eca\u56de\u30c6\u30b9\u30c8\u306e\u90fd\u5408\u3067MACadd\u5217\u306f\u7701\u7565\u3057\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE SensorData (\n    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n\/\/    MACadd VARCHAR(30) NOT NULL,\n    value1 VARCHAR(10),\n    value2 VARCHAR(10),\n    value3 VARCHAR(10),\n    reading_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n)<\/code><\/pre>\n\n\n\n<p>\u30c6\u30fc\u30d6\u30eb\u304c\u51fa\u6765\u4e0a\u304c\u3063\u305f\u3089\u3001\u9069\u5f53\u306b\u30c7\u30fc\u30bf\u3092\u5165\u308c\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO `SensorData`(`value1`, `value2`, `value3`) VALUES (12.3,23.4,35.3)<\/code><\/pre>\n\n\n\n<p>\u5b9f\u884c\u3092\u62bc\u3059\u3068SQL\u6587\u304c\u5b9f\u884c\u3055\u308c\u3001\u884c\u304c\u633f\u5165\u3055\u308c\u307e\u3059\u3002\u3053\u3053\u307e\u3067\u78ba\u8a8d\u3057\u305f\u3089\u3001\u6b21\u306fMicroPython\u4e0a\u3067json\u3092\u7528\u3044\u305fPOST\u6587\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" title=\"posttest.py\" >import ujson\nimport urequests\n \n\ndict = {\n        \"data_value\":\"12.4\",\n        \"temp_value\":\"23.4\",\n        \"humi_value\":\"35.2\"\n        }\nresponse = urequests.post(\n        'http:\/\/**url**\/postrcv.php',\n        data=ujson.dumps(dict).encode(\"utf-8\"),\n        headers={'Content-Type': 'application\/json'}\n        )\nprint  (response.text)<\/pre><\/div>\n\n\n\n<p>MicroPython\u3067\u306fpython\u3067\u4f7f\u7528\u3059\u308bjson\u3068requests\u306e\u982d\u306bu\u3092\u3064\u3051\u308b\u5f62\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u5f62\u3067post\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306b\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u308bphp\u5074\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:php decode:true \" title=\"postrcv.php\" >&lt;?php\n\n$in = json_decode(stripslashes(file_get_contents('php:\/\/input')),true);\n$data_value = $in[\"data_value\"];\n$temp_value = $in[\"temp_value\"]; \n$humi_value = $in[\"humi_value\"];\n\n$servername = \"localhost\";\n$dbname = \"esp_data\";\n$username = \"username\";\n$password = \"password\";\n\n$conn = new mysqli($servername, $username, $password, $dbname);\nif ($conn-&gt;connect_error) {\n     die(\"Connection failed: \" . $conn-&gt;connect_error);\n} \n\n$sql=\"INSERT INTO `SensorData`(`value1`, `value2`, `value3`) VALUES ($data_value,$temp_value,$humi_value)\";\nif ($conn-&gt;query($sql) === TRUE) {\n    echo \"New record created successfully\";\n} \nelse {\n    echo \"Error: \" . $sql . \"&lt;br&gt;\" . $conn-&gt;error;\n}\n    \n$conn-&gt;close();\n\n?&gt;<\/pre><\/div>\n\n\n\n<p>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089ampy\u3092\u7528\u3044\u3066\u4e0a\u8a18MicroPython\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8d70\u3089\u305b\u305f\u7d50\u679c\u304c\u6b21\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\Users\\>ampy -p com4 run c:\\micropython\\posttest.py\nNew record created successfully<\/code><\/pre>\n\n\n\n<p>phpMyAdmin\u3067\u78ba\u8a8d\u3057\u3066\u3082\u65b0\u3057\u3044\u30ec\u30b3\u30fc\u30c9\u304c\u633f\u5165\u3055\u308c\u3066\u3044\u307e\u3059\u3002<a href=\"http:\/\/160.16.91.174\/phpmyadmin\/sql.php\"><\/a><\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p><a href=\"http:\/\/160.16.91.174\/phpmyadmin\/tbl_change.php\">&nbsp;\u7de8\u96c6<\/a><a href=\"http:\/\/160.16.91.174\/phpmyadmin\/tbl_change.php\">&nbsp;\u30b3\u30d4\u30fc<\/a><a href=\"http:\/\/160.16.91.174\/phpmyadmin\/sql.php\"><img decoding=\"async\" src=\"http:\/\/160.16.91.174\/phpmyadmin\/themes\/dot.gif\" alt=\"\u524a\u9664\">&nbsp;\u524a\u9664<\/a>1712.323.435.32021-02-25 19:35:51<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u30bb\u30f3\u30b5\u304b\u3089\u306e\u30c7\u30fc\u30bf\u3082\u3068\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u3001Wi-Fi\u306b\u3064\u306a\u304c\u308a\u3001\uff2e\uff34\uff30\u3067\u6642\u8a08\u306e\u88dc\u6b63\u3082\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 IoT\u3092\u9032\u3081\u308b\u4e2d\u3067\u5fc5\u8981\u306a\u306e\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u3072\u305f\u3059\u3089\u30c7\u30fc\u30bf\u3092\u653e\u308a\u8fbc\u307f\u3001\u305d\u306e\u4e2d\u3067\u3001\u7570\u5e38\u306e\u3042\u308b\u30c7\u30fc\u30bf\u3092\u3044\u304b\u306b\u65e9\u304f\u898b\u3064\u3051\u51fa &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sakae-shokai.com\/wordpress\/?p=341\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;ESP32\u304b\u3089MariaDB\u306b\u30c7\u30fc\u30bf\u3092\u3068\u3070\u3059&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":234,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,39,16],"tags":[18,40,19],"class_list":["post-341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-mariadb","category-micropython","tag-esp32","tag-mariadb","tag-micropython"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=341"}],"version-history":[{"count":3,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":345,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/341\/revisions\/345"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/234"}],"wp:attachment":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}