Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@
* SPI SCK SCK D5 13 / ICSP-3 52 D13 ICSP-3 15
*/

#include <Arduino.h>
#include <SPI.h>
#include <MFRC522.h>
#include <ESP8266WiFi.h>

#define ESP8266 1
#include <ESP8266HTTPClient.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager

#ifndef STASSID
#define STASSID "HUAWEI-B535-07AA"
#define STAPSK "rozar97431"
#endif

#define SERVER_IP "192.168.8.100:3000"
// #define SERVER_IP "192.168.8.100:3000"
// #define SERVER_IP "192.168.30.136:3000"
#define SERVER_IP "192.168.43.172:3000"

// #define RST_PIN 9 // Configurable, see typical pin layout above
// #define SS_PIN 10 // Configurable, see typical pin layout above
Expand All @@ -58,49 +57,61 @@

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

const char *ssid = STASSID;
const char *password = STAPSK;
// const char *ssid = STASSID;
// const char *password = STAPSK;

// byte newUid[4] = {0x71, 0x85, 0x13, 0x09};

bool initialisation = true;

void setup()
{
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial)
; // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
delay(5000);
delay(2000);
Serial.println("Begin setup");
// Serial.println("D3");
// Serial.println(D3);
// Serial.println("D4");
// Serial.println(D4);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)
// WiFiManager, Local intialization. Once its business is done,
// there is no need to keep it around
WiFiManager wm;

// Configure a static IP address for the ESP card in Access Point mode
// wm.setAPStaticIPConfig(ip, gateway, subnet);
wm.setAPStaticIPConfig(IPAddress(192, 168, 5, 1),
IPAddress(192, 168, 5, 1),
IPAddress(255, 255, 255, 0));

//reset settings - wipe credentials for testing
wm.resetSettings();

// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result

bool res = wm.autoConnect("AutoConnectAP"); // anonymous ap

if (!res)
{
delay(500);
Serial.print(".");
Serial.println("Failed to connect");
// ESP.restart();
}
else
{
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

Serial.println("End setup");
}
Expand All @@ -109,27 +120,21 @@ String getUID(MFRC522::Uid *uid)
{
String res = "";

// Serial.print(F("Card UID:"));
for (byte i = 0; i < uid->size; i++)
{
// if (uid->uidByte[i] < 0x10)
// {
// // Serial.print(F(" 0"));
// res += F(" 0");
// }
// else
// {
// // Serial.print(F(" "));
// res += F(" ");
// }
// Serial.print(uid->uidByte[i], HEX);
res += String(uid->uidByte[i], HEX);
}
return res;
}

void loop()
{
if (initialisation)
{
Serial.println("IP address: " + WiFi.localIP().toString());
initialisation = !initialisation;
}

// Serial.println("Begin loop");
// delay(1000);
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
Expand All @@ -145,20 +150,26 @@ void loop()
}

// wait for WiFi connection
if ((WiFi.status() == WL_CONNECTED))
if (WiFi.status() == WL_CONNECTED)
{

WiFiClient client;
HTTPClient http;

Serial.print("[HTTP] begin...\n");
// configure traged server and url
http.begin(client, "http://" SERVER_IP "/postplain/"); //HTTP
String serverEndPoint = "http://" SERVER_IP "/postplain/";
Serial.print("[HTTP] serverEndPoint: " + serverEndPoint + "\n");
http.setReuse(true);
http.begin(client, serverEndPoint);
http.addHeader("Content-Type", "application/json");

Serial.print("[HTTP] BEFORE POST\n");
// start connection and send HTTP header and body
int httpCode = http.POST("{\"uid\":" + getUID(&(mfrc522.uid)) + "}");
String message = "{\"uid\":" + getUID(&(mfrc522.uid)) + "}";
Serial.print("[HTTP] message: " + message + "\n");
int httpCode = http.POST(message);
String payload = http.getString();
Serial.print("[HTTP] payload: " + payload + "\n");

// httpCode will be negative on error
if (httpCode > 0)
Expand All @@ -168,7 +179,8 @@ void loop()
}
else
{
Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
Serial.printf("[POST FAILED] httpCode: %d\n", httpCode);
Serial.printf("[POST FAILED] error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
Expand Down
5 changes: 5 additions & 0 deletions arduino/olimex_128x64_koch_snowflake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
39 changes: 39 additions & 0 deletions arduino/olimex_128x64_koch_snowflake/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions arduino/olimex_128x64_koch_snowflake/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
18 changes: 18 additions & 0 deletions arduino/olimex_128x64_koch_snowflake/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 115200
lib_deps =
adafruit/Adafruit SSD1306@^2.4.4
tectiv3/Adafruit-SSD1331@0.0.0-alpha+sha.488737cb7a
Loading