Send HTTP post request from an esp8266 - http-post

I want to send temperature data from an esp8266. I've adapted my code from this Instructable; this is my code:
#include "SoftwareSerial.h"
#include "ESP8266.h"
String ssid = "Red Wi-Fi de Alexis" ;
String password = "adrian2003" ;
SoftwareSerial wifi(4, 2) ;
String Host = "mail.interseccion.com.mx:8901" ;
String Url = "/Ws_Temperatura" ;
void setup()
{
wifi.begin(9600) ;
Serial.begin(9600) ;
wifi.println("AT+RST") ;
wifi.println("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"") ;
}
void loop()
{
float tmp = 22.22 ;
//URL Temperatura
//URL: mail.interseccion.com.mx:8901/Ws_Temperatura?Id_temp=0&Id_Device=1&Valor=00.00&Temperatura_Action=Insert
String urluno = String("Id_temp=0&Id_Device=2&Valor=");
String temp = String(tmp);
String urldos = String("&Temperatura_Action=Insert");
String urlfinal = String(String(urluno) + String(tmp) + String(urldos));
int tamano = urlfinal.length() ;
wifi.println("AT+CIPSTART=\"TCP\",\"" + Host + "\", 8901") ;
String Post = "POST" + Url + "HTTP/1.1\r\n" +
"Host: " + Host + "\r\n" +
"Content-Type: application/x-www-form-urlencoded" +
"Content-Length: " + tamano + "\r\n" + urlfinal ;
wifi.println("AT+CIPSEND= " + Post.length()) ;
wifi.println("AT+CIPCLOSE") ;
}
I tried to send with esp8266 library but it doesn't work.

I read the code, and I detected a little error in these lines:
wifi.println("AT+CIPSEND= " + Post.length()) ;
wifi.println("AT+CIPCLOSE") ;
Your ESP8266 is ready to receive data, but you are not sending anything, so add this line :)
wifi.println("AT+CIPSEND= " + Post.length()) ;
wifi.println(Post); // this line
wifi.println("AT+CIPCLOSE") ;
The process is as follows for example
ARDUINO sends:
AT + CIPSTART = "TCP", www.google.com, 80
ESP8266 responds:
CONNECT
ok
ARDUINO sends:
AT + CIPSEND = 45
where 45 is the size of the entire frame
ESP8266 responds:
>
> means that that it expects to receive data. The data is sent here.
and finally
ARDUINO sends:
AT + CIPCLOSE
ESP8266 responds:
Closed
ok

Related

Generate Azure Storage SAS Signature In Ruby

I am trying to use the following code to generate a valid URL for accessing a blob in my Azure storage account. The Azure account name and key are stored in .env files. For some reason, the URL doesn't work; I get a Signature did not match error.
# version 2018-11-09 and later, https://learn.microsoft.com/en-us/rest/api/storageservices/create-service-sas#version-2018-11-09-and-later
signed_permissions = "r"
signed_start = "#{(start_time - 5.minutes).iso8601}"
signed_expiry = "#{(start_time + 10.minutes).iso8601}"
canonicalized_resource = "/blob/#{Config.azure_storage_account_name}/media/#{medium.tinyurl}"
signed_identifier = ""
signed_ip = ""
signed_protocol = "https"
signed_version = "2018-11-09"
signed_resource = "b"
signed_snapshottime = ""
rscc = ""
rscd = ""
rsce = ""
rscl = ""
rsct = ""
string_to_sign = signed_permissions + "\n" +
signed_start + "\n" +
signed_expiry + "\n" +
canonicalized_resource + "\n" +
signed_identifier + "\n" +
signed_ip + "\n" +
signed_protocol + "\n" +
signed_version + "\n" +
signed_resource + "\n" +
signed_snapshottime + "\n" +
rscc + "\n" +
rscd + "\n" +
rsce + "\n" +
rscl + "\n" +
rsct
sig = OpenSSL::HMAC.digest('sha256', Base64.strict_decode64(Config.azure_storage_account_key), string_to_sign.encode(Encoding::UTF_8))
sig = Base64.strict_encode64(sig)
#result = "#{medium.storageurl}?sp=#{signed_permissions}&st=#{signed_start}&se=#{signed_expiry}&spr=#{signed_protocol}&sv=#{signed_version}&sr=#{signed_resource}&sig=#{sig}"
PS: This is in Rails and medium is a record pulled from the DB that contains information about the blob in Azure.
Turns out the issue was clock skew. The signed_start and signed_expiry amounts I was using were too tight. WHen I relaxed then to -30/+20, I could reliably create SAS tokens using the snipper I posted.

Sending very long strings from MetaTrader 4 to Python backend using ZeroMQ Push/Pull Pattern

I have a quite weird issue related to ZeroMQ messaging between MetaTrader 4 and a python backend.
The below shown code creates three strings which should be forwarded to a ZeroMQ PUSH socket. However, it only sends the live_trades string via the socket. Both the account_info and the historical_trades strings are not sent.
While debugging the weirdness only increased:
When I print the historical_trades string, it is shown in the MT4 expert journal, but not in the MT4 log editor
When I add Print( historical_trades ) before or after the pushSocket.send(StringFormat("%s", historical_trades, true)); it sends the string.
Possible issues which I actually exclude:
The PUSH socket is too slow: I decreased the timer to 10 seconds and more, same result
MT4 itself is too slow to create the strings: It prints them correctly, so it is fast enough
The ZeroMQ SNDHWM ( HighWaterMark ) blocks the EA/socket from sending multiple strings in no time: Already increased it to 100 which should be more than sufficient
Any other ideas I cannot verify with debugging:
The MT4 Print() function does some other stuff behind the scenes which enables the EA to send the string?
Maybe there is a maximum string size in MT4 which blocks the string creation loop (my string is around 35.000 characters long). But then why does it work when I just Print() the string once within the onTimer() function?...
Any chance that the account related information is not accessible on weekends?
Or it is just my code which might be buggy..
Any ideas much appreciated!
int OnInit()
{
//---
EventSetTimer(2); // Set Second Timer as push intervall
context.setBlocky(false);
// Send data to PULL_PORT that consumer is listening to.
Print("Connecting MT4 Dashex Feeder to Dashboard on Port " + IntegerToString(PUSH_PORT) + "..");
pushSocket.connect(StringFormat("%s://%s:%d", ZEROMQ_PROTOCOL, HOSTNAME, PUSH_PORT));
pushSocket.setSendHighWaterMark(100);
pushSocket.setLinger(0);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
Print("Disconnecting MT4 Dashex Feeder on Port " + IntegerToString(PUSH_PORT) + "..");
pushSocket.disconnect(StringFormat("%s://%s:%d", ZEROMQ_PROTOCOL, HOSTNAME, PUSH_PORT));
// Shutdown ZeroMQ Context
context.shutdown();
context.destroy(0);
EventKillTimer();
}
//---
//+------------------------------------------------------------------+
//| Expert timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
/*
1.) Account information
*/
string account_info = "";
account_info = account_info +
"account_info|" +
version + "|" +
DID + "|" +
IntegerToString(AccountNumber()) + "|" +
AccountInfoString(ACCOUNT_COMPANY) + "|" +
IntegerToString(AccountInfoInteger(ACCOUNT_LEVERAGE)) + "|" +
DoubleToString(AccountInfoDouble(ACCOUNT_BALANCE),2) + "|" +
DoubleToString(AccountInfoDouble(ACCOUNT_PROFIT),2) + "|" +
DoubleToString(AccountInfoDouble(ACCOUNT_EQUITY),2) + "|" +
DoubleToString(AccountInfoDouble(ACCOUNT_MARGIN),2) + "|" +
DoubleToString(AccountInfoDouble(ACCOUNT_MARGIN_FREE),2) + "|" +
DoubleToString(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL),2) + "|" +
AccountInfoString(ACCOUNT_CURRENCY) + "|" +
IntegerToString(IsDemo()) + "|" +
pushSocket.send(StringFormat("%s", account_info, true));
Print("Pushing Account Information To Dashex.Finance Dashboard For Account No. " + IntegerToString(AccountNumber()));
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
/*
2.) Pending and running trades
*/
int live_orders = OrdersTotal();
string live_trades = "";
for(int i=live_orders; i >= 0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==false) continue;
live_trades = live_trades +
"live_trades|" +
version + "|" +
DID + "|" +
IntegerToString(AccountNumber()) + "|" +
IntegerToString(OrderTicket()) + "|" +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "|" +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "|" +
IntegerToString(OrderType()) + "|" +
DoubleToString(OrderLots(),2) + "|" +
OrderSymbol() + "|" +
DoubleToString(OrderOpenPrice(),5) + "|" +
DoubleToString(OrderClosePrice(),5) + "|" +
DoubleToString(OrderStopLoss(),5) + "|" +
DoubleToString(OrderTakeProfit(),5) + "|" +
DoubleToString(OrderCommission(),2) + "|" +
DoubleToString(OrderSwap(),2) + "|" +
DoubleToString(OrderProfit(),2) + "|" +
"<" + OrderComment() + ">|";
}
pushSocket.send(StringFormat("%s", live_trades, true));
Print("Pushing Live Trades To Dashex.Finance Dashboard For Account No. " + IntegerToString(AccountNumber()));
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
/*
3.) History Trades
*/
int hstTotal = OrdersHistoryTotal();
string historical_trades = "";
Print(hstTotal);
for(int i=hstTotal; i >= 0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
IntegerToString(AccountNumber()) + "|" +
IntegerToString(OrderTicket()) + "|" +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "|" +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "|" +
IntegerToString(OrderType()) + "|" +
DoubleToString(OrderLots(),2) + "|" +
OrderSymbol() + "|" +
DoubleToString(OrderOpenPrice(),5) + "|" +
DoubleToString(OrderClosePrice(),5) + "|" +
DoubleToString(OrderStopLoss(),5) + "|" +
DoubleToString(OrderTakeProfit(),5) + "|" +
DoubleToString(OrderCommission(),2) + "|" +
DoubleToString(OrderSwap(),2) + "|" +
DoubleToString(OrderProfit(),2) + "|" +
"<" + OrderComment() + ">|";
}
pushSocket.send(StringFormat("%s", historical_trades, true));
Print("Pushing History Trades To Dashex.Finance Dashboard For Account No. " + IntegerToString(AccountNumber()));
Sleep(1);
}
MetaTrader 4 log.editor:
MetaTrader 4 console:
Q : Any chance that the account related information is not accessible on weekends?
This has an easy proof: do a Comment( aStringUnderTEST ); + check all account / Broker-related items.
Q : Maybe there is a maximum string size in MT4 which blocks the string creation loop...?
This is, except a case of an MT4-Build-X.Y.Z release-bug awaiting a BugFIX, very low probability hypothesis.
Yet it has an easy proof: do a loop of growing string-lengths and test until what size the processing keeps working. The indirectly proved size-limit will help you track the root cause, MT4 not being the SPoF here, is it?
Q : The MT4 Print function does some other stuff behind the scenes which enables the EA to send the string?
The MT4 Support ought be contacted if this is to get confirmed or denied. The software is licensed as an as-is product, so do not expect any rapid response or a rocket science to take place if you try to drill down to the bolts and nuts, inside their closed and sealed product.

Update by query by using jest client

I am trying using script with query to update particular documents , but m not sure which class I need to use of jest client which work's with update by query
Here is my code
String h = " { "
+ " \"script\": { \n"
+ " \"inline\": \"ctx._source.order=params.prasad\", \n "
+ "\"params\": { \"prasad\":["+column+"] \n"
+ " } , \n"
+ "\"lang\": \"painless\" \n"
+ "},\n"
+ "\"query\": { \n"
+ "\"term\": { \n"
+ "\"orgid\": "+orgId+" \n"
+ "} \n"
+ "}";
LocalJestClientInstance.getInstance().getClient().execute(new Update.Builder(h).index(index).type(type).build());
This is not updating my documents.
Uri generating is this uri=loadfields/loadfields_type/_update,method=POST
Instead of _update how to get the _update_by_query
Jest didn't have it before but it looks like it does have it now.
My workaround was to use a second client as well, a standard http client and parse the JSON output just for this functionality that was missing.

Using ACE with WT and highlighting lines. This is not working

This code is not working, I keep having a loading sign on top to the right but the editor works. Is it possible to have some help towards the actual connection from the Ace Editor file to the C++ WT file.
//Start.
editor1 = new Wt::WText(wt_root);
editor1->setText("Testing for the highlight.");
editor1->setInline(false);
//REQUIREMENT FOR THE ACEEDITOR FILE INPUTED.
Wt::WApplication::instance()->require(std::string("AceFiles/ace.js"));
//CONFIG FOR THE EDITOR THAT WILL SUPPORT TEXT.
editor = new Wt::WContainerWidget(wt_root);
editor->resize(500, 500);
range = new Wt::WContainerWidget(wt_root);
//editor_ref IS THE STRING THAT THE USER IS WRITTING.
std::string editor_ref = editor->jsRef();
std::string range_ref = range->jsRef();
std::string command =
editor_ref + ".editor = ace.edit(" + editor_ref + ");" +
range_ref + ".range = ace.require('ace/range')." + range_ref + ";" +
editor_ref + ".editor.setTheme(\"ace / theme / github\");" +
editor_ref + ".editor.getSession().setMode(\"ace/mode/assembly_x86\");" +
editor_ref + ".editor.session.addMarker(new Range(1, 0, 15, 0), \"fullLine\");";
editor->doJavaScript(command);
//CONFIG. FOR THE JSIGNAL USED.
//BEING THE CONNECTION BETWEEN THE C++ DOC AND THE JAVA SCRIPT.
jsignal = new Wt::JSignal<std::string>(editor, "textChanged");
jsignal->connect(this, &Ui_AceEditor::textChanged);
//CONFIG FOR THE BUTTON.
b = new Wt::WPushButton("Save", wt_root);
command = "function(object, event) {" +
jsignal->createCall(editor_ref + ".editor.getValue()") +
";}";
b->clicked().connect(command);

How to display fields in new line in same textBox in telerik reporting?

I am using Silverlight4 and Telerik Reporting Q3 2011. I am trying to Generate Reports of all Outlets. I used Table to display its fields. And I want to Display Full Address in same cell. How could I?
I Used following Experession to display Full Address in same cell.
= Fields.AddressLine1
+ ", " + Fields.AddressLine2
+ ", " + Fields.Suburb
+ ", " + Fields.City
+ ", " + Fields.State
+ ", " + Fields.Country
I want do display this in same cell but want output like below..
=====================
Address
=====================
15A,
xxxx xxxRoad,
xxxxxx,
xxxxxxxx
====================
But I m getting this
=====================
Address
=====================
15A, xxxx xxxRoad, xxxxxx, xxxxxxxx
=====================
How do I get Output Which I want?
made the Function NewLineFeeds() in this function I used Replace() Method to replace the specific string to newLine(\n) .
public static string NewLineFeeds(string text)
{
string result = text.Replace(", ", "\n");
result = result.Replace(", ", "\n");
result = result.Replace(", ", "\n");
return result;
}
and my Expression is
=NewLineFeeds(Fields.AddressLine1
+ ", " + Fields.AddressLine2
+ ", " + Fields.Suburb
+ ", " + Fields.City
+ ", " + Fields.State
+ ", " + Fields.Country)
This call the Function NewLineFeeds() and replace ", " to \n (new Line). Add this will work Fine..

Resources