matthew Champion
Published © GPL3+

Warehouse management pick to light device

A WIFI connected Wemos d1 mini battery powered pick to light device using ws2812b R.G.B addressable lights. JSON is used as the protocol

IntermediateFull instructions provided4 hours392
Warehouse management pick to light device

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
or wemos D1 mini pro
×1
DC to DC buck converter generic
×1
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
18650 battery cell
×2
ws2812b adressable lights
×1
Rocker Switch, Non Illuminated
Rocker Switch, Non Illuminated
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic.

Code

testjson.php

PHP
example to send json post to the arduino from your computer. oho must be installed on your computer.
#!/usr/bin/php
<?php

$arg1 = $argv[1];
$arg2 = $argv[2];
$arg3 = $argv[3];
$arg4 = $argv[4];
$arg5 = $argv[5];
$arg6 = $argv[6];
$arg7 = $argv[7];
$arg8 = $argv[8];
$arg9 = $argv[9];
$arg10 = $argv[10];
$arg11 = $argv[11];
$arg12 = $argv[12];
$arg13 = $argv[13];
$arg14 = $argv[14];
$arg15 = $argv[15];
$arg16 = $argv[16];
$arg17 = $argv[17];
$arg18 = $argv[18];
$arg19 = $argv[19];
$arg20 = $argv[20];


$myObj = array(

array("light" => "$arg1",
"Red" =>"$arg2",
"Green" =>"$arg3",
"Blue" =>"$arg4",
"duration" =>"$arg5"
),
array("light" => "$arg6",
"Red" =>"$arg7",
"Green" =>"$arg8",
"Blue" =>"$arg9",
"duration" =>"$arg10"
),
array("light" => "$arg11",
"Red" =>"$arg12",
"Green" =>"$arg13",
"Blue" =>"$arg14",
"duration" =>"$arg15"
),   
array("light" => "$arg16",
"Red" =>"$arg17",
"Green" =>"$arg18",
"Blue" =>"$arg19",
"duration" =>"$arg20"
),

);

$myJSON = json_encode($myObj);

 // A sample PHP Script to POST data using cURL

  $data = $myJSON ;
  $post_data = $data;

  // Prepare new cURL resource
  $crl = curl_init('192.168.1.206/postform/');

  curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($crl, CURLINFO_HEADER_OUT, true);
  curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($crl, CURLOPT_POST, true);
  curl_setopt($crl, CURLOPT_HEADER, 1);
  curl_setopt($crl, CURLOPT_POSTFIELDS, $post_data);


  // Set HTTP Header for POST request 
  curl_setopt($crl, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Content-Length: ' . strlen($data))

  );

  // Submit the POST request
  $result = curl_exec($crl);
  echo $result;
  // handle curl error
  if ($result === false) {
      // throw new Exception('Curl error: ' . curl_error($crl));
      echo "no";//print_r('Curl error: ' . curl_error($crl));
      $result_noti = 0; die();

  } else {
      echo "yes"; 
      $result_noti = 1; die();
  }
  // Close cURL session handle
  curl_close($crl);

?>

Trolly-lights3.ino

Arduino
code to program the Wemos d1 mini with
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ArduinoJson.h>
#include <ESP8266WiFiMulti.h>
#include <FastLED.h>
#include <EEPROM.h>
#define NUM_LEDS 4
#define DATA_PIN 13


#ifndef STASSID
//#define STASSID "EE-Hub-H6pg"
//#define STAPSK  "gift-glaze-NOT"
CRGB leds[NUM_LEDS];

#endif
int si;
int light[4];
int duration[4];
int red[4];
int green[4];
int blue[4];
//const char* ssid     = STASSID;
//const char* password = STAPSK;
int sw = 0;
String T1;
String T2;
const char *ssid = "pick";
const char *password = "12345678";
int count = 0; 
int buttonState;   int s = 0; int but = 0; int set =0;

char htmlResponse[3000];    
char let;     char Sid [16]; 
char hh [20]; char mm [20];   char Pid [16]; 


String sid;   String pid;
 

ESP8266WebServer server(80);
ESP8266WiFiMulti WiFiMulti;
WiFiClient client;


void handleRoot() {
  server.send(200, "text/html");
}

void handleRoot2() {                                        // web page set up interface
  snprintf ( htmlResponse, 3000,
"<!DOCTYPE html>\
<html lang=\"en\">\
  <head>\
    <meta charset=\"utf-8\">\
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
  </head>\
  <style>\
  h1 {\
     font-size: 20px;\
     color: black;\
     text-align: center;\
     border: 1px solid #151515;\
     border-radius: 2px;\
     background-color: #A4A4A4;\
     width: 100%;\
}\
button {\
        background-color: #BDBDBD;\
        border: solid black 1px;\
        border-radius: 4px;\
    padding: 2px;\
    font-size: 1.1em;\
    display: inline-block;\
        color: black;\
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);\
}\
</style>\
  <body>\
          <h1>Networking</h1>\
          <form  action=\"/up\" method=\"post\">\
          <input type='text' name='hh' id='hh' size=15 autofocus> SSid &nbsp;&nbsp;&nbsp;&nbsp;<a href=\"/Net\">View<a/>\
          <button id=\"save_button\">Save</button><br>\
          </div></form>\    
          <form  action=\"/up1\" method=\"post\">\     
          <input type='text' name='mm' id='mm' size=15 autofocus> Password &nbsp;&nbsp;<a href=\"/Pas\">View<a/>\
          <button id=\"save_button1\">Save</button><br>\
          </div></form>\       
          <div>\
          <a href=\"/exit\"><big><big><button>Exit</button></big></big><a/>\
  </body>\
</html>"); 

   server.send ( 200, "text/html", htmlResponse ); 

}

void up() {
    server.arg("hh").toCharArray(hh, 20);            // ssid and ect upload handling                                         // converting html data to char arrays
    sid = "";
    for (s = 0; s < 20; s++  ) {                   //write the html data to eeprom memory Wifi ssid,
      EEPROM.write(s, hh[s]);
      EEPROM.commit();}
 
    server.send(200, "text/html", "<h1>Data Saved</h1><br><a href=\"/\"> MainMenu<a/> <a href=\"/exit\">Exit<a/>");
}

void up1() {
    server.arg("mm").toCharArray(mm, 20);      // converting html data to char arrays  
    pid = "";   
    for (s = 21; s < 42; s++  ) {             //write the html data to eeprom memory Wifi password,
      EEPROM.write(s, mm[s - 21]);
      EEPROM.commit();}   
    server.send(200, "text/html", "<h1>Data Saved</h1><br><a href=\"/\"> MainMenu<a/> <a href=\"/exit\">Exit<a/>"); 
}


void exit1() {
    server.send(200, "text/html", "<h1>AP Closed</h1>"); 
    but = 1;    // change variable to exit while loop and continue with void set up 
    WiFi.disconnect();
}
void set1() {
    server.send(200, "text/html", "<h1>Setup JSON device and AP Closed</h1>");
    set =1; 
    but = 1;    // change variable to exit while loop and continue with void set up 
    WiFi.disconnect();
}

void Net() {                                //read  ssid data from  eeprom to display on html setup screen
    sid = "";
    for (s = 0; s < 20; s++  ) {   
    byte value = EEPROM.read(s);
    char m = (char(value));
    sid  = sid + m; }
    server.send(200, "text/html", "<big><big>"+sid+"</big</big>");
  
}
void Pas() {                              //read  password data from  eeprom to display on html setup screen
    pid = "";
    for (s = 21; s < 42; s++  ) {   
    byte value = EEPROM.read(s);
    char n = (char(value));
    pid  = pid + n;}
    server.send(200, "text/html", "<big><big>"+pid+"</big></big>");
  
}


void handleForm() {
  if (server.method() != HTTP_POST) {
    server.send(405, "text/plain", "Method Not Allowed");
  } else {
    sw =1;
    count = 0;
    String message = "";
    for (uint8_t i = 0; i < server.args(); i++) {
      message += "" + server.arg(i);
    }
    server.send ( 200, "text/json", message );
    DynamicJsonDocument doc(1024);
    deserializeJson(doc, message);
    si = doc.size();
    int x = 0;
    while (si != x){
    light[x] = doc[x]["light"].as<int>();
    red[x] = doc[x]["Red"].as<int>();
    green[x] = doc[x]["Green"].as<int>();
    blue[x] = doc[x]["Blue"].as<int>();
    duration[x] = doc[x]["duration"].as<int>();
    Serial.println(light[x]);

    x++;

    }
  }
}

void handleNotFound() {
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
}



void setup() {
    FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed



  Serial.begin(115200);
     delay(100);
     pinMode(0, INPUT);  
     EEPROM.begin(512);
     delay(1000);
     digitalWrite(12, HIGH);   
     delay(100);
     buttonState = digitalRead(0);
     Serial.println();
     Serial.println(buttonState);
     
     if (buttonState == 0){but = 0;}         // if button is pressed go to setup acess point
          if (buttonState == 0){
             leds[3] = CRGB::Blue; 
             FastLED.show();   
             leds[2] = CRGB::Blue; 
             FastLED.show();   
             leds[1] = CRGB::Blue;        
             FastLED.show();  
          WiFi.softAP(ssid, password);
          IPAddress myIP = WiFi.softAPIP();
          server.on("/", handleRoot2);               //Server responses when links are pressed
          server.on("/up", up);
          server.on("/up1", up1);

          server.on("/exit", exit1);
          server.on("/Net",Net);
          server.on("/Pas",Pas);  
      
          server.begin();
          Serial.println(myIP);
  

           while (but == 0){  
             server.handleClient();
             delay(300);
           }
      }
    Net();
    Pas();
   leds[3] = CRGB::Black; 
    FastLED.show();      
   leds[3] = CRGB::Black; 
    FastLED.show();      
   leds[3] = CRGB::Black; 
     FastLED.show();   
  char Ssid[20];    char Ppid[20];  
    sid.toCharArray(Ssid, 20);
    pid.toCharArray(Ppid, 20);    
  
  WiFi.hostname("trolly1");
  WiFi.begin(sid, pid);
  Serial.println("Hello-1");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);
  server.on("/postform/", handleForm);
  server.onNotFound(handleNotFound);
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {

  count ++;
  server.handleClient();
  if(sw == 1){
    int x = 0;
    while( si != x){
    leds[light[x]-1] = CRGB(red[x],green[x],blue[x]);
    FastLED.show();   
    x++;
    }

  sw = 0;
  
  }
    int x = 0;
    while(si != x){
    if (count > duration[x] * 100){  
    leds[light[x]-1] = CRGB(0,0,0);}
    FastLED.show();
    x++;
    }
  
}

Credits

matthew Champion

matthew Champion

6 projects • 4 followers
Llandovery, Wales

Comments